how can i read from a textfile?
i want to make an ini file but i am unable to manage access to certain line. so how can i specify which line the program should read and use a value?
please help me! thank you very much!
Printable View
how can i read from a textfile?
i want to make an ini file but i am unable to manage access to certain line. so how can i specify which line the program should read and use a value?
please help me! thank you very much!
Maybe this will help:
To write a value in an ini file:
To read a value from an ini file:Code:'Declaration:
Private Declare Function WritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA"_
(ByVal HeadingName As String, ByVal KeyName As Any,_
ByVal Value As Any, ByVal lpFileName As String) As Long
'Code to use it:
Dim Return As Long
Return = WritePrivateProfileString("Heading1", "Key1",_
"Value1", "C:\Myini.ini")
'If Return is nonzero it worked, otherwise, it failed
WPCode:'Declaration:
Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA"_
(ByVal lpApplicationName As String, ByVal lpKeyName As Any,_
ByVal lpDefault As String, ByVal lpReturnedString As_
String, ByVal nSize As Long, ByVal lpFileName As String)_
As Long
'Code to use it:
Dim Return As Long
Dim Value As String
Value = String$(255, 0) 'The 255 is the length, the 0 is the char(Return).
Return = GetPrivateProfileString("Heading1", "Key1",_
"C:\Myini.ini", Value, Len(Value), "C:\Myini.ini")
'If Return is nonzero it worked, otherwise, it failed
'The value of the key is specified in the 'Value' string
Well, you can't use Return as a varible because it's already a RESTRICTION.
Yes Escaflowne is right. Return is a reserved word.
Most of us use:
Code:Ret = WritePrivateProfileString("Heading1", "Key1", "Value1", "C:\Myini.ini")
...and still others use lRet or sRet or whatever data type it is...
Good point Parksie, makes code easier to understand by just looking at it.Quote:
Originally posted by parksie
...and still others use lRet or sRet or whatever data type it is...
I find that a lot of people use Retval which means Return Value.
..and some of us just prefex the reservered word
eg... sName or lReturn
...it's a case of preference when it comes to naming variables and one should use varnames that relate to what
you are trying to express in them so others behind you won't struggle with the code... ie. ireflex for Return
surely wouldn't make your variable very easy in association.