您好,登录后才能下订单哦!
这篇文章给大家介绍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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。