Visual Basic help

Hello everyone.

I am trying to write a program in Visual Basic (the program is the game of blackjack, to be precise), and am having trouble finding a way to code the program so that once a card is removed from the deck, it will not reappear until the next shuffle. I downloaded a tutorial that suggested using collections to do this… I have only just started learning Visual Basic and have had no exposure with collections until now.

The tutorial I downloaded gave the following example of using collections to randomize a list of items, and then selecting them, making sure there are no repeats. In this example, there are 6 names, instead of a deck of cards being used.

The program halts once it gets to that last line of code, and says:

… whilst highlingting “Rand” as the culprit.

What’s the problem?

I am still only in the beginner’s learning phase of Visual Basic, so please keep any responses as lay as possible ;).

Thank you.

Change “Rand” to “Rnd”.

Tried that already…

The “Rand” function must be defined elsewhere in the program - there’s no such function in VB. It looks like the example is incomplete.

Replacing “Rand” with “Rnd” won’t do it. Rnd only takes one (optional) parameter, not two.

Try adding this function:



Private Function Rand(lLBound As Long, lUBound As Long) As Long
Rand = Int((lUBound + 1 - lLBound) * Rnd) + lLBound
End Function


Good point.

Ok. What Armilla said. Try the function here:

[URL=http://www.vbexplorer.com/VBExplorer/random/random_numbers_1.asp]

Ok, inserting Armilla’s code got it past that line, but the program stops again at…

It stops again at “Me.Cls”. (I have printed the rest of the code).

What it’s trying to do is display the new “jumbled” list of names on the form. “Me” normally means the active form, right? And Cls means clear?

Either way, it’s highlighting Me.Cls and saying, once again:

Some more assistance here would be very appriciated.

And also appreciated.

Is the code actually running in a Form, or is it somewhere else (like a class or module)?

The Me object is only available to code that is defined in a Form, not elsewhere (well…it’s available in classes, which Forms sorta are, but let’s not muddy the issue). “Me.Cls” should be valid for any code running in a Form.