16,717
社区成员
发帖
与我相关
我的任务
分享
Dim sr As IO.StreamReader = New IO.StreamReader("SQLTemp.txt")
Dim strSQL As String = ""
Dim strRead As String = ""
While sr.EndOfStream = False
strRead = sr.ReadLine
if strRead = [DB] then
While strRead = [DBCOMMON]
strRead = sr.ReadLine
strSQL += strRead
End While
end if
End While
'聲明INI配置檔讀寫API函數
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
'定義讀取配置檔函數
Public Function GetINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As String
Dim Str As String = LSet(Str, 256)
GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)
Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)
End Function
'定義寫入配置檔函數
Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As Long
WriteINI = WritePrivateProfileString(Section, AppName, lpDefault, FileName)
End Function
讀取
Try
Dim path As String
path = Application.StartupPath + "\reportTool.ini "
Me.txtTrioLabel.Text = GetINI("DB", "JDBC_USE_CONN_POOL", "", path)
Me.txtCFlag.Text = GetINI("DB", "JDBC_CONN_POOL_MAX", "", path)
....
Catch ex As Exception
' MsgBox(ex.Message)
End Try
Dim sr As IO.StreamReader = New IO.StreamReader("SQLTemp.txt")
Dim strSQL As String = ""
While sr.EndOfStream = False
if sr.ReadLine = [DB] then
strSQL += sr.ReadLine
elseif sr.ReadLine = [DBCOMMON] then
Exit while
end if
End While