Write it like this:
Dim Reel1Num As Long
Reel1Num = (CLng(Rnd * 20) + 1)
Don't use Integer
in VB6 - it represents a 16-bit signed integer and it has slightly less performance than Long
which is really a 32-bit signed integer. This way you also won't run into limits with the 16-bit data type.
The reason your code doesn't work is because the Int()
function doesn't convert the data type of a value to type Integer
- it rounds the specified value to an integer value but keeps its data type.
To convert a value to a particular data type, use the CInt()
, CLng()
, etc. functions. But as I said, avoid using Integer
unless you specifically need it - Long
is better in most cases.
Edit:
After you posted your code, I can't see a definition of the Reel1Num
variable - where is it defined? Is it Reel1Spin
? If that's the case, make sure you enable the Require variable declaration
option in Tools->Options
- it's off by default. If you don't have it on, it's a very easy way to shoot yourself in the foot.
Unrelated to your error, but most of your image objects are defined incorrectly - in VB6, the type of a variable must be specified for every variable, not once per line. So on this line:
Public ImgBeth, ImgWallow, ImgDan, ImgChris, ImgCatBug As StdPicture
you only really create 1 StdPicture
object, all others will be variants. The right way to do it is:
Public ImgBeth As StdPicture, ImgWallow As StdPicture, ImgDan As StdPicture, _
ImgChris As StdPicture, ImgCatBug As StdPicture
Aside from these, I can't see anything wrong with your code - I don't have VB6 installed on my computer. Keep in mind, that VB6 had a funky way of dealing with type mismatch and in some cases the highlighted line may not be the one that causes the actual error. This used to drive me crazy.