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.

Newcomers DBPro Corner / comma separated values in files

Author
Message
Kelby
19
Years of Service
User Offline
Joined: 20th Sep 2005
Location: Lancashire, UK
Posted: 28th Sep 2005 18:42
Is it possible to have comma separated values in a file, like you can in a data statement?

I am using dark basic pro

eg

Data 1,1,2,0,0

When you read a file you can only bring in one value,

Read String 1, myValue$
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Sep 2005 20:45
Quote: "When you read a file you can only bring in one value"


Reading data from a file is exactly the same as reading from data statements apart from the fact that you open the file and create a 'channel' between DB and the file.

All you need to do is read the values in a loop:



The important thing to remember is that if your loop counts to 50 then myValue$ will get overwritten 50 times by the new data as it is read in, So, as soon as you read it, you have to use the data value, (or store it in an array for later use as I have in the above snippet).

TDK_Man

Kelby
19
Years of Service
User Offline
Joined: 20th Sep 2005
Location: Lancashire, UK
Posted: 29th Sep 2005 14:41
Thanks for your reply TDK, but what I am trying to do is read data from a file into a data array(10,10) for a matrix, say a 10 x 10 matrix for tiling the texture to each square, I would like my file to look something like this;

1,1,1,1,1,1,1,2,2,2
1,1,2,1,3,3,3,2,2,2

not

1
1
1
1
1
1
2
2
2
1
1
2

and so on.

Thanks Darren
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 29th Sep 2005 21:19 Edited at: 29th Sep 2005 21:21
here, i threw this together for you real quick...(it reminded me of something in C++...namely the getline function...)

this would do what you are saying for whatever size you want...



try running that with a txt file called "stuff.txt" with the below contents...


hope it works for you, i tried to comment heavily to make it was understandable...

--Peter

"We make the worst games in the universe."

spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 30th Sep 2005 01:13
To simplify Peter_'s code a little, you can use the undocumented token commands that will automatically parse a string delimited with any character. Just replace the file bit of code with this;



Boo!
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 30th Sep 2005 01:24 Edited at: 30th Sep 2005 01:25
o_O

neato, didn't know how to do that in DBPro...thanks!

"We make the worst games in the universe."

Kelby
19
Years of Service
User Offline
Joined: 20th Sep 2005
Location: Lancashire, UK
Posted: 30th Sep 2005 10:13
Thanks Spooky, thats just what I am looking for.

Login to post a reply

Server time is: 2024-11-13 21:04:39
Your offset time is: 2024-11-13 21:04:39