07 September 2012, 10:28 | #1 |
Registered User
Join Date: Nov 2011
Location: Folkestone, Kent
Posts: 119
|
Hi Soft Basic help wanted
I am trying to write a routine to sort listed data into time difference groups such that any group of data with a fixed time difference will have a line of space before the next group as follows:-
Basic data list a b c d e f g h etc If a-b < 5 then print a and b, if b-c < 5 print a,b and c etc If c-d > 5 then print a line of space and start again at d this will then look like this:- a b c d e f g h etc Any item without a close neighbour is to be unlisted Can anyone help? |
07 September 2012, 12:40 | #2 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
You can do this by starting at the first value and search forward while the difference is lower than your threshold. If the interval you searched in covers more than one value then you print these and a blank line after. If the next value after the interval is still inside your list then you repeat the whole procedure.
EDIT: assuming you have a list sorted in ascending order: Code:
' set the threshold and number of items in our list t = 5 n = 10 list(n) = list(n-1)+t ' search through the whole list s = 0 while s < n ' find the end of the current interval e = s while list(e+1)-list(e) < t e = e+1 wend ' if there were more than 1 item we print them if e-s > 0 for i = s to e print list(i) next print end if ' step to the next item and repeat s = e+1 wend Last edited by Leffmann; 07 September 2012 at 12:51. |
07 September 2012, 17:00 | #3 |
Registered User
Join Date: Nov 2011
Location: Folkestone, Kent
Posts: 119
|
Thanks. I will ponder on your answer and see if I can make it applicable. If not, may I
ask for more help? regards Dan |
07 September 2012, 20:18 | #4 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Sure, no problem. This code should work with HiSoft Basic v2.0 from 1994, I'm not sure how compatible the other versions are.
|
11 September 2012, 10:11 | #5 |
Registered User
Join Date: Nov 2011
Location: Folkestone, Kent
Posts: 119
|
Hi Leffmann, my HiSoft basic program is V2.0, so it should work. My data generated from another program is filed in the following format:-
Day 11 9 Time 0 0 4 Har 12 22 35 Day 11 9 Time 10 10 40 Har 16 52 48 This makes the line lengths different. If we need the length of the file to use in the formula you gave me, we need the number of lines and not just the file length. Typically my files have between 3500 and 4000 lines. I tried using the following code to find the file length:- Open for input as #1 : length&=LOF(1) FileBuf$=INPUT$(length&,#1) PRINT LOF(1) I use the print statement to check LOF. The result is a large number 155378 is an example. To find the number of lines we need to divide this by the number of data bits in a line (I think). Therefore the line lengths must be equal. How can I file data so that all of the items are tabbed in columns? This would be useful also for visual inspection of the data. I use the following code in my data generation program. OPEN ans2$ for APPEND AS #1 thanks for your help |
11 September 2012, 18:03 | #6 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
You can achieve both tabulation and fixed-width lines if you write your data with the print using-statement, f.ex:
Code:
print #1, using "### ### ### \ \", x, y, 10, "test" Do you have the v2.0 manual btw? I'd like to add it to my own files but can't find a download anywhere. EDIT: if the lines in your file are already sorted, and you're not doing anything else with the file but reading it in to group the lines and print them, then you can probably do this in one go and print as you read. Last edited by Leffmann; 11 September 2012 at 18:14. |
12 September 2012, 00:33 | #7 |
Global Moderator
Join Date: Aug 2008
Location: Sidcup, England
Posts: 10,300
|
|
12 September 2012, 07:02 | #8 | |
Registered User
Join Date: Nov 2011
Location: Folkestone, Kent
Posts: 119
|
Quote:
Yes I have the original manual in hard copy. I find it hard to use because I'm not really a programmer. I'm just starting to learn but have a research project to complete. I shall try your advice. Thanks for your help |
|
12 September 2012, 07:04 | #9 |
Registered User
Join Date: Nov 2011
Location: Folkestone, Kent
Posts: 119
|
|
12 September 2012, 14:45 | #10 | |
Registered User
Join Date: Nov 2011
Location: Folkestone, Kent
Posts: 119
|
Quote:
Thanks. I have now managed to get the files right and can calculate the number of lines of text. Next is to get the search routine right. |
|
13 September 2012, 12:43 | #11 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Thanks a lot! Been looking for this everywhere.
Yes I understand, the manual is more of a reference and not so much a guide to programming for someone just starting out. Glad you got the formatting sorted out. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Basic help wanted | alphagemini | Coders. General | 6 | 07 March 2013 22:35 |
Manuals for GFA Basic and Hi-Soft Basic 2 | ricky500 | request.Apps | 20 | 12 February 2013 21:06 |
Hi Soft Basic help wanted | alphagemini | Coders. General | 4 | 11 January 2013 11:39 |
Alarm program in Hi Soft basic | alphagemini | Coders. General | 6 | 05 August 2012 18:00 |
Basic Vector Code wanted | redblade | Coders. General | 16 | 24 December 2005 05:41 |
|
|