回复 16楼 jrs123
一个可以通过的方案:谢谢这一高手的代码:Option Explicit '快手改——1
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal _
lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal _
lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName _
As String) As Long
Dim tags As Integer
Dim FN As String
Dim temp_a As String, temp_b As String, temp_c As String, temp_d As String
Dim t1 As String, t2 As String, t3 As String, t4 As String
Private Function IsFileExist(strFileName As String) As Boolean '快手改——2
Dim varFSO As Variant
Set varFSO = CreateObject("Scripting.FileSystemObject")
IsFileExist = varFSO.FileExists(strFileName)
Set varFSO = Nothing
End Function
Private Sub Form_Initialize() '快手改——3
FN = "my.txt"
End Sub
Private Sub Form_Load() '快手改——4
If IsFileExist(FN) = True Then
Call ReadData
End If
Text1.Text = t1
Text2.Text = t2
Text3.Text = t3
Text4.Text = t4
End Sub
Private Sub text1_click() '快手改——5
tags = 1
Call myInput(tags)
End Sub
Private Sub Text2_click() '快手改——6
tags = 2
Call myInput(tags)
End Sub
Private Sub Text3_click() '快手改——7
tags = 3
Call myInput(tags)
End Sub
Private Sub Text4_click() '快手改——8
tags = 4
Call myInput(tags)
End Sub
'如下接收输入函数
Private Sub myInput(tags As Integer) '快手改——9
'获取输入
Dim message, title, defaultValue As String
Dim myValue As String
message = "请输入你的留言" '设置提示信息
title = "InputBox Demo" '设置标题
defaultValue = "" '设置默认值
myValue = InputBox(message, title, defaultValue, 100, 100)
'显示输入对话框
'判断并处理(保存)输入
If myValue = "" Then
MsgBox "没有输入任何内容!", vbInformation + vbOKOnly, "提示"
Else
'保存输入,留言间用特殊标示“||”隔开,不用逗号是因为留言中可能包含逗号,故尽可能避免分拆时错误
'读出原始内容
Call ReadData
'合并保存并显示
Call WriteData(tags, myValue)
End If
End Sub
'如下读取数据函数
Private Sub ReadData() '快手改——10
temp_a = GetINI(FN, "GueseBook", "No1")
temp_b = GetINI(FN, "GueseBook", "No2")
temp_c = GetINI(FN, "GueseBook", "No3")
temp_d = GetINI(FN, "GueseBook", "No4")
t1 = Mid(temp_a, 1, InStr(temp_a, "||") - 1)
t2 = Mid(temp_b, 1, InStr(temp_b, "||") - 1)
t3 = Mid(temp_c, 1, InStr(temp_c, "||") - 1)
t4 = Mid(temp_d, 1, InStr(temp_d, "||") - 1)
End Sub
'如下保存数据函数
Private Sub WriteData(tags As Integer, myValue As String) '快手改——11
Call ReadData
Select Case tags
Case 1
WritePrivateProfileString "GueseBook", "No1", myValue & "||" & temp_a, App.Path & "\" & FN
Text1.Text = myValue
Case 2
WritePrivateProfileString "GueseBook", "No2", myValue & "||" & temp_b, App.Path & "\" & FN
Text2.Text = myValue
Case 3
WritePrivateProfileString "GueseBook", "No3", myValue & "||" & temp_c, App.Path & "\" & FN
Text3.Text = myValue
Case 4
WritePrivateProfileString "GueseBook", "No4", myValue & "||" & temp_d, App.Path & "\" & FN
Text4.Text = myValue
End Select
End Sub
'如下INI文件读取函数
Public Function GetINI(ByRef inifile As String, ByVal section As String, ByVal key As String, Optional ByVal defvalue As String = vbNullString) As String '快手改——12
'inifile INI文件名, section 段落,key 关键字,defvalue 值
Dim thisQU1 As String
Dim QU1 As Long
thisQU1 = Space$(256) '事先定义读取的字串宽度
QU1 = GetPrivateProfileString(section, key, defvalue, thisQU1, 255, App.Path & "\" & inifile)
GetINI = Left$(thisQU1, Len(Trim$(thisQU1)) - 1) '名称
End Function