Click to See Complete Forum and Search --> : How would i read a specific line from a text file as a string?


Decayed
February 24th, 2000, 07:28 PM
I would like to read configuration from a text file like config.txt
each line would look like: variable value (for example: version "0.9")

What code would i need to write if i only wanted to extract one variable and it's value from the config.txt?

How would i find the variable and read it's value ????


---------------------
~:{Decayed}:~
the.decayed@usa.net
http://www.q3seek.com

Cakkie
February 24th, 2000, 11:50 PM
You can use a .ini file. You can use the GetPrivateProfileString or GetPrivateProfileInt API to retrieve a value of such file. To write it, you need to use the API WritePrivateProfileString/WritePrivateProfileInt. It is written to file like this:

[default]
username=cakkie

[custom]
textcolor=red

eg:

' write something to the ini file
retval = WritePrivateProfileString("default","username","cakkie","c:\myIni.ini")
' read something from the ini file
retval = GetPrivateProfileString("default","username","none",uName, 255, "c:\myIni.ini")




For more info, and a complete example, check out http://www.vbapi.com/ref/funcc.html#inifiles

Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.

Ravi Kiran
February 25th, 2000, 05:21 AM
If you want to include the Double quotations also then you can use INput # statement, to read one line at a time into a string buffer, not reading the ""s

Otherwise, for typical key=value pairs, WritePrivateProfilestring/int is best, as the other reply suggests

RK