VB6 trouble

Try This.

Private Sub cmdRun_Click()
Dim i As Integer
Dim Max As Integer
Dim Min As Integer
Max = 25
Min = 1
i = (Int((Max - Min + 1) * Rnd + Min))
mySelect (i)
End Sub

Private Sub mySelect(ByVal myNr As Integer)
Select Case myNr
Case 1
MsgBox "Question 1"
Case 2
MsgBox "Question 2"
'.
'.
'.
'.
Case 25
MsgBox "Question 25"
End Select

Jesper
 
I normally add the randomize timer line in this kind of software


Randomize Statement Example

This example uses the Randomize statement to initialize the random-number generator. Because the number argument has been omitted, Randomize uses the return value from the Timer function as the new seed value.

Dim MyValue
Randomize ' Initialize random-number generator.
MyValue = Int((6 * Rnd) + 1) ' Generate random value between 1 and 6.
 
Add a Button and a label to test the code for yourself. This
code generates 25 numbers 1-25 and stores then in the variable "num". The Constant SIZE can be changed if you need to generate more numbers.

Option Explicit
Const SIZE = 25
Dim num(SIZE) As Integer

Private Sub Command1_Click()
Dim i, j As Integer
Dim duplicate As Integer
Dim MyValue

For i = 0 To SIZE - 1
duplicate = 0
Randomize ' Initialize random-number generator.
' Generate random value between 1 and 25.

MyValue = Int(((SIZE) * Rnd) + 1)
num(i) = MyValue
For j = 0 To i - 1
If num(i) = num(j) Then
duplicate = 1
End If
Next

If (duplicate = 1) Then
i = i - 1
End If

Next

Dim MyString As String
MyString = ""
For j = 0 To SIZE - 1
MyString = MyString & "," & num(j)
Next
Label1 = MyString

End Sub
 

Similar Topics

Hello, I'm trying to solve a problem. The visualisation is done by VB6. How can i figure out wich databit in S7 is linked to wich variable in VB...
Replies
1
Views
1,538
im doing some coding in vb6 and i have an error in this line : Dim myOPCServer As New RSiOPCAuto.OPCServer it gives me this error when compling...
Replies
11
Views
2,301
Good day all. I have a SLC500 that is controlling an air flow rig. The HMI is a PC using a home-made program using VB6. I have no experience with...
Replies
11
Views
4,485
does anybody have an example of how to connect to a 90-30 ge fenuc plc with the SNP-X protcol through visual basic? i have seen something on this...
Replies
5
Views
1,883
G'day there, I want to send real time data to a VB6 application. It works in excel thanks to a previous response from member - plastic, but I...
Replies
0
Views
3,802
Back
Top Bottom