PDA

Click to See Complete Forum and Search --> : how to read from an INI file???


rino_2
Nov 26th, 1999, 03:14 AM
Hi,

I would like to type a caption into a text box and then save that caption into an INI file sao that the next time I staret the program the caption is in the form.caption. I use this code to write to the file:

open "C:\Caption.ini" for output as #1
write #1, text1.text
close # 1

now, thats the writing side of things taken care of but how do I read the caption from the file and place it in form1s caption???

Richard

Aaron Young
Nov 26th, 1999, 11:41 AM
If you want to use a True INI File, then you need to use the GetPrivateProfileString and WritePrivateProfileString API's, eg.

Private 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
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

Private Sub Form_Load()
Dim sBuff As String * 255
'Load the Caption from the INI File.
Call GetPrivateProfileString(App.Title, "Caption", "Default Caption", sBuff, 255, "C:\Caption.ini")
Caption = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
Text1 = Caption
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Save the New Caption to the INI File.
Call WritePrivateProfileString(App.Title, "Caption", ByVal Text1.Text, "C:\Caption.ini")
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net