Do Loop Help VB.Net

dbawannabe

New member
Joined
Mar 5, 2005
Messages
1
Programming Experience
Beginner
Assignment is to build a form that includes 5 contol buttons, each labeled with a type of loop. For each control button, write a small snip of code that accomplishes the following:

For/Next Loop, generate a list of numbers from 15 to 35 and output the results in the Listbox control - this one I managed to figure out.

Do While, Do Until, Do/Loop While, Do/Loop Until, using an input box ask the user to enter a number between 15 and 25 inclusive. Use an If statement to evaluate the response. If the response is correct, use a msg box control to display a Thank You, if incorrect use a msgbox to display a Try Again message. I have tried everything I can think of to make this work, but nothing works. I am taking this class distance learning and the book is junk. I have two other books I have used for reference, but still cannot seem to make it work. Please help if you can.

Here is what I have, I will not bore you with all the code I have tried.

FOR NEXT LOOP WORKS
Private
Sub btnForNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForNext.Click
Dim intCount As Integer

For intCount = 15 To 35

Me.lstResults.Items.Add(intCount)

Next intCount

End Sub

I don't know how to even begin the Do loops. Thanks for any help you can give.

 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
basically you ask the user to input a number (store value in intUserNumber as an integer)then:

VB.NET:
Dim blnCorrect as Boolean = False
Do
  If intUserNumber < 35 and intUserNumber > 15 then
	Messagebox.Show("Thank You")
	blnCorrect = True
  Else
	 Messagebox.Show("Try Again")
 	blnCorrect = False
	'be sure to re-prompt them for a new number otherwise this loop will never end
  End If
Loop Until blnCorrect = True
 
Top Bottom