我正在尝试使用do循环将一个单词输入到输入框中,然后在输入框中输入另一个单词并继续运行直到a。输入,然后句子将显示在标签中。可以有人帮忙
Public Class Form1
Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
Dim chrFlag As Char = "."
Dim strSentence As String = ""
Dim strWord As String = ""
Do
strWord = Val(InputBox("Enter 1 Word"))
If strWord <> chrFlag Then
strSentence = strSentence + strWord + " "
End If
Loop Until strWord = chrFlag
Me.lblDisplay.Text = strSentence
End Sub
结束班
答案 0 :(得分:0)
您的行为无序。您无法将所有代码都放在Click操作中,因为您要求的内容需要多次点击。正如您所拥有的那样,您的所有代码都将在第一次单击时执行,您将陷入无限循环。
你应该有一个句子的全局变量,每次点击都会被修改。你实际上并不需要一个循环来满足你的要求,就像语句一样。我会写这样的逻辑;
Class Form1 {
String sentence = "";
Sub OnButtonClick {
sentence = sentence + word;
if word.equals(".") then
view.text = sentence;
sentence = "";
else
sentence = sentence + " ";
end if
}
}