Creating a Config.INI File in VB6.0

In the Module File I name it INIWrite.bas Here is the code: Author: kevern Copyright © 2009 Kevern Solutions Option Explicit Public Function WriteIniValue(INIpath As String, PutKey As String, PutVariable As String, PutValue As String) Dim temp As String Dim LcaseTemp As String Dim ReadKey As String Dim ReadVariable As String Dim LOKEY As Integer Dim HIKEY As Integer Dim KEYLEN As Integer Dim VAR As Integer Dim VARENDOFLINE As Integer Dim NF As Integer Dim X As Integer AssignVariables: NF = FreeFile ReadKey = vbCrLf & "[" & LCase$(PutKey) & "]" & Chr$(13) KEYLEN = Len(ReadKey) ReadVariable = Chr$(10) & LCase$(PutVariable) & "=" EnsureFileExists: Open INIpath For Binary As NF Close NF SetAttr INIpath, vbArchive LoadFile: Open INIpath For Input As NF temp = Input$(LOF(NF), NF) temp = vbCrLf & temp & "[]" Close NF LcaseTemp = LCase$(temp) LogicMenu: LOKEY = InStr(LcaseTemp, ReadKey) If LOKEY = 0 Then GoTo AddKey: HIKEY = InStr(LOKEY + KEYLEN, LcaseTemp, "[") VAR = InStr(LOKEY, LcaseTemp, ReadVariable) If VAR > HIKEY Or VAR Chr$(13) temp = Left$(temp, Len(temp) - 1) Loop Do Until Left$(temp, 1) > Chr$(13) temp = Mid$(temp, 2) Loop OutputAmendedINIFile: Open INIpath For Output As NF Print #NF, temp Close NF End Function This is the INIRead File I name it INIRead.bas Here is the Code: Option Explicit Public Function ReadIniValue(INIpath As String, KEY As String, Variable As String) As String Dim NF As Integer Dim temp As String Dim LcaseTemp As String Dim ReadyToRead As Boolean AssignVariables: NF = FreeFile ReadIniValue = "" KEY = "[" & LCase$(KEY) & "]" Variable = LCase$(Variable) EnsureFileExists: Open INIpath For Binary As NF Close NF 'SetAttr INIpath, vbArchive LoadFile: Open INIpath For Input As NF While Not EOF(NF) Line Input #NF, temp LcaseTemp = LCase$(temp) If InStr(LcaseTemp, "[") 0 Then ReadyToRead = False If LcaseTemp = KEY Then ReadyToRead = True If InStr(LcaseTemp, "[") = 0 And ReadyToRead = True Then If InStr(LcaseTemp, Variable & "=") = 1 Then ReadIniValue = Mid$(temp, 1 + Len(Variable & "=")) Close NF: Exit Function End If End If Wend Close NF End Function

You can have more sample code in my blog, just take a visit here: http://jackjones2010.blogspot.com/2010/07/creating-configini-file-in-vb60.html Thanks and Good Luck!
Submitted byAnonymous (not verified)on Thu, 09/16/2010 - 21:08

I wonder what is the method to automatically poll key strokes from outside vb applications. and if any source program to this use. Thanks Mike Kim

I am an experience VB Programmer, I don't take advices from other authors, I created this code w/o any help from others. Keep that in mind!

Add new comment