Dim sandwich_value As Currency
Dim sandwich_type As String
Private Sub Form_Load()

Dim filling(7)

filling(0) = "Bacon"
filling(1) = "Lettuce"
filling(2) = "Tomato"
filling(3) = "Onion"
filling(4) = "Cheese"
filling(5) = "Ham"
filling(6) = "Chicken"

For k = 0 To 6

List1.AddItem filling(k)

Next

For k = 0 To 1

Option1(k).Value = False

Next

End Sub

Private Sub List1_Click()

If List1.ListIndex = -1 Then Exit Sub

List2.AddItem List1.Text

List1.RemoveItem List1.ListIndex

End Sub

Private Sub List2_Click()

If List2.ListIndex = -1 Then Exit Sub

List1.AddItem List2.Text

List2.RemoveItem List2.ListIndex

End Sub


Private Sub Option1_Click(Index As Integer)

    Select Case Index

        Case 0
            sandwich_value = 2.1
            sandwich_type = "large"
        Case 1
            sandwich_value = 1.3
            sandwich_type = "small"

    End Select

End Sub

Private Sub Command1_Click()

Label6.Caption = "The price of your " & sandwich_type & " sandwich with " & List2.ListCount & " fillings is £" & sandwich_value + (List2.ListCount * 0.2) & "0"

End Sub

Private Sub Command2_Click()

    'reset form to its load settings
    Unload filling ' Unload form.
    Load filling ' Load it.
    Show ' Show it.

End Sub

Back to vb6 exercises