'读字符串函数
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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)