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 / Quick question for any in the know

Author
Message
Phrozin
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Florida USA
Posted: 14th Feb 2004 15:46 Edited at: 14th Feb 2004 15:47
K, I have a small situation that I can't seem to be able to find a answer to. I've tried searching for delimited, and file structure and came up empty on all forums.

Question:
In Dark Basic Classic can one use a file delimited by colons ( : )?

In Example:

MaxSpeed: 118
Accel: 0.65
Brake: 0.51
Turn: 18.2
GrossWeight: 2145

*New file*
MaxSpeed: 131
Accel: 0.59
Brake: 0.75
Turn: 15.7
GrossWeight: 1891

When opened and gone through, it would search for the next colon and then read to the right of it? I'm going to have to make a nasty little function for this aren't I?!

Thanks for any help,
Phrozin
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 14th Feb 2004 15:55
yup, you need a function shouldn't be too hard though using the read string and mid$() commands


GO TO THE ETERNAL DESTINY FORUMS!!! http://forums.eternaldestinyonline.com
Do it now!!!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 14th Feb 2004 16:52
if you don't want to make a delimited file parser just use ini files and use the various plugins that are floating around. The plugins make use if the win32api for reading and writing ini files.
I think TCA and/or RobK both have these available.

-RUST-
"What the... Mooooooooooo!"
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Feb 2004 18:04
I don't think it's Rob, but it might be me

Just put this in a separate .dba file and use the IDE to include it


You use it like this



Run this code and look at the filename.ini to see the format it uses.

For free Plug-ins, source and the DBPro Interface library for Visual C++ 6 and .NET
http://www.matrix1.demon.co.uk
Phrozin
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Florida USA
Posted: 15th Feb 2004 06:19
ReD_eYe, Cattle Rustler, & IanM, Thank you for the replies!

ReD_eYe, Thank you for the intro to the MID$() command, Have no clue how I could have missed that one.

Cattle Rustler, Thank you for your reply. I would much rather use the ini files but wasn't aware of plug-ins for DB. I'm assuming TCA & Robk are user names for this board? Going to try a search for them after I post.

IanM, Thank you for the reply as well. I've givin' the code a quick look and seems to be just what I need. Now I'll spend all night reading it line by line to understand all it does.

Again, thank you all for your help!
Phrozin
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Feb 2004 08:57
try checking the code base for "string tokenizer". Using the functions I wrote, you can extract the following:

MaxSpeed: 118

nextToken() would return MaxSpeed the first time, the 118 the next time its called. I can't remember for sure, but I think my function can take more than 1 delimiter, even though I say it can't in the source file.

"eureka" - Archimedes
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 15th Feb 2004 16:07
Phrozin

IanM's code is directly implementing the win32api for reading ini files. Windows has done all the leg work for you and has put 4 useful functions in kernel32.dll which we can all use in dbp by implementing as IanM has done above. The windows and programs written for windows use this api to read and write ini files which are 'key=value' pairs, broken out in 'sections', and is an industry standard - no reason to reinvent the wheel, but you could always experiment with your own ways, or other ways (like Phaelax's) to do the same thing. Based on your original post's key=value schema I suggested ini files and the win32api. I have a COM dll that I wrote in vb6 that wraps the 4 main ini functions and includes a few other functions and I use that dll in almost all of my vb6/vb.net projects that require a I/O ini file. Too bad I can't use the com dll from dbp

anyways, good luck

-RUST-
"What the... Mooooooooooo!"
Phrozin
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Florida USA
Posted: 16th Feb 2004 15:13
Thank you for the replies.

Phaelax, I looked through your code. Nice work, although I've only been working with DBC for 2 days now, I can see where that will come in handy.

Cattle Rustler, Thx for the tip. I think I'm gonna follow IanM's advice and try his code out as it's already in windows and requires little code from me (as a beginner this is a plus). As I was going through the code I noticed the "#Global" and am wondering is this code meant for DBPro only or does DBC handle Global variables as well?

Again Thanks everyone for helping me out,
I really appreciate it!

Phrozin
Phrozin
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Florida USA
Posted: 18th Feb 2004 23:53 Edited at: 19th Feb 2004 10:28
IanM, quick question for you.

In the above functions and uses that you posted, How does one set the save path as generic? By generic I mean a save path that would be in the program directory? I've tried using every Windows environment variable that I could remember and it wont save using any of them. If you use "..\filename.ini" it will save but in the next directory up. If you try "..\somefolder\another_folder\filename.ini" it wont save.

Any idea's?

*Edit*
Nevermind, I figured it out. actually a typo figured it out. to save to the working directory and in a subfolder you would use ".\some_folder\Another_folder\filename.ini" But make sure the folder/folders exist first.

Again Thank you for all your help,
Phrozin
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Feb 2004 01:06
Great - that saves me posting ...




um

For free Plug-ins, source and the DBPro Interface library for Visual C++ 6 and .NET
http://www.matrix1.demon.co.uk

Login to post a reply

Server time is: 2024-09-21 20:45:48
Your offset time is: 2024-09-21 20:45:48