第1个回答 2009-09-07
我做个简单的,您试试看
Option Explicit
'用于记住在TextBox输入数值时所对应的单位
Dim intMark As Integer
Private Sub Combo1_Click()
Dim intTemp As Single
'若TextBox内容不为空,且是数值
If (Text1.Text <> "") And (IsNumeric(Text1.Text) = True) Then
intTemp = Val(Text1.Text)
Select Case Combo1.ListIndex
Case 0
intTemp = intTemp / (10 ^ intMark)
Text1.Text = intTemp
intMark = 0
Case 1
If intMark > 1 Then
intTemp = intTemp / (10 ^ (intMark - 1))
Else
intTemp = intTemp * (10 ^ (intMark + 1))
End If
Text1.Text = intTemp
intMark = 1
Case 2
If intMark > 2 Then
intTemp = intTemp / (10 ^ (intMark - 2))
Else
intTemp = intTemp * (10 ^ (2 - intMark))
End If
Text1.Text = intTemp
intMark = 2
Case 3
intTemp = intTemp * (10 ^ (3 - intMark))
Text1.Text = intTemp
intMark = 3
Case Else
End Select
Else
End If
End Sub
Private Sub Form_Load()
Dim intI As Integer
Combo1.AddItem "米"
Combo1.AddItem "分米"
Combo1.AddItem "厘米"
Combo1.AddItem "毫米"
Combo1.ListIndex = 0
intMark = 0
Text1.Text = 123
End Sub