5 Replies - 934 Views - Last Post: 27 August 2012 - 04:06 PM Rate Topic: -----

#1 CosNick   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-August 12

Error when with IF and Select statements for allocating credits

Posted 26 August 2012 - 07:05 PM

I'm making a Slot Machine for a school project and iv'e ran into a problem. on the form there is 3 image boxes and when the button spin is pressed a random picture appears in each text box this is the code for the spin:
 spin = Int(Rnd() * 8) + 1

       Select Case spin
            Case 1
                Dim bmwin As New Bitmap("c:\a\win.png")
                slot1.Image = bmwin
            Case 2
                Dim bmbar As New Bitmap("c:\a\BAR.png")
                slot1.Image = bmbar
            Case 3
                Dim bmgrape As New Bitmap("c:\a\Grape.png")
                slot1.Image = bmgrape
            Case 4
                Dim bmdiamond As New Bitmap("c:\a\Diamond.png")
                slot1.Image = bmdiamond
            Case 5
                Dim bmdice As New Bitmap("c:\a\Dice.png")
                slot1.Image = bmdice
            Case 6
                Dim bmhorseshoe As New Bitmap("c:\a\HorseShoe.png")
                slot1.Image = bmhorseshoe
            Case 7
                Dim bmclover As New Bitmap("c:\a\Clover.png")
                slot1.Image = bmclover
            Case 8
                Dim bm7 As New Bitmap("c:\a\7.png")
                slot1.Image = bm7
        End Select

and 5 is deducted from the credit label (lblCredit).
lblCredit.Text = Str(Int(lblCredit.Text) - 5)

I have now tried to make each diffrent combination of spins worth diffrent points. I have a test to make if the image 'win' appears in the first image box although i can not get the code quite right, i have what i think would work using a If statement but it does not seem to work with the select case, it says there is a expression expected can anyone see what iv'e done wrong or how to fix this? This is the code
If 
            Select Case spin
                Case 1
                    Dim bmwin As New Bitmap("c:\a\win.png")
                    slot1.Image = bmwin
                    lblCredit.Text = Str(Int(lblCredit.Text) + 10)
            End Select
        End If


Is This A Good Question/Topic? 0
  • +

Replies To: Error when with IF and Select statements for allocating credits

#2 Mina-no-Hime   User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Error when with IF and Select statements for allocating credits

Posted 26 August 2012 - 07:23 PM

It means that you can't just have If stand alone. It's like if you walked up to somebody and just said "If, then go to the store." You have to specify, "if what" - such as "If we're out of milk, then go to the store."
Was This Post Helpful? 0
  • +
  • -

#3 CosNick   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-August 12

Re: Error when with IF and Select statements for allocating credits

Posted 27 August 2012 - 03:19 AM

I have tried many different codes to try and achieve my goal and with your advice in mind but every time i write something different there is always a problem, this is my first ever program so i have next to no knowledge on visual basic this is some more i have tried but failed, if anyone knows how to do this help will be much appreciated

The error for this is Error Operator '=' is not defined for types 'WindowsApplication1.Form4' and 'System.Drawing.Bitmap'.

Private Sub slot1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles slot1.Click
        Dim bmclover As New Bitmap("c:\a\Clover.png")
        If Me = bmclover Then lblCredit.Text = +50
    End Sub


For this bit of code it actually corrupted the other code now where i have made the spins all the bmclovers now say
Error Variable 'bmclover' hides a variable in an enclosing block.
even if i delete the code there is still this error that i am stuck with
Dim clover As Image
        If slot1.Image Is clover Then
            lblCredit.Text = Str(Int(lblCredit.Text) + 100)
        End If

Was This Post Helpful? 0
  • +
  • -

#4 CosNick   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-August 12

Re: Error when with IF and Select statements for allocating credits

Posted 27 August 2012 - 03:32 AM

View PostCosNick, on 27 August 2012 - 03:19 AM, said:

For this bit of code it actually corrupted the other code now where i have made the spins all the bmclovers now say
Error Variable 'bmclover' hides a variable in an enclosing block.
even if i delete the code there is still this error that i am stuck with


This part is fixed
Was This Post Helpful? 0
  • +
  • -

#5 Mina-no-Hime   User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Error when with IF and Select statements for allocating credits

Posted 27 August 2012 - 04:29 AM

View PostCosNick, on 27 August 2012 - 03:19 AM, said:

this is my first ever program so i have next to no knowledge on visual basic

A slot machine program should not be your first program. You need to start small (much smaller), and work your way up. Go back to the basics and start learning there.

View PostCosNick, on 27 August 2012 - 03:19 AM, said:

The error for this is Error Operator '=' is not defined for types 'WindowsApplication1.Form4' and 'System.Drawing.Bitmap'.

    Private Sub slot1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles slot1.Click
        Dim bmclover As New Bitmap("c:\a\Clover.png")
        If Me = bmclover Then lblCredit.Text = +50
    End Sub

The problem is that you don't seem to understand what the Me identifier in Visual Basic is. It isn't the button, it's the form (in this case). Secondly, even if you were using the right item in place of Me, you wouldn't get a positive result (meaning bmclover will never equal one of your other objects in this case) - you're not simply checking to see if it has the same image, you're checking if they're the same control, which they are not.

Your best bet at this point is to go back to the beginning and start building yourself up. You can't simply jump into a program -- you have to know how to crawl before you can walk.
Was This Post Helpful? 1
  • +
  • -

#6 CosNick   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-August 12

Re: Error when with IF and Select statements for allocating credits

Posted 27 August 2012 - 04:06 PM

This was a assigned task not chosen by me, i joined the class late and only have a few days left to complete it :S
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1