VB 保存现状

来源:百度知道 编辑:UC知道 时间:2024/06/06 05:40:28
窗口关闭的时候自动将text1 text2 text3三个文件框里的数据保存到与程序同目录下的DATA.INI文件里,然后在程序下次启动的时候检测到同文件夹里如果有DATA.INI文件的话 则将DATA.INI里的数据显示到TEXT1 TEXT2 TEXT3 中

程序退出用form_UNload
程序加载用FORM_LOAD

data.ini 格式说明
text1=
text2=
text3=

谁能帮我写一个!? 非常感谢 如果能够实现 另加30分

Option Explicit
Dim myPath As String
Private Sub Form_Load()
Dim mytxt1, mytxt2, mytxt3
myPath = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\" & "DATA.ini")
MsgBox myPath
If Dir(myPath) <> "" Then
Open myPath For Input As #1
Line Input #1, mytxt1
Text1 = Right(mytxt1, Len(mytxt1) - 6)
Line Input #1, mytxt2
Text2 = Right(mytxt2, Len(mytxt2) - 6)
Line Input #1, mytxt3
Text3 = Right(mytxt3, Len(mytxt3) - 6)
Close #1
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Open myPath For Output As #1
Print #1, "Text1=" & Text1
Print #1, "Text2=" & Text2
Print #1, "Text3=" & Text3
Close #1
End Sub

这里有一个类:
Option Explicit

Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName