0

Hi there,

I am new here, and i humbly seek your assistance, when i try to increment the for loop it jumps to case 5 of the select case statement. What i actually want is when i press the Next button it shows me a set of options which is case 2, but now it straight away jumps to case 5.

Please help me.

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Dim counter1 As Byte = 1

        For counter1 = 1 To 5
            Select Case counter1
                Case 1
                    lblQuestion.Text = "What is the country of this flag?"
                    GroupBox1.Text = "Question 1 of 5"
                    RadioButton1.Text = "Singapore"
                    RadioButton2.Text = "Malaysia"
                    RadioButton3.Text = "Indonesia"
                    RadioButton4.Text = "China"

                    picQuiz.Image = Image.FromFile("singaporeflag.gif")
                    picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

                Case 2
                    lblQuestion.Text = "What is the country of this flag?"
                    GroupBox1.Text = "Question 2 of 5"
                    RadioButton1.Text = "Singapore"
                    RadioButton2.Text = "Malaysia"
                    RadioButton3.Text = "Indonesia"
                    RadioButton4.Text = "China"

                    picQuiz.Image = Image.FromFile("china-flag.gif")
                    picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

                Case 3
                    lblQuestion.Text = "What is the country of this flag?"
                    GroupBox1.Text = "Question 3 of 5"
                    RadioButton1.Text = "Singapore"
                    RadioButton2.Text = "Malaysia"
                    RadioButton3.Text = "Indonesia"
                    RadioButton4.Text = "China"

                    picQuiz.Image = Image.FromFile("id-lgflag.gif")
                    picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

                Case 4
                    lblQuestion.Text = "What is the country of this flag?"
                    GroupBox1.Text = "Question 4 of 5"
                    RadioButton1.Text = "Singapore"
                    RadioButton2.Text = "Malaysia"
                    RadioButton3.Text = "Indonesia"
                    RadioButton4.Text = "China"

                    picQuiz.Image = Image.FromFile("malaysia-flag.jpg")
                    picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

                Case 5
                    lblQuestion.Text = "What is the country of this flag?"
                    GroupBox1.Text = "Question 5 of 5"
                    RadioButton1.Text = "Singapore"
                    RadioButton2.Text = "Malaysia"
                    RadioButton3.Text = "Indonesia"
                    RadioButton4.Text = "China"

                    picQuiz.Image = Image.FromFile("united-states-flag.gif")
                    picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

            End Select
            counter1 += 1
        Next

        'Next counter1

    End Sub
End Class
5
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by Riga
0

am i incrementing the counter twice? i though i only am initiating it once at line 62?

0

First Change the counterl to an integer type, second remove line 62. This will allow the counter to increment correctly. The Byte type cannot be treated as a integer while in a Select Case, as the values are reference differently. For a better understanding look Here as this gives a better understanding of your Select Case statement. Bytes also increment differently in a For Loop, as a byte is looked at in machine addressing and values rather than as an integer.

Edited by zinnqu: Missed a few words

0

First Change the counterl to an integer type, second remove line 62. This will allow the counter to increment correctly. The Byte type cannot be treated as a integer while in a Select Case, as the values are reference differently. For a better understanding look Here as this gives a better understanding of your Select Case statement. Bytes also increment differently in a For Loop, as a byte is looked at in machine addressing and values rather than as an integer.

So what do you propose if i want to increment the counter1 by 1 so that every time i click the next button it will show a new set of options.

For example: the default value is case 1, when i click next button i want to increment the counter by 1 so that it will proceed to case 2 and so on and so forth. I have tried Do while loop however to no avail.

0

The question here is that every time you launch the button click event, you fire a loop, always ending at 5.

Istead you can
1) declare the counter outside the button click procedure
2) monitor their value to start at 1 showing the button when the forms Load, and hidding the button when his value is greater than 5 after incrementing it in the button click procedure.
3)Finally, remove the For and the Next sentences.

Hope this helps.

1

If that is what you need to do then change the for loop to a while loop.

this will allow you to set a command loop where you control the increments and allow you to wait for the input of the user.

public sub Button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
While Counter1 <= 5

Select Case counter1

Case 1

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 1 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("singaporeflag.gif")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

Case 2

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 2 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("china-flag.gif")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

Case 3

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 3 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("id-lgflag.gif")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

Case 4

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 4 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("malaysia-flag.jpg")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

Case 5

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 5 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("united-states-flag.gif")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

End Select

counter1 += 1
End Sub

Delcare couter1 as a global Integer

All is well!

Edited by zinnqu: n/a

0

If that is what you need to do then change the for loop to a while loop.

this will allow you to set a command loop where you control the increments and allow you to wait for the input of the user.

public sub Button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
While Counter1 <= 5

Select Case counter1

Case 1

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 1 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("singaporeflag.gif")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

Case 2

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 2 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("china-flag.gif")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

Case 3

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 3 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("id-lgflag.gif")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

Case 4

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 4 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("malaysia-flag.jpg")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

Case 5

lblQuestion.Text = "What is the country of this flag?"

GroupBox1.Text = "Question 5 of 5"

RadioButton1.Text = "Singapore"

RadioButton2.Text = "Malaysia"

RadioButton3.Text = "Indonesia"

RadioButton4.Text = "China"

 

picQuiz.Image = Image.FromFile("united-states-flag.gif")

picQuiz.SizeMode = PictureBoxSizeMode.StretchImage

 

End Select

counter1 += 1

End While

End Sub

Delcare couter1 as a global Integer

All is well!

Don't forget for the END WHILE :) :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.