您好,登錄后才能下訂單哦!
這篇文章給大家介紹VB.NET中怎么讀取INI文件,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
VB.NET讀取INI文件的相關代碼示例:
'聲明INI配置文件讀寫API函數
Private Declare Function GetPrivateProfileString()
Function GetPrivateProfileString Lib "kernel32"
Alias "GetPrivateProfileStringA" (ByVal
lpApplicationName As String, ByVal lpKeyName As
String, ByVal lpDefault As String, ByVal lpReturned
String As String, ByVal nSize As Int32, ByVal
lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString()
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()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()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
Private Sub Form1_Load()Sub Form1_Load(ByVal
sender As System.Object, ByVal e As System.
EventArgs) Handles MyBase.Load
Dim path As String
path = Application.StartupPath + "\server.ini"
TextBox1.Text = GetINI("Server", "IP", "", path)
TextBox2.Text = GetINI("Server", "port", "", path)
End Sub
Private Sub Button1_Click()Sub Button1_Click
(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim path As String
path = Application.StartupPath + "\server.ini"
WriteINI("Server", "IP", TextBox1.Text, path)
WriteINI("Server", "port", TextBox2.Text, path)
MsgBox("配置設置已經成功!!!!")
Me.Close()
Catch ex As Exception
MsgBox("錯誤!!!!")
End Try
End Sub
關于VB.NET中怎么讀取INI文件就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。