我设计了一个vb程序,现在遇到了两个问题不能解决,希望各位高手可以帮忙解决。

2024-12-25 04:18:33
推荐回答(2个)
回答1:

需要定义一个变量ComputYN,用于判断当a、b、c、d 改变时是否需要计算。
这里又定义了两个文本框:TextX、TextY,用于存放你计算出来的x、y,也可根据自己的需要做其它处理。

程序启动时进入密码校验程序,这里的密码为“123”,可根据需要设置

Private ComputYN As Boolean
Private Sub Form_Load()
ComputYN = False
Command4.Caption = "Command4"

Dim Mima As String, mima1 As String
Dim Nci As Integer

Mima = "123"
Nci = 0
While Nci < 3
mima1 = InputBox("请输入密码(第" & Nci + 1 & "次):", "输入密码", "")
mima1 = Trim(mima1)
If Mima = mima1 Then GoTo 10
Nci = Nci + 1
If Nci = 3 And Mima <> mima1 Then
'Form1.Hide
End
End If
Wend
10 '
End Sub

Private Sub Command4_Click()
If ComputYN = False Then
Comput1
ComputYN = True
Command4.Caption = "计算"
Else
ComputYN = False
Command4.Caption = "Command4"
End If
End Sub

Private Sub Comput1()
'测绘重心
Dim a As Single
Dim b As Single
Dim c As Single
Dim d As Single
Dim e As Single

Dim G As Single
Dim X As Single
Dim Y As Single

a = Val(Text1.Text) + 0.0000000001
b = Val(Text2.Text) + 0.0000000001
c = Val(Text3.Text) + 0.0000000001
d = Val(Text4.Text) + 0.0000000001
e = Val(Text5.Text) + 0.0000000001
G = (a + b + c + d) / 9.8 - e
X = (4000 * a + 4000 * b + 10400 * c + 10400 * d) / (a + b + c + d)
Y = (3600 * a + 6000 * b + 3600 * c + 6000 * d) / (a + b + c + d)

TextX.Text = X
TextY.Text = Y
End Sub

Private Sub Text1_Change()
If ComputYN = True Then Comput1
End Sub

Private Sub Text2_Change()
If ComputYN = True Then Comput1
End Sub
Private Sub Text3_Change()
If ComputYN = True Then Comput1
End Sub
Private Sub Text4_Change()
If ComputYN = True Then Comput1
End Sub
Private Sub Text5_Change()
If ComputYN = True Then Comput1
End Sub

回答2:

1.
if 密码错误次数=3 then end

2.
你的这个想法不错,但是编程比较复杂,要设置一个全局变量作为开关, 计算过程作为一个单独的子程序,当文本框的change事件发生,就调用一次。