VB.NET中怎么读取INI文件
这篇文章给大家介绍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 Int32Private 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 StringDim 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 LongWriteINI = 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.LoadDim 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.ClickTry
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文件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
分享文章:VB.NET中怎么读取INI文件
转载来源:http://pwwzsj.com/article/gjcspi.html