Simple For..Next query

B

Bails

Hi all. I am trying to write some code for a "Lotto" program (hey its a bit
of fun) It creates 3 profiles of numbers and extrapolates a full 36 game
card from them.

On the 3rd profile ask's a question like "please enter a number between 15
and 36, but one that has NOT been used in Profile 1 or 2".

Then I wanted to offer some suggestions in a statusbar. I tried running a
for next loop starting at 15 and finishing at 36 steping 1 at time and
displaying the result in the status bar. HOWEVER I wanted to exclude any
numbers that had already been provided in the previous profiles.

I have listed the code below but keep getting errors as I have a Next
without for command. How can I re-write it so it works.

Also, how can I get the numbers to appear next to each other along the
Status Bar without having to assign them to a new bar each time. I vaguely
remember being able to put a semi colon (;) at the end of a statement to
indicate that the next number should append to there, but this doesnt work
in .net.

THANKS IN ADVANCE.

For iCounter = 15 To 36 Step 1

Select Case iCounter

case = iFirstNumber Or iSecondNumber Or iThirdNumber Or iFourthNumber Or
iFifthNumber Or iSixthNumber Then

next icounter

Case Else

iSuggestion = iCounter

StatusBar1.Text = iSuggestion;

End Select

Next iCounter
 
G

Guest

Try loading the numbers into a hashtable:

ht.Add(thisNumber, null)

You can then check to see if the number exists already:

If Not ht.Exists(thisNumber) Then
ht.Add(thisNumber, null)
End If

If ht.Count = 6 Then
'You now have your numbers, so start next set of numbers
End If

You can also use a sorted list, if you want the numbers to be sorted from
lowest to highest.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top