English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm programming with visual basic, but I don't know if its possible to do a random variable. I want to be able to randomly choose a value for a variable and then use the value to choose one out of two possible message boxes to pop up afterward.

2007-01-10 03:56:29 · 2 answers · asked by Sebastian 1 in Computers & Internet Programming & Design

2 answers

There is a Random function in VB >I think it's RAND()<
The 2 message boxes is just a simple conditional...IF RandomVariable = some qualification then MSGBOX1 ELSE MSGBOX2

2007-01-10 04:15:57 · answer #1 · answered by rod 6 · 1 1

If you want a random number, you can use the RANDOMIZE statement. Then you can MOD the random number by TWO - to see if the number is EVEN or ODD (since we have TWO messages here, that seems to be a logical way to do this). If the random number MOD 2 = 0 (the number is EVEN - MOD returns the REMAINDER after the number is divided by whatever number is after the MOD function) then do one message, otherwise the answer will return a value of 1 - which means that the number isn't divisible by two without having 1 as a remainder - then popup the other message.

2007-01-10 09:31:59 · answer #2 · answered by Richard H 7 · 0 0

fedest.com, questions and answers