2016-05-09 4 views
0

ユーザーが2つの数値を入力し、その差が正または負である(First Number - Second Number)それらの間に2の増分で数字の行を出力します。Visual Studio 2010:For-Nextループ構造を使用して数値を生成する

例えば、私の最初の数は8であり、私の第二の数は0であった場合、表示は次のようになります2 4 6 8

これは私のコードである:

Private Sub DualInput(sender As System.Object, e As System.EventArgs) Handles btnDualInput.Click 
    'Displays two numbers in increments or decrements of 2. 
    Num3 = InputBox("Enter your first number.", "First Number") 
    Num4 = InputBox("Enter your second number.", "Second Number") 
    Dim increment As Integer 
    'Positive Difference 
    If (Num3 - Num4) > 0 Then 
     For increment = Num3 To Num4 Step 2 
      lblAnsDual.Text += increment 
     Next increment 
     'Negative Difference 
    ElseIf (Num3 - Num4) < 0 Then 
     For increment = Num4 To Num3 Step -2 
      lblAnsDual.Text += increment 
     Next increment 
     'Zero 
    Else : MsgBox("The difference cannot be zero!", MsgBoxStyle.Critical, "Error") 
    End If 
    lblAnsDual.Visible = True 
End Sub 

私はエラーを取得していません、しかし、出力はラベル(私はデフォルトで "Answer"に設定されている)からのテキストのみを返します。

これを修正する方法については、お手伝いをしてください。

答えて

0

私がこのコード

Private Sub DualInput(sender As System.Object, e As System.EventArgs) Handles btnDualInput.Click 
    lblAnsDual.Visible = True 
    'Displays two numbers in increments or decrements of 2. 
    Num3 = InputBox("Enter your first number.", "First Number") 
    Num4 = InputBox("Enter your second number.", "Second Number") 
    Dim increment As Integer 
    'Positive Difference 
    If Num3 > Num4 Then 
     For increment = Num3 To Num4 Step -2 
      lblAnsDual.Text += Str(increment) 
     Next increment 
     'Negative Difference 
    ElseIf Num3 < Num4 Then 
     For increment = Num3 To Num4 Step 2 
      lblAnsDual.Text += Str(increment) 
     Next increment 
     'Zero 
    Else : MsgBox("The difference cannot be zero!", MsgBoxStyle.Critical, "Error") 
    End If 
でそれを自分自身を固定思わ
関連する問題