看似简单~其实有点难!textbox求和问题!
分别在text1,text2中输入两个值0000001,100
我要求和的结果是0000101
请问怎么实现?? --------------------编程问答-------------------- 把它们当成2进制数字来计算就好了。 --------------------编程问答-------------------- Format(Val(Text1.Text) + Val(Text2.Text), "000000000") --------------------编程问答-------------------- 不知道是不是这样理解 --------------------编程问答-------------------- Format(Val(Text1.Text) + Val(Text2.Text), "000000000")
---正解 --------------------编程问答-------------------- to yangao(人品决定一切,相貌决定人品!)
我看看~一分钟就好 --------------------编程问答-------------------- to yangao(人品决定一切,相貌决定人品!)
问题你这样设置的话
得出来的结果的位数就限定死了啊
比如我在输入0001 和100
我得出来的结果就是000000101
--------------------编程问答-------------------- Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then MsgBox "请输入数字!": Exit Sub
If Not IsNumeric(Text2.Text) Then MsgBox "请输入数字!": Exit Sub
If Len(Text1.Text) >= Len(Text2.Text) Then
num1 = Text1.Text
num2 = Text2.Text
Else
num1 = Text2.Text
num2 = Text1.Text
End If
x_len1 = Len(num1)
x_len2 = Len(num2)
If Mid(num1, x_len2 - 1, 1) > 0 Then x_len2 = x_len2 + 1
thecount = CCur(Right(num1, x_len2)) + CCur(num2)
If Len(thecount) > x_len2 Then
Text3.Text = Left(num1, x_len2 + 1) & thecount
Else
Text3.Text = Left(num1, x_len2) & thecount
End If
End Sub
--------------------编程问答-------------------- '适当按你的要求修改下即可
Dim lngLength As Long
Dim strFormat As String
If Len(Trim(Text1.Text)) > Len(Trim(Text2.Text)) Then
lngLength = Len(Trim(Text1.Text))
Else
lngLength = Len(Trim(Text2.Text))
End If
strFormat = String(lngLength, "0")
MsgBox Format(Val(Text1.Text) + Val(Text2.Text), strFormat) --------------------编程问答-------------------- 楼上的这下可以了 --------------------编程问答-------------------- Dim lngLength As Long
Dim strFormat As String
If Len(Trim(Text1.Text)) > Len(Trim(Text2.Text)) Then
lngLength = Len(Trim(Text1.Text))
Else
lngLength = Len(Trim(Text2.Text))
End If
strFormat = String(lngLength, "0")
MsgBox Format(Val(Text1.Text) + Val(Text2.Text), strFormat)
补充:VB , 控件