7,759
社区成员
发帖
与我相关
我的任务
分享
Dim strLine As String, strItem() As String, tmp As Control
Open App.Path & "\1.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strLine
If InStr(strLine, "=") Then
strItem = Split(strLine, "=")
Exit Do
End If
Loop
Close #1
If Ubound(strItem) = 1 Then
For Each tmp
If tmp.Name = Trim(strItem(0)) Then tmp.Text = Trim(strItem(1))
Next
End if
'Form1
'放1个TextBox、1个CommandButton、1个ScriptControl
Option Explicit
Private Sub Command1_Click()
Dim sScript As String
'你自己改为从文件读取代码'
sScript = "Text1.Text = 1"
With ScriptControl1
.Reset
.Language = "VBScript"
.AddObject "Form1", Me, True
.ExecuteStatement sScript
End With
End Sub
Public Const MAX_TEXT_LENGTH = 1024
Public 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 Integer, ByVal lpFileName As String) As Integer
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal FileName As String) As Integer
Public Function GetIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As String
Dim tStr As String
tStr = Space(MAX_TEXT_LENGTH)
GetPrivateProfileString Section, Key, Chr(32), tStr, LenB(tStr), FileName
GetIni = Trim(tStr)
End Function
Public Sub SetIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
WritePrivateProfileString Section, Key, Value, FileName
End Sub
'用法
'写
'SetIni "C:\Text.ini","Config","Text1.Text","1"
'读
'Text1.Text=GetIni("C:\Text.ini","Config","Text1.Text")
'
'Text.ini内格式
'==================
'[Config]
'Text1.Text=1
'==================