vb6.0编写的程序如何保存修改设置??
请各位为我编写一下这个的具体程序代码!按修改键Command1时把已选定的Commad2或Commad3或Commad4的Caption修改成Text1的内容,要求能保存...
请各位为我编写一下这个的具体程序代码!
按修改键Command1时把已选定的Commad2或Commad3或Commad4的Caption修改成Text1的内容,
要求能保存所修改的内容下次进入软件时显示上次修改的内容!
请列出具体代码!
如图:http://pdkm04.mofile.com/p/1/2008/2/24/O7/O737ERFRZA_203.bmp
如何保存到ini文件当中? 展开
按修改键Command1时把已选定的Commad2或Commad3或Commad4的Caption修改成Text1的内容,
要求能保存所修改的内容下次进入软件时显示上次修改的内容!
请列出具体代码!
如图:http://pdkm04.mofile.com/p/1/2008/2/24/O7/O737ERFRZA_203.bmp
如何保存到ini文件当中? 展开
1个回答
展开全部
'两个函数 , 先在一个模快中定义API函数
Declare Function WritePrivateProfileString Lib "KERNEL32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal LpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
'如果是读INT值可以用字符串转化,所以没有另外定义函数
'Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPriviteProfileIntA" (ByVal lpApplicationname As String, ByVal LpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileString Lib "KERNEL32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal LpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'定义读与写INI文件的函数
'****读INI文件****
'文件名 lpFileName 如果不存在会自己创建,如果只有文件名,默认在Windows\system目录下
'[lpAppName]
'lpKeyName=取回的设置值
'lpDefault 当键值不存在时的默认值
Public Function ReadINI(ByVal lpFileName As String, ByVal lpAppName As String, ByVal LpKeyName As String) As String
Dim Temp As String * 255
Dim lpDefault As String
lpDefault = ""
If GetPrivateProfileString(lpAppName, LpKeyName, lpDefault, Temp, Len(Temp), lpFileName) <= 0 Then
ReadINI = ""
Else
ReadINI = MyTrim(Temp) 'MyTrim函数见下
End If
End Function
'****写INI文件****
'[lpAppName]
'lpKeyName=lpString
Public Function WriteINI(ByVal lpFileName As String, ByVal lpAppName As String, ByVal LpKeyName As String, ByVal lpString As String) As Boolean
If WritePrivateProfileString(lpAppName, LpKeyName, lpString, lpFileName) = 0 Then
WriteINI = False
Else
WriteINI = True
End If
End Function
'包含三个函数,分别取Rtrim,Ltrim,Trim
'可以去字符串中如ASC码为0,10,13,32的字符
Public Function MyRtrim(ByVal Tmpstr As String)
Dim i, S As Integer
i = Len(Tmpstr)
If i = 0 Then
MyRtrim = ""
Exit Function
End If
S = Asc(Right(Tmpstr, 1))
While (S = 0 Or S = 13 Or S = 10 Or S = 32) And i > 0
i = i - 1
Tmpstr = Left(Tmpstr, i)
If Len(Tmpstr) = 0 Then
MyRtrim = ""
Exit Function
End If
S = Asc(Right(Tmpstr, 1))
Wend
MyRtrim = Tmpstr
End Function
Public Function MyLtrim(ByVal Tmpstr As String)
Dim i, S As Integer
i = Len(Tmpstr)
If i = 0 Then
MyLtrim = ""
Exit Function
End If
S = Asc(Left(Tmpstr, 1))
While (S = 0 Or S = 13 Or S = 10 Or S = 32) And i > 0
i = i - 1
Tmpstr = Right(Tmpstr, i)
If Len(Tmpstr) = 0 Then
MyLtrim = Tmpstr
Exit Function
End If
S = Asc(Left(Tmpstr, 1))
Wend
MyLtrim = Tmpstr
End Function
Public Function MyTrim(ByVal Tmpstr As String)
Tmpstr = MyLtrim(Tmpstr)
Tmpstr = MyRtrim(Tmpstr)
MyTrim = Tmpstr
End Function
---------------------------------
把以上内容保存到一个模块里,再按提示调用。在点修改后写入三个值,然后表单load事件里,又读INI文件中这三个值并显示到对应的command上。
Declare Function WritePrivateProfileString Lib "KERNEL32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal LpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
'如果是读INT值可以用字符串转化,所以没有另外定义函数
'Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPriviteProfileIntA" (ByVal lpApplicationname As String, ByVal LpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileString Lib "KERNEL32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal LpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'定义读与写INI文件的函数
'****读INI文件****
'文件名 lpFileName 如果不存在会自己创建,如果只有文件名,默认在Windows\system目录下
'[lpAppName]
'lpKeyName=取回的设置值
'lpDefault 当键值不存在时的默认值
Public Function ReadINI(ByVal lpFileName As String, ByVal lpAppName As String, ByVal LpKeyName As String) As String
Dim Temp As String * 255
Dim lpDefault As String
lpDefault = ""
If GetPrivateProfileString(lpAppName, LpKeyName, lpDefault, Temp, Len(Temp), lpFileName) <= 0 Then
ReadINI = ""
Else
ReadINI = MyTrim(Temp) 'MyTrim函数见下
End If
End Function
'****写INI文件****
'[lpAppName]
'lpKeyName=lpString
Public Function WriteINI(ByVal lpFileName As String, ByVal lpAppName As String, ByVal LpKeyName As String, ByVal lpString As String) As Boolean
If WritePrivateProfileString(lpAppName, LpKeyName, lpString, lpFileName) = 0 Then
WriteINI = False
Else
WriteINI = True
End If
End Function
'包含三个函数,分别取Rtrim,Ltrim,Trim
'可以去字符串中如ASC码为0,10,13,32的字符
Public Function MyRtrim(ByVal Tmpstr As String)
Dim i, S As Integer
i = Len(Tmpstr)
If i = 0 Then
MyRtrim = ""
Exit Function
End If
S = Asc(Right(Tmpstr, 1))
While (S = 0 Or S = 13 Or S = 10 Or S = 32) And i > 0
i = i - 1
Tmpstr = Left(Tmpstr, i)
If Len(Tmpstr) = 0 Then
MyRtrim = ""
Exit Function
End If
S = Asc(Right(Tmpstr, 1))
Wend
MyRtrim = Tmpstr
End Function
Public Function MyLtrim(ByVal Tmpstr As String)
Dim i, S As Integer
i = Len(Tmpstr)
If i = 0 Then
MyLtrim = ""
Exit Function
End If
S = Asc(Left(Tmpstr, 1))
While (S = 0 Or S = 13 Or S = 10 Or S = 32) And i > 0
i = i - 1
Tmpstr = Right(Tmpstr, i)
If Len(Tmpstr) = 0 Then
MyLtrim = Tmpstr
Exit Function
End If
S = Asc(Left(Tmpstr, 1))
Wend
MyLtrim = Tmpstr
End Function
Public Function MyTrim(ByVal Tmpstr As String)
Tmpstr = MyLtrim(Tmpstr)
Tmpstr = MyRtrim(Tmpstr)
MyTrim = Tmpstr
End Function
---------------------------------
把以上内容保存到一个模块里,再按提示调用。在点修改后写入三个值,然后表单load事件里,又读INI文件中这三个值并显示到对应的command上。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询