Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you read from an .INI file?

Status
Not open for further replies.

Hawkeye123456

Programmer
May 5, 2000
24
0
0
US
I am planning on storing data for my program in an INI file, but I dont know how to read from one. Some one told me that there is an api that does it, but I could not find it. Any help would be nice
 
Public 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


Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long




Jimmy mailto:nhan_tiags@yahoo.com
 
ok thanks for the declairs, but now what do I do with them? I pu them in my program and I was reading through the variables, and could not figure out what each one did.
 
See the following thread - HELP PLEASE!!! Have to use .ini file (REALLY - HELP!) You might have to hit NEXT a couple of times.
 
' Read the fruit.ini file to get parameters
Open sDir & "\fruit.ini" For Input As #1 Len = 80
' Read thru ini file.
Do While Not EOF(1) ' Loop until end of file.
Readini ' Read fruit.ini file.
If EOF(1) Then
Ctr = 0
End If
Loop
Close #1 ' Close file.
Private Sub Readini()
Dim J As Integer
On Error Resume Next
If EOF(1) Then Exit Sub
J = 0
Do Until EOF(1)
Input #1, Temp
If LCase(Mid(Temp, 1, 13)) = "databasename=" Then
DBNam = Mid(Temp, 14, Len(Temp) - 13)
End If
If LCase(Mid(Temp, 1, 10)) = "directory=" Then
DBDrive = Mid(Temp, 11, 1)
DBdir = Mid(Temp, 11, Len(Temp) - 10)
End If
If LCase(Mid(Temp, 1, 11)) = "campheader=" Then
DBHdr = Mid(Temp, 12, Len(Temp) - 10)
End If
If LCase(Mid(Temp, 1, 7)) = "userid=" Then
iniUserID(J) = Mid(Temp, 8, Len(Temp) - 7)
End If
If LCase(Mid(Temp, 1, 7)) = "passwd=" Then
iniUserPassWd(J) = Mid(Temp, 8, Len(Temp) - 6)
J = J + 1
End If
Loop
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top