Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / reading number of strings from .txt file

Author
Message
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 3rd Jun 2005 06:42
im trying to run a sequence to identify how many strings are in a .txt file which is prooving to be very annoying as i cant seem to get it to work iw as wonderinng if anyone knew how to do this.

thanks for any help

kR

kR
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 3rd Jun 2005 10:46 Edited at: 3rd Jun 2005 10:47
kRx,

This is quite simple once understood. Use a repeat until loop to read each string from the file, incrementing a count variable each time there is a string. If there is no string in the current loop, then end the loop and do not increment the variable. The value in the count variable will be what you need. Check the code snippet below.




+NanoBrain+
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 4th Jun 2005 00:58
NanoBrain's code should work just fine, but I thought I would just post some code that uses the File End() command. My code is basically the same except for the File End() command. The File End() command will return a value of 1 if theres no data left to read in the file, if there still is data in the file it will return a 0. Everything else is basically the same.



kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 4th Jun 2005 01:43
exellent i was kindaish on the right track but urs worked so much better thanks a lot works perfectly now

kR
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 4th Jun 2005 02:22
i didnt know about the file end syntax damn im an idiot ! *slaps self* thanks guys the code iw as working on works perfectly now

kR

Login to post a reply

Server time is: 2025-05-22 20:22:22
Your offset time is: 2025-05-22 20:22:22