Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[resolved]Another noob VB6 question (dealing with cases)


Jeff
 Share

Recommended Posts

Here is the script I put in:

```
Private Sub Purchasbutton_Click()

    Dim Buying As String
    Buying = SelectAnItem.Text

    Select Case Buying
        Case "Sugar"
            If inv1.Caption = "Empty" And Money >= 1 Then
                    inv1.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of sugar."

            ElseIf inv2.Caption = "Empty" And Money >= 1 Then
                    inv1.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of sugar."
            Else
                If Money < 1 Then
                  Newsfeed.AddItem "You don't have enough doubloons to buy that!"
                Else
                    Newsfeed.AddItem "You need more cargospace to buy that!"
            End If
        Case Else
            inv1.Caption = "fail"
    End Select

End Sub
```
And when I run it, I get

> Compile error: Case else outside Select Case

If I take out the case else, I still run into problems.  Anyone have any suggestions on how to fix it?  Or why it is breaking?

–-------Edit-----------------
Now I just go to the debugging screen whenever I put this code in:
```
Private Sub Purchasbutton_Click()

    Dim Buying As String
    Buying = SelectAnItem.Text

    Select Case Buying
        Case "Sugar"
            If inv1.Caption = "Empty" And Money >= 1 Then
                    inv1.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv2.Caption = "Empty" And Money >= 1 Then
                    inv2.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv3.Caption = "Empty" And Money >= 1 Then
                    inv3.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv4.Caption = "Empty" And Money >= 1 Then
                    inv4.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv5.Caption = "Empty" And Money >= 1 Then
                    inv5.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv6.Caption = "Empty" And Money >= 1 Then
                    inv6.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv7.Caption = "Empty" And Money >= 1 Then
                    inv7.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv8.Caption = "Empty" And Money >= 1 Then
                    inv8.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv9.Caption = "Empty" And Money >= 1 Then
                    inv9.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv10.Caption = "Empty" And Money >= 1 Then
                    inv10.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv11.Caption = "Empty" And Money >= 1 Then
                    inv11.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv12.Caption = "Empty" And Money >= 1 Then
                    inv12.Caption = Buying
                    Money = Money - 1
            Else
                If Money < 1 Then
                  Newsfeed.AddItem "You don't have enough doubloons to buy that!"
                Else
                    Newsfeed.AddItem "You need more cargospace to buy that!"
            End If
            End If
        Case "Coffee"
            If inv1.Caption = "Empty" And Money >= 1 Then
                    inv1.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying

            ElseIf inv2.Caption = "Empty" And Money >= 1 Then
                    inv2.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv3.Caption = "Empty" And Money >= 1 Then
                    inv3.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv4.Caption = "Empty" And Money >= 1 Then
                    inv4.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv5.Caption = "Empty" And Money >= 1 Then
                    inv5.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv6.Caption = "Empty" And Money >= 1 Then
                    inv6.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv7.Caption = "Empty" And Money >= 1 Then
                    inv7.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv8.Caption = "Empty" And Money >= 1 Then
                    inv8.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv9.Caption = "Empty" And Money >= 1 Then
                    inv9.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv10.Caption = "Empty" And Money >= 1 Then
                    inv10.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv11.Caption = "Empty" And Money >= 1 Then
                    inv11.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv12.Caption = "Empty" And Money >= 1 Then
                    inv12.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            Else
                If Money < 1 Then
                  Newsfeed.AddItem "You don't have enough doubloons to buy that!"
                Else
                    Newsfeed.AddItem "You need more cargospace to buy that!"
            End If
            End If
            Case "Tobbacco"
            If inv1.Caption = "Empty" And Money >= 1 Then
                    inv1.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying

            ElseIf inv2.Caption = "Empty" And Money >= 1 Then
                    inv2.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv3.Caption = "Empty" And Money >= 1 Then
                    inv3.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv4.Caption = "Empty" And Money >= 1 Then
                    inv4.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv5.Caption = "Empty" And Money >= 1 Then
                    inv5.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv6.Caption = "Empty" And Money >= 1 Then
                    inv6.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv7.Caption = "Empty" And Money >= 1 Then
                    inv7.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv8.Caption = "Empty" And Money >= 1 Then
                    inv8.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv9.Caption = "Empty" And Money >= 1 Then
                    inv9.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv10.Caption = "Empty" And Money >= 1 Then
                    inv10.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv11.Caption = "Empty" And Money >= 1 Then
                    inv11.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv12.Caption = "Empty" And Money >= 1 Then
                    inv12.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            Else
                If Money < 1 Then
                  Newsfeed.AddItem "You don't have enough doubloons to buy that!"
                Else
                    Newsfeed.AddItem "You need more cargospace to buy that!"
            End If
            End If
Case "Cacao"
            If inv1.Caption = "Empty" And Money >= 1 Then
                    inv1.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying

            ElseIf inv2.Caption = "Empty" And Money >= 1 Then
                    inv2.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv3.Caption = "Empty" And Money >= 1 Then
                    inv3.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv4.Caption = "Empty" And Money >= 1 Then
                    inv4.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv5.Caption = "Empty" And Money >= 1 Then
                    inv5.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv6.Caption = "Empty" And Money >= 1 Then
                    inv6.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv7.Caption = "Empty" And Money >= 1 Then
                    inv7.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv8.Caption = "Empty" And Money >= 1 Then
                    inv8.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv9.Caption = "Empty" And Money >= 1 Then
                    inv9.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv10.Caption = "Empty" And Money >= 1 Then
                    inv10.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv11.Caption = "Empty" And Money >= 1 Then
                    inv11.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv12.Caption = "Empty" And Money >= 1 Then
                    inv12.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            Else
                If Money < 1 Then
                  Newsfeed.AddItem "You don't have enough doubloons to buy that!"
                Else
                    Newsfeed.AddItem "You need more cargospace to buy that!"
            End If
            End If
Case "Gold"
            If inv1.Caption = "Empty" And Money >= 2 Then
                    inv1.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying

            ElseIf inv2.Caption = "Empty" And Money >= 2 Then
                    inv2.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv3.Caption = "Empty" And Money >= 2 Then
                    inv3.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv4.Caption = "Empty" And Money >= 1 Then
                    inv4.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv5.Caption = "Empty" And Money >= 2 Then
                    inv5.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv6.Caption = "Empty" And Money >= 2 Then
                    inv6.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv7.Caption = "Empty" And Money >= 2 Then
                    inv7.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv8.Caption = "Empty" And Money >= 2 Then
                    inv8.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv9.Caption = "Empty" And Money >= 2 Then
                    inv9.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv10.Caption = "Empty" And Money >= 2 Then
                    inv10.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv11.Caption = "Empty" And Money >= 2 Then
                    inv11.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv12.Caption = "Empty" And Money >= 2 Then
                    inv12.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            Else
                If Money < 2 Then
                  Newsfeed.AddItem "You don't have enough doubloons to buy that!"
                Else
                    Newsfeed.AddItem "You need more cargospace to buy that!"
            End If
            End If
Case "Silver"
            If inv1.Caption = "Empty" And Money >= 2 Then
                    inv1.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying

            ElseIf inv2.Caption = "Empty" And Money >= 2 Then
                    inv2.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv3.Caption = "Empty" And Money >= 2 Then
                    inv3.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv4.Caption = "Empty" And Money >= 1 Then
                    inv4.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv5.Caption = "Empty" And Money >= 2 Then
                    inv5.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv6.Caption = "Empty" And Money >= 2 Then
                    inv6.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv7.Caption = "Empty" And Money >= 2 Then
                    inv7.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv8.Caption = "Empty" And Money >= 2 Then
                    inv8.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv9.Caption = "Empty" And Money >= 2 Then
                    inv9.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv10.Caption = "Empty" And Money >= 2 Then
                    inv10.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv11.Caption = "Empty" And Money >= 2 Then
                    inv11.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            ElseIf inv12.Caption = "Empty" And Money >= 2 Then
                    inv12.Caption = Buying
                    Money = Money - 2
                    Newsfeed.AddItem "You have succesfully bought a crate of " & Buying
            Else
                If Money < 2 Then
                  Newsfeed.AddItem "You don't have enough doubloons to buy that!"
                Else
                    Newsfeed.AddItem "You need more cargospace to buy that!"
            End If
            End If
        Case Else
            Newsfeed.AddItem "Error: Purchasing insuccessful."
    End Select

End Sub
```
I've gone over it a couple times, but can't seem to see whats wrong…
Link to comment
Share on other sites

Try:

```
Private Sub Purchasbutton_Click()

    Dim Buying As String
    Buying = SelectAnItem.Text

    Select Case Buying
        Case "Sugar"
            If inv1.Caption = "Empty" And Money >= 1 Then
                    inv1.Caption = Buying
                    Money = Money - 1
                    Newsfeed.AddItem "You have succesfully bought a crate of sugar."

            ElseIf inv2.Caption = "Empty" And Money >= 1 Then
                    inv1.Caption = Buying
                    Money = Money - 1
                     Newsfeed.AddItem "You have succesfully bought a crate of sugar."
            Else
                If Money < 1 Then
                   Newsfeed.AddItem "You don't have enough doubloons to buy that!"
                Else
                    Newsfeed.AddItem "You need more cargospace to buy that!"
            End If
            End If
        Case Else
            inv1.Caption = "fail"
    End Select

End Sub

```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...