Home > Software engineering >  Vb6 a simple fixed string random content problem
Vb6 a simple fixed string random content problem

Time:10-23

Thank you, could you tell me my train of thought is
Dim (a)


A is an array of content for (44, 11, 22, aa, bb) five elements, assuming that
Each random get one of the elements, rather than one of the Numbers, that is to string don't number,
I tried RND but always in a mess, and the number is not string,
Please give a code,,, have a better chance if you can control,,,,,,,
RND every time before I get the result of all seem to is within the scope of the lowest and highest number, rather than the one of five, such as ceiling, 55 floor 11
There are 22 among,33,44
Is
(11,22,33,44,55)
I want a random one of them, what every time is a 25,36,48,15 this
The younger brother VB is not too fine, only understand a little point, self-taught, so that the product comforms to the you
Thank you

CodePudding user response:

If the above array is five digits, so through the random number divided by the remainder after 5 to 0,1,2,3,4 this a few number of the array subscript, the subscript to obtain the content of the array, not feasible?

CodePudding user response:

If you think of the array, 11, 22, and is also a string of words:

MsgBox a (Int (RND () * 5))

Otherwise:
StrTmp="12"
The Do While IsNumeric (strTmp)
StrTmp=a (Int (RND () * 5))
Loop
MsgBox strTmp

Probability control is also available, see how do you control,

CodePudding user response:

 Private Sub Command1_Click () 
Dim a (4) As the Variant
Dim As Long I
A (0)=11
A (1)=22
A (2)="aa"
A (3)=44
A (4)="bb"
I=CLng (Rnd * 5)
The Debug. Print a (I), TypeName (a (I))
End Sub
'bb String
'44 Integer
'44 Integer
'22 Integer
'aa String
'bb String
'11 Integer
'bb String
'bb String
'bb String
'11 Integer
'aa String
'bb String
'...

CodePudding user response:

It's very simple
Will is loading a new array of Numbers in the array
Then use the new array (Int (Rnd () * UBound (array))) get a random elements,
  • Related