Night
I'm jumping in for the ride. Like you, I have not worked
with Types before either.
Let me focus on 2 segments of your code .. which I
excerpted from Colin's post.
Declarations
Code:
Dim station_table As station_type
Dim ticket_table(2) As ticket_type
Dim ticket() As Variant
'
Private Type station_type
stationID As Integer
stationName As String
ResavationRef As resavation_type
End Type
Sub ... from Colin
Code:
Private Sub Form_Load()
With station_table
.stationID = 1
.stationName = "Adelaide"
.ResavationRef.resavationID = 1
End With
ReDim Preserve Tickets(3)
With Tickets(1)
.ticketID = 1
.travellerName = "Bob Smith"
.resavationID = 297
.stationStart = 1
.stationEnd = 3
.discountID = 5
.carriageID = 27
' ..... other data here
End With
With Tickets(2)
.ticketID = 2
' ..... other data here
End With
With Tickets(3)
.ticketID = 3
' ..... other data here
End With
MsgBox ("Total number of tickets = " & UBound(Tickets))
End Sub
A few observations .. mainly questions as I'm new at this too
- why is ticket_table(2) dim'd as an array? .. the other Types aren't.
- why isn't there a Private Type ticket_table declaration?
- where do Tickets(1), ..(2), ..(3) come from? .. not declared anywhere
- to deal with your "unsold ticket 2" issue, you might need a loop
EDIT:
I thought I'd give your OP another look-see ...
Sub ... excerpted from your OP
Code:
Private Sub Form_Load()
Dim tickets As String
ticket = Array("0", "1", "2")
For i = LBound(ticket) To UBound(ticket)
ticket_table(ticket(0)).travellerName = "Bob Smith"
ticket_table(ticket(0)).resavationID = 297
ticket_table(ticket(0)).stationStart = 1
ticket_table(ticket(0)).stationEnd = 3
ticket_table(ticket(0)).discountID = 5
ticket_table(ticket(0)).carriageID = 27
ticket_table(ticket(0)).seatID = 1
ticket_table(ticket(0)).carriageID1 = 7
ticket_table(ticket(0)).dateofService = 5 - Dec - 2000
ticket_table(ticket(0)).stationRef.stationID = 1
ticket_table(0).ticketID = 1
ticket_table(ticket(1)).ticketID = 2
ticket_table(ticket(2)).ticketID = 3
tickets = (ticket_table(i).ticketID)
Next i
MsgBox ("Total number of tickets = " + tickets)
End Sub
Most of my earlier questions remain.
Spoo