Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
QBasic Random Data Files
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00456801
Message ID:
00457789
Views:
27
>>Good morning, Ron.
>>
>>I received the files today. I'm cheking them. I think I'll send you a little QBASIC program for you to use as a template for converting all your data.
>
>Here it is, Ron.
>
>Maybe George or something else could perfect the code, but it works. I've sent it to you with a test file and other pieces.
>
>
>'Here I declare the source and target filenames
>DataSource$ = "test.ron"
>DataTarget$ = "test.txt"
>
>'This is the structure definition
>'You just have to specify the length of the strings
>TYPE roRecord
>    roStr      AS STRING * 20
>    roInt      AS INTEGER
>    roLong     AS LONG
>    roSingle   AS SINGLE
>    roDouble   AS DOUBLE
>END TYPE
>
>'Here we create a variable from that structure
>'Think about this as a kind of scatter memvar blank
>DIM rs AS roRecord
>
>'Let's open the source
>OPEN DataSource$ FOR RANDOM AS #1 LEN = LEN(rs)
>
>'...and the target
>OPEN DataTarget$ FOR OUTPUT AS #2
>
>'Set our record counter
>DIM recc AS INTEGER
>recc = 0
>
>'Scan trough the file
>DO
>    recc = recc + 1
>    GET #1, recc, rs
>
>    PRINT #2, rs.roStr;
>    PRINT #2, USING "########"; rs.roInt;
>    PRINT #2, USING "############"; rs.roLong;
>    PRINT #2, USING "########.#######"; rs.roSingle;
>    PRINT #2, USING "############.#######"; rs.roDouble
>
>LOOP UNTIL (EOF(1))
>
>
>CLOSE #1
>CLOSE #2
>
>
>This is quite generic. I think it's easy to adapt it. Also, as you can imagine, the USING mask could be as you want. In most cases Single and Doubles would have two decimals places, and the like. You can even define a couple variables IntMask$ and FloatMask$ and use each one to handle both integer or floating point types.
>
>Hope this helps. If not, just shout! I'll hear you. 8-)

Martin,

Looks OK. Nothing pops out as being incorrect. A couple of comments, however, if you don't mind. My strategy always would use the FREEFILE() function to retrieve the available handle. In this instance, however, it shouldn't make a difference. I'm the cautious type. I'd also use the WHILE NOT EOF(1)...WEND pre-test iteration structure, rather than the DO...LOOP UNTIL post-test, in case the file was empty. Probably not a concern here, however. As I said, this is probably (in this case) simply differences in style.:-)
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform