home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "libINI"
- Option Explicit
- '
- Global gblIniFile As String ' name of INI file/registry entry
-
-
- Function GetWinDir() As String
- '
- ' get the Windows launch dir
- '
- Dim cTemp As String
- Dim nTemp As Integer
- '
- cTemp = String$(255, 32) ' reserve space
- nTemp = OSGetWindowsDirectory(cTemp, 255) ' call API
- GetWinDir = Left$(cTemp, nTemp) ' set return value
- End Function
-
- Function GetIniStr(cSection As String, ByVal cItem As String, ByVal cDefault As String)
- '
- ' this routine looks for cItem
- ' in section cSection. If it
- ' is not found, the item is
- ' written using the cDefault
- ' value.
- '
- Dim cTemp As String
- '
- ' try to get it
- cTemp = GetSetting(gblIniFile, cSection, cItem, cDefault)
- '
- ' returned default? may be missing, write it to be sure
- If Trim(UCase(cTemp)) = Trim(UCase(cDefault)) Then
- SaveSetting gblIniFile, cSection, cItem, cDefault
- End If
- '
- GetIniStr = cTemp ' set return value
- '
- End Function
-
- 'Function GetWinDir() As String
- ' '
- ' ' get the windows launch dir
- ' '
- ' Dim cTemp As String
- ' Dim nTemp As Integer
- ' '
- ' cTemp = String$(255, 32) ' reserve space
- ' nTemp = OSGetWindowsDirectory(cTemp, 255) ' call API
- ' GetWinDir = Left$(cTemp, nTemp) ' set return value
- 'End Function
-
-
-
-
- Function WriteINIStr(ByVal cSection, ByVal cItem, ByVal cDefault) As Integer
- '
- ' write cKeyName into cSection
- SaveSetting gblIniFile, cSection, cItem, cDefault
- WriteINIStr = True ' in case they ask!
- '
- End Function
-
-
- Public Function OpenINI(Optional cININame As Variant)
- '
- ' For 32-bit
- ' set gblIniFile name for registry calls
- '
- ' For 16-bit
- ' set gblIniFile name for File calls
- ' if not there, create a new one
- '
- OpenINI = True ' assume all goes OK
- '
- If IsMissing(cININame) Then ' no parm passed?
- cININame = App.EXEName ' set to this app
- End If
- gblIniFile = Trim(cININame) ' clean up spaces
- '
- Dim nFile As Integer ' for file channel
- Dim cFile As String ' for file name
- '
- ' If we're running in 16-bit environment
- ' we have to get to a file in the Windows
- ' launch directory. We'll make sure it's
- ' there and create a new one if needed.
- '
- #If Win16 Then
- On Error Resume Next ' keep quiet about errors
- nFile = FreeFile ' get free file channel
- cFile = gblIniFile + ".INI" ' fill out file name
- Open cFile For Input As nFile ' try to open it
- If Err <> 0 Then ' some error
- If Err = 53 Then ' was it 'FileNotFound?'
- Open cFile For Output As nFile ' create it
- Else ' uh-oh....
- MsgBox Error$, vbCritical, "Error opening INI File - " + Str(Err)
- OpenINI = False ' we failed!
- End If
- End If
- Close nFile 'close channel
- #End If
- '
- End Function
-