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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Ini Files 1

Status
Not open for further replies.

nateshk

Programmer
Jan 16, 2001
49
0
0
HK
Hi,

Can anybody help me with storing, editing and reading from an *.ini file through VB 6.0.

Thanx in advance


Natesh

 
Check out the FAQs in this forum.
Here's a thread: faq222-1198
I haven't viewed this if it actually works but the API functions used will steer you in the right direction. [/b][/i][/u]*******************************************************[sub]
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Try this. Let us know if it helps

'In your form
Option Explicit

Private Sub Form_Load()
iniPath = "c:\temp\temp.ini"
End Sub

Private Sub Command2_Click()
Call IniDetailsWrite("Section1", "Value1", "WrittenValue")
End Sub

Private Sub Command1_Click()
MsgBox IniDetailsRead("Section1", "Value1", "Section1Value1")
End Sub

'--------------
'In a module
Option Explicit

Dim sdata As String
Dim lDataLen
Public iniPath As String

Declare Function WritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal _
lpKeyName As Any, ByVal lsString As Any, _
ByVal lplFilename As String) As Long

Declare Function GetPrivateProfileString Lib _
"kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal _
lpKeyName As String, ByVal lpDefault As _
String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As _
String) As Long


'Return ini information

Public Function IniDetailsRead(Section As String, Key As String, DefaultValue As String) As String
'you may want to use app.path as the default dir
sdata = Space$(500)
lDataLen = GetPrivateProfileString(Section, Key, DefaultValue, sdata, Len(sdata), iniPath)
IniDetailsRead = Trim(Left$(sdata, lDataLen))
End Function

Public Function IniDetailsWrite(Section As String, Key As String, NewValue As String)
' Set the string value.
Dim retval
retval = WritePrivateProfileString(Section, Key, NewValue, iniPath)
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top