‘Class random, simple class demo

 

Option Explicit

 

Private Const MAX_INTEGER = 32767

Private Const MIN_INTEGER = -32768

 

Private mMax As Long

Private mMin As Long

 

Private value As Integer

 

Public Property Let max(ByVal newMax As Integer)

    mMax = newMax

End Property

 

Public Property Let min(ByVal newMin As Integer)

    mMin = newMin

End Property

 

Public Property Get max() As Integer

    max = mMax

End Property

 

Public Property Get min() As Integer

    min = mMin

End Property

 

'Public Function getMin() As Integer

'    getMin = min

'End Function

'

'Public Function getMax() As Integer

'    getMax = max

'End Function

'

'Public Sub setMax(ByVal newMax As Integer)

'    max = newMax

'End Sub

'

'Public Sub setMin(ByVal newMin As Integer)

'    min = newMin

'End Sub

 

Public Function nextRnd() As Integer

    nextRnd = CInt(Rnd * (max - min + 1) + min)

End Function

 

Private Sub Class_Initialize()

    max = MAX_INTEGER

    min = MIN_INTEGER

End Sub

 

‘Form code: goes in your form with one button

 

Option Explicit

 

Private Sub cmdNextRandom_Click()

 

    Dim random As CRandom

   

    Set random = New CRandom

   

    random.max = 10

    random.min = 1

   

    MsgBox random.nextRnd & " " & _

            random.max & " " & _

            random.min

           

    Dim random2 As New CRandom

   

    random2.max = 100

    random2.min = 50

   

    MsgBox random2.nextRnd & " " & _

            random2.max & " " & _

            random2.min

 

 

End Sub