Ini File Manipulation

Top  Previous  Next

In EasyHL7 processing profiles and the default vendorpath are stored in ini files.

The default vendorpath is stored in the win.ini file and processing profiles are stored in local .ini files that you (or the user) can create and distribute.

 

All samples are for VB6.

 

'In the declaration section of a module

 

Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long

 

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

 

Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long

 

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

 

'Then in the module itself

 

Public Sub SetMystring(cArea$, cElem$, cVal$, cFileName$)

Dim i As Long

i = WritePrivateProfileString(cArea$, cElem$, cVal$, cFileName$)

End Sub

 

Public Sub SetWinString(cArea$, cElem$, cVal$)

Dim i As Long

i = WriteProfileString(cArea$, cElem$, cVal$)

End Sub

 

Public Function GetMyString(sect$, subsect$, IniFile$, Optional strDefault As String = "") As String

Dim buff As String, j%, ret$, i%

buff = Space$(2500)

i% = GetPrivateProfileString(sect$, subsect$, "", buff, 2500, IniFile$)

j% = InStr(buff, Chr$(0)) - 1

   If j% > 0 Then

     ret$ = RTrim$(Mid$(buff, 1, j%))

   Else

     If Len(RTrim$(buff)) = 1 And Asc(buff) = 0 Then

       buff = ""

     End If

     ret$ = RTrim$(buff)

   End If

   If ret$ = "" Then

       GetMyString = strDefault

   Else

       GetMyString = ret$

   End If

End Function

 

Public Function GetWinString(strSection As String, strItem As String, Optional DefaultVal As String = "") As String

Dim buff As String, j%, ret$, i%

buff = Space$(2500)

i% = GetProfileString(strSection, strItem, "", buff, 2500)

j% = InStr(buff, Chr$(0)) - 1

   If j% > 0 Then

     ret$ = RTrim$(Mid$(buff, 1, j%))

   Else

     If Len(RTrim$(buff)) = 1 And Asc(buff) = 0 Then

       buff = ""

     End If

     ret$ = RTrim$(buff)

   End If

If ret$ = "" Then

   ret$ = DefaultVal

End If

GetWinString = ret$

End Function