VB2010怎么读写INI文件?

VB2010怎么读写INI文件?,第1张

【读函数】参数:节名,主健名,默认值,路径

'读字符串函数

Public Function GetStr(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)

Dim Str As New String(CChar(" "), 50)

GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)

'读取的字符串没有结尾﹐用下面的方法可以很好的处理。

Dim lngLen As Integer

lngLen = InStr(Str, vbNullChar)

Str = Trim$(Left$(Str, lngLen - 1))

Return Str

End Function

【调用】

Private Sub HospitalInfo_Load(ByVal sender...) Handles MyBase.Load

Dim path As String

path = Application.StartupPath + "\Config.ini"

TextBox1.Text = GetStr("Friends", "Name", "", path)

End Sub

【写函数】参数:节名,主健名,默认值,路径

Public Function WriteStr(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As Long

Dim WriteINI As Long

WriteINI = WritePrivateProfileString(Section, AppName, lpDefault, FileName)

End Function

【调用】

Private Sub Button3_Click(....) Handles Button3.Click

Dim path As String

path = Application.StartupPath + "\Config.ini"

WriteStr("Friends", "Name", "ad", path)

WriteStr("Friends", "Age", 1, path)

MsgBox("保存成功!")

End Sub

Dim name As String = ""

        Dim age As Integer

        name = InputBox("请输入姓名")

        age = InputBox("请输入年龄")

        FileOpen(1, "d:\信息.txt", OpenMode.Append)

        WriteLine(1, name, age)

        FileClose(1)

 FileOpen(1, "d:\信息.txt", OpenMode.Append)

        WriteLine(1, name, age)

        FileClose(1)

        Dim h As String

        Dim j As String

        Dim f As String

        f = ""

        h = ""

        j = ""

        While EOF(1) = False

            f = LineInput(1) & vbCrLf & f

        End While

        FileClose(1)

        MsgBox("姓名" & "  " & "年龄" & vbCrLf & f)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12083729.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存