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 < LOKEY Then GoTo AddVariable: GoTo RenewVariable: AddKey: temp = Left$(temp, Len(temp) - 2) temp = temp & vbCrLf & vbCrLf & "[" & PutKey & "]" & vbCrLf & PutVariable & "=" & PutValue GoTo TrimFinalString: AddVariable: temp = Left$(temp, Len(temp) - 2) temp = Left$(temp, LOKEY + KEYLEN) & PutVariable & "=" & PutValue & vbCrLf & Mid$(temp, LOKEY + KEYLEN + 1) GoTo TrimFinalString: RenewVariable: temp = Left$(temp, Len(temp) - 2) VARENDOFLINE = InStr(VAR, temp, Chr$(13)) temp = Left$(temp, VAR) & PutVariable & "=" & PutValue & Mid$(temp, VARENDOFLINE) GoTo TrimFinalString: TrimFinalString: temp = Mid$(temp, 2) Do Until InStr(temp, vbCrLf & vbCrLf & vbCrLf) = 0 temp = Replace(temp, vbCrLf & vbCrLf & vbCrLf, vbCrLf & vbCrLf) Loop Do Until Right$(temp, 1) > 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
Comments
About the code:
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!
~kevern~
how to create a payroll history of an employee?
how to create a payroll history of an employee? from the day of hiring up to present..
how to create a payroll history of an employee?
Good day,
What you mean payrol history? history of every employee transaction or the employee database.?
polling method in vb6
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
learn how to give credit to the original author
sana sinama mo na din un iniwrite.bas..
anyways, here is the original author of this module..
Bernie Madigan
Hey!
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!
Pages
Add new comment