楼主可能认为我昨天的Text1建议是一句调侃,那你就大错特错了。
你的难题可用三步来解决。
1.在程序任何需要处(可多处)插入中断过程(Sub) Stops,运行中只要Text1.Text<>"",就可以拿到程序的控制权。
2.中断后,利用Text1的窗口进行人机对话。或对变量重新赋值(图片左侧有示意),或对控件参数作调整(图片右侧有示意)。
3.修改完成后,清空Text1,将程序的控制权交出,程序接着中断前的代码再运行。
另:给出的代码中,Timer1没有实际用途,只是为了方便演示,和示意Stops可以插到任何处的示范而已,可以删除。
Option Explicit '只有公共变量才是 Form1.Control
Public iR1 As Integer, iS1 As String
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 500
iS1 = "0"
Text1.Text = ""
End Sub
Private Sub Text1_Change()
Dim pp As Integer, rr As Variant, ss As String
Dim tt As Integer, Obj As Object
On Error GoTo Sp '最后字符为 "~" 时,此 Sub 才有效
If Right$(Text1.Text, 1) <> "~" Then Exit Sub
pp = InStr(1, Text1.Text, "=")
If pp > 0 Then
If Left$(Text1.Text, 1) = "i" Then
ss = Left$(Text1.Text, pp - 1)
rr = Mid$(Text1.Text, pp + 1, Len(Text1.Text) - pp - 1)
CallByName Form1, ss, VbLet, rr
tt = -1
Else
For Each Obj In Form1.Controls
ss = Obj.Name
tt = Len(ss)
If Left$(Text1.Text, tt) = ss Then
ss = ""
Exit For
End If
Next
If ss <> "" Then
Text1.Text = "错误!"
Exit Sub
ElseIf Mid$(Text1.Text, tt + 1, 1) = "." Then
ss = Mid(Text1.Text, tt + 2, pp - tt - 2)
Else
ss = Obj.Name
End If
rr = Mid$(Text1.Text, pp + 1, Len(Text1.Text) - pp - 1)
rr = Mid$(Text1.Text, pp + 1, Len(Text1.Text) - pp - 1)
CallByName Obj, ss, VbLet, rr
tt = -1
End If
End If
Sp: pp = Len(Text1.Text) - 1 '删 "~" ,避免反复调用
Text1.Text = Left$(Text1.Text, pp)
If Err.Number > 0 Or tt <> -1 Then Text1.Text = "无效输入!"
End Sub
Private Sub Stops()
Do While Text1.Text <> ""
Text1.SetFocus
DoEvents
Loop
End Sub
Private Sub Timer1_Timer()
Dim pp As Integer
Cls
For pp = 0 To 8
Print "iR1=" & CStr(iR1),
Next pp
Print
Stops
For pp = 0 To 4
Print "iS1=" & iS1 & ",";
Next pp
Print
End Sub