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

Tuesday, December 21, 2010

Chapter 17- Sub Procedures

Page 263-264 - Do the problem from the reading (weekly pay solution)
Page 367369 - Do problem from reading (Birthday Solution)

Pick 2 out of the 3... or do them all
Page 381-382- Problem 4- Grade Solution- then #5 Modify Grade Solution

Problem #7- Water Bill

Problem #8- Cable Company

Friday, December 17, 2010

Yahtzee Stuff

'Rolls 3 times and disables button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndiceRoll.Click
countRolls = countRolls + 1
Timer1.Enabled = True
If countRolls = 3 Then
btndiceRoll.Enabled = False
End If
End Sub

'Dice change 10 times and holding dice
If Hold1.Checked = False Then
r1 = Int(Rnd() * 6) + 1
End If
' rnd picks a number between 0 and .999999
If r1 = 1 Then
Dice1.Load("c:\Programming2010\Dice\d1.gif")
End If
If r1 = 2 Then
Dice1.Load("c:\Programming2010\Dice\d2.gif")
End If
If r1 = 3 Then
Dice1.Load("c:\Programming2010\Dice\d3.gif")
End If
If r1 = 4 Then
Dice1.Load("c:\Programming2010\Dice\d4.gif")
End If
If r1 = 5 Then
Dice1.Load("c:\Programming2010\Dice\d5.gif")
End If
If r1 = 6 Then
Dice1.Load("c:\Programming2010\Dice\d6.gif")
End If

'rolls Dice 10 times before stopping
If countTimes = 10 Then
Timer1.Enabled = False
countTimes = 0
End If