[求助]获取焦点问题
我打算编写这样一个程序:界面如下图所示,其中r为圆半径,L为圆周长,S为圆面积。当我在三个文本框中任意选中一个并输入数字后,另外的两个文本框给出相应的结果。
程序代码如下,比较复杂,应该如何简化?是不是可以应用焦点?谢谢!
Private Sub Command1_Click()
Dim r As Single, L As Single, S As Single, pi As Single
pi = 3.14159
If Text1.Text <> "" Then
r = Val(Text1.Text)
L = 2 * pi * r
S = pi * r * r
Text2.Text = Str(L)
Text3.Text = Str(S)
ElseIf Text2.Text <> "" Then
L = Val(Text2.Text)
r = L / 2 / pi
S = pi * r * r
Text1.Text = Str(r)
Text3.Text = Str(S)
ElseIf Text3.Text <> "" Then
S = Val(Text3.Text)
r = Sqr(S / pi)
L = 2 * pi * r
Text1.Text = Str(r)
Text2.Text = Str(L)
End If
End Sub