Home > Software engineering >  VB to read ini file
VB to read ini file

Time:10-04

This is what my ini file configuration
[ConnStr]
ServerPath_1=winxpensqlmk
Pass_1=haier_2012
UserName_1=sa
DBName_1=Z100

ServerPath_2=winxpensqlmk
Pass_2=haier_2012
UserName_2=sa
DBName_2=Z100_2
[Common]
UpdateCount=100

To open the database operation was carried out on the table, but can you tell me how to do ah,,,, the great god, and he ~ T - T,

CodePudding user response:

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

'Read iniFile
The Public Function Getini (nApp As String, nKey As String, nDefault As String, nFilePath As String) As String
Dim nStr As String, nSize As Long, As Long s

NSize=1024
NStr=String (nSize, 0)
S=GetPrivateProfileString (nApp, nKey nDefault, nStr, nSize, nFilePath) 'GetSet=Left (nStr, s)
S=InStr (nStr, vbNullChar & amp; VbNullChar)

If the s & gt; 0 Then
Getini=Left (nStr, s - 1)
End the If

End the Function
'Write iniFile
Sub Writeini (nApp As String, nKey As String, nValue As String, nFilePath As String)
Dim iLen As Integer
ILen=WritePrivateProfileString (nApp, nKey, nValue, nFilePath)
End Sub

CodePudding user response:

The value of reading ServerPath_1 call
Getini (" ConnStr ServerPath_1 ", ""," ", "your.ini file path")

CodePudding user response:

Then read ini variable to SQL connection string
  •  Tags:  
  • API
  • Related