Tuesday, October 22, 2013

Car goes forward and Hits a Wall

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
     picCar1.Left = picCar1.Left + 10

If picCar1.Top < rightBorder.Top + rightBorder.Height And picCar1.Top > rightBorder.Top - picCar1.Height And picCar1.Left < rightBorder.Left + rightBorder.Width And picCar1.Left > rightBorder.Left - picCar1.Width Then
     
Timer1.Enabled = False

 
End If

End Sub

Friday, October 11, 2013

SORT used with Slot Machineto make it easier to detect the 3 bars

Public Class frmMain
    Public counter, x, y, z As Integer
    Public sort(3) As Integer
    Public f, s, w As Integer


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        lblBobSlotMachine.Text = "Bob's Slot Machine"
        Randomize()
        picMoney.Visible = False
        counter = 0
        'Start Dice
        Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        x = Int(Rnd() * 7) + 1
        If x = 1 Then
            picBox1.Image = My.Resources.Bar
        ElseIf x = 2 Then
            picBox1.Image = My.Resources.Bar2
        ElseIf x = 3 Then
            picBox1.Image = My.Resources.Bar3
        ElseIf x = 4 Then
            picBox1.Image = My.Resources.Apple
        ElseIf x = 5 Then
            picBox1.Image = My.Resources.Cherry
        ElseIf x = 6 Then
            picBox1.Image = My.Resources.grapes
        Else
            picBox1.Image = My.Resources.seven
        End If

        y = Int(Rnd() * 7) + 1
        If y = 1 Then
            PicBox2.Image = My.Resources.Bar
        ElseIf y = 2 Then
            PicBox2.Image = My.Resources.Bar2
        ElseIf y = 3 Then
            PicBox2.Image = My.Resources.Bar3
        ElseIf y = 4 Then
            PicBox2.Image = My.Resources.Apple
        ElseIf y = 5 Then
            PicBox2.Image = My.Resources.Cherry
        ElseIf y = 6 Then
            PicBox2.Image = My.Resources.grapes
        Else
            PicBox2.Image = My.Resources.seven
        End If
        z = Int(Rnd() * 7) + 1
        If z = 1 Then
            PicBox3.Image = My.Resources.Bar
        ElseIf z = 2 Then
            PicBox3.Image = My.Resources.Bar2
        ElseIf z = 3 Then
            PicBox3.Image = My.Resources.Bar3
        ElseIf z = 4 Then
            PicBox3.Image = My.Resources.Apple
        ElseIf z = 5 Then
            PicBox3.Image = My.Resources.Cherry
        ElseIf z = 6 Then
            PicBox3.Image = My.Resources.grapes
        Else
            PicBox3.Image = My.Resources.seven
        End If
        counter = counter + 1
        If counter = 10 Then
            Winner()
            Timer1.Enabled = False

        End If
    End Sub
    Sub sortItems()
        sort(1) = x
        sort(2) = y
        sort(3) = z
        For f = 1 To 3
            For s = 1 To 2
                If sort(f) < sort(s) Then
                    w = sort(f)
                    sort(f) = sort(s)
                    sort(s) = w
                End If
            Next s
        Next f
        x = sort(1)
        y = sort(2)
        z = sort(3)

    End Sub

    Sub Winner()
        sortItems()
        lblTestx.Text = x
        lbltesty.Text = y
        lblTestz.Text = z

        If x = 1 And y = 2 And z = 3 Then
            'all bars - all differnt
            lblBobSlotMachine.Text = "3 different Bars- $800 Winner"
            picMoney.Visible = True
        End If
        If x = 1 And y = 1 And z = 3 Then
            'all bars - all differnt
            lblBobSlotMachine.Text = "3 different Bars- $800 Winner"
            picMoney.Visible = True
        End If
        If x = 1 And y = 1 And z = 2 Then
            'all bars - all differnt
            lblBobSlotMachine.Text = "3 different Bars- $800 Winner"
            picMoney.Visible = True
        End If

        If x = 2 And y = 3 And z = 3 Then
                lblBobSlotMachine.Text = "Bars- $800 Winner"
                picMoney.Visible = True
            End If
            If x = 2 And y = 3 And z = 3 Then
                    lblBobSlotMachine.Text = "Bars- $800 Winner"
                    picMoney.Visible = True
                End If

        If x = y And x = z Then
            lblBobSlotMachine.Text = "Bars- $800 Winner"
            picMoney.Visible = True
        End If


                If x = y And x = z Then
                    lblBobSlotMachine.Text = "$800 Winner"
                    picMoney.Visible = True
                End If

                If x = 7 And y = 7 And z = 7 Then
                    lblBobSlotMachine.Text = "$1000 Winner"
                    picMoney.Visible = True
                End If

                If x = 5 Or y = 5 Or z = 5 Then
                    lblBobSlotMachine.Text = "$2 Winner"
                    picMoney.Visible = True
                End If
    End Sub


End Class

Monday, September 9, 2013

Simple Slot Machine- 3 Labels, Button and Money

'Simple Slot Machine
Dim x, y, z As Integer
        Randomize()
picMoney.Visible = False
        x = Int(Rnd() * 7) + 1
        y = Int(Rnd() * 7) + 1
        z = Int(Rnd() * 7) + 1
        lblBox1.Text = x
        lblBox2.Text = y
        lblBox3.Text = z
       If x=7 or y=7 and z= 7 Then
            picMoney.Visible = True
       End If

Thursday, June 13, 2013

Function- New Price

Public Class Form1
    Dim dblNewPrice As Double
    Dim dblCurrentPrice As Double
    Private Function GetNewPrice(ByVal dblPrice As Double) As Double
        'Increases the current price by 5% and returns the new price
        dblPrice = dblPrice * 1.05
        Return dblPrice
    End Function


    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        Double.TryParse(txtCurrentPrice.Text, dblCurrentPrice)
        dblNewPrice = GetNewPrice(dblCurrentPrice)
        lblNewPrice.Text = dblNewPrice.ToString("c2")
    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class


 




Thursday, November 29, 2012

Getting Data from Notepad File

Import Data From a Text File
Public Class Form1
    Dim Word(5) As String
    Dim X, y As Integer
    Dim inFile As IO.StreamReader
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        For y = 1 To 5
            'y=1 at first: the first word that is added to the listbox is Word(1)
            lstBox1.Items.Add(Word(y))
        Next y
        btnGo.Enabled = False
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' This program reads 5 data Items
        'inFile opens the notpad file

        inFile = IO.File.OpenText("C:\Users\administrator\VB\spelling.txt")
        'this function loops around until there is no more data
        Do Until inFile.Peek = -1
            X = X + 1
            'Word(1) stores the first word; Word(2) stores the second word and so forth
            Word(X) = inFile.ReadLine
        Loop
        'you must close the file
        inFile.Close()
    End Sub
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

Thursday, January 12, 2012

Numeric plus decimal points only in Textboxes

If (e.KeyChar < "1" Or e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
e.Handled = True