Dear all,
I am new in visual basic and i would like some help with the classes in visual basic 6. For demo i made a simple class. The code of the class is the following:
So i would like to make a 100 instances of that traffic_lights. The problem occurs when i try to call the class from my main code. The main code followsvb Code:
Option Explicit 'local variable(s) to hold property value(s) Private mvarstatus As Single 'local copy Private mvardirection As Long 'local copy Public Sub change_direction(ByVal new_direction As Integer) If new_direction > 3 Or new_direction < 0 Then Me.direction = InputBox("Error in light status.Enter a number 1 for forward 2 left turn 3 right turn ", "Error in Direction") Else Me.direction = new_direction End If End Sub Public Sub Changer_status(ByVal new_status As Integer) If new_status > 3 Or new_status < 0 Then Me.status = InputBox("Error in light status.Enter a number 1 for forward 2 left turn 3 right turn ", "Error in Direction") Else Me.status = new_status End If End Sub Public Property Let direction(ByVal vData As Long) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.direction = 5 mvardirection = vData End Property Public Property Get direction() As Long 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.direction direction = mvardirection End Property Public Property Let status(ByVal vData As Single) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.status = 5 If vData > 3 Or vData < 0 Then vData = InputBox("Error in light status.Enter a number 1 for green 2 for orange 3 for red", "Error in status") Else mvarstatus = vData End If End Property Public Property Get status() As Single 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.status If status > 3 Or staus < 0 Then mvarstatus = InputBox("Error in light status.Enter a number 1 for forward 2 left turn 3 right turn ", "Error in Direction") Else status = mvarstatus End If End Property Private Sub Class_Initialize() Me.direction = 0 Me.status = 0 End SubCould someone to help me find out where i making the mistake?vb Code:
Private Sub Form_Load() Dim i As Integer Dim light As traffic_light Set light = New traffic_light Dim lights(100) As traffic_light Set lights(100) = New traffic_light light.direction = 1 light.status = 1 lights(1).change_direction (1) End Sub
Thanks in advance for your time.


Reply With Quote
