-2

当我输入一个二进制数时,它会在 messagebox.show 中给我多个结果。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim s As String
    Dim a, b, c As Long
    a = CLng(Val(TxtBoxInput.Text))
    s = TxtBoxInput.Text
    TxtBoxInput.Clear()

    For i = 1 To Len(s) Step 1
        b = CLng(Mid(s, i, 1))
        c = Len(s) - i
        b = CLng(Val(b) * (2 ^ c))
        TxtBoxInput.Text = CStr(MessageBox.Show(CStr(Val(TxtBoxInput.Text) + b)))
    Next i
End Sub
4

2 回答 2

2

您将使用MsgBox 方法。从您的示例中不确定结果是您想要展示的地方。

MsgBox("Information Here", MsgBoxStyle.Information, "MyTitle")

根据评论编辑

将您的 MessageBox 放在循环之外,如下所示:

Dim s, temp As String
Dim a, b, c As Long

a = CLng(Val(TxtBoxInput.Text))
s = TxtBoxInput.Text
TxtBoxInput.Clear()
For i = 1 To Len(s) Step 1
    b = CLng(Mid(s, i, 1))
    c = Len(s) - i
    b = CLng(Val(b) * (2 ^ c))
    temp = CStr(Val(temp) + b)
 Next i

MessageBox.Show(temp)
于 2013-04-19T01:19:12.777 回答
0
Dim s As String
Dim a, b, c As Long
a = CLng(Val(TxtBoxInput.Text))
s = TxtBoxInput.Text
TxtBoxInput.Clear()

For i = 1 To Len(s) Step 1
    b = CLng(Mid(s, i, 1))
    c = Len(s) - i
    b = CLng(Val(b) * (2 ^ c))
    TxtBoxInput.Text = CStr(Val(TxtBoxInput.Text) + b)
Next i

MSGBOX(TXTBOXINPUT)

于 2013-04-19T03:16:04.997 回答