Monday, February 28, 2011

Practice #4 number 2



Dim total, goal, months, pay, years As Integer months = 0
 
pay = 25 

months += 1
total += pay 'adds pay CInt(txtMonthyIncome.Text) 
Do While total < 10000
LooplblYears.Text = (months / 12).ToString ' loops months so that a counnter is kept

Friday, February 18, 2011

Do While and For each loops.

This code shows Do While First

  • The Do While...Loop is used to execute statements until a certain condition is met. The following Do Loop counts from 1 to 100.
Dim number As Integer
number = 1
Do While number <= 100
number = number + 1
Loop
Do (While last)
For
 For  n = 1 To 3
            MsgBox(n)
        Next
Her is an example of a for each loop
    For Each singleChar In siteName
            MsgBox(singleChar)
        Next

Monday, February 14, 2011

Selecting items in a listbox

This code will show how to select items in a listbox

Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim shirt, pants, shoes As String 
shirt = "shirt"
pants = "pants"
shoes = "shoes"


Me.Close()
End Sub ClassMe.lstTotalItems.Items.Add(shirt)Me.lstTotalItems.Items.Add(pants)Me.lstTotalItems.Items.Add(shoes)Me.lstTotalItems.ScrollAlwaysVisible = TrueEnd Sub
lstTotalItems.SelectedItem = Private Sub btnItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem1.Click"shirt"End Sub
lstTotalItems.SelectedItem = Private Sub btnItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem2.Click"pants"End Sub
lstTotalItems.SelectedItem = Private Sub btnItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem3.Click"shoes"End Sub 



EndPrivate Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Adding Items to a listbox

This code will demonstrate how to add items and select them in a listbox

 Public Class Form1
  
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
     Dim shirt, pants, shoes As String
  
     Shirt = "shirt"
  
     pants = "pants"
  
     shoes = "shoes"
  
     Me.lstTotalItems.Items.Add(shirt)
  
     Me.lstTotalItems.Items.Add(pants)
  
     Me.lstTotalItems.Items.Add(shoes)
  
     Me.lstTotalItems.ScrollAlwaysVisible = True
  
   End Sub
  
   Private Sub btnItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem1.Click
  
     lstTotalItems.SelectedItem = "shirt"
  
   End Sub
  
   Private Sub btnItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem2.Click
  
     lstTotalItems.SelectedItem = "pants"
  
   End Sub
  
   Private Sub btnItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem3.Click
  
     lstTotalItems.SelectedItem = "shoes"
  
   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
  

Adding Buttons and labels programmatically ...

This code shows how to add textboxes and labels and set their location background color etc...

  Public Class Form1
  
 Dim lbl1, lbl2, lbl3 As New Label
  
 Dim WithEvents txt1, txt2, txt3 As New TextBox
  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
 lbl1.Text = "Hello"
  
 lbl1.Location = New Point(8, 163)  
 lbl2.AutoSize = true
  
 Me.Controls.Add(lbl1)
  
 lbl2.Text = "Press the reset button"
  
 lbl2.Location = (123, 5)
  
 lbl3.AutoSize = true
  
  Me.Controls.Add(lbl2)
  
 lbl3.Text = "Live life "
  
 lbl3.Location = New Point(5, 236)True
  
 txt1.Location =New Point(1, 6)
  
  txt1.Name ="txt1"
  
  Me.Controls.Add(lbl3)
  
 Me.Controls.Add(txt1)" 
  
  txt2.Location =New Point(65, 6)
  
  txt2.Name =)"txt2" 
  
  txt3.Location = New Point(124, 240) 
  
 txt3.Name ="txt3" 
  
  Me.Controls.Add(txt2)
  
 New Point(54, 166)   
  
 Me.Controls.Add(txt3) 
  
  
  
 End Sub 
  
 End Class
  

Manipulationg Buttons and Textboxes

This code will manipulate a textbox on a form

 Public Class Form1
  
   Private Sub btnBackGroundColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackgroundColor.Click
  
     'This changes the text colors back and forth between tomato and white
  
     If txtOutputbox.BackColor = Color.White Then
  
       txtOutputbox.BackColor = Color.Tomato
  
     Else
  
       txtOutputbox.BackColor = Color.White
  
     End If
  
   End Sub
  
   Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  
     'Enables the textbox
  
     If txtOutputbox.Enabled = False Then
  
       txtOutputbox.Enabled = True
  
     Else
  
       txtOutputbox.Enabled = False
  
     End If
  
   End Sub
  
   Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  
     'This one it the same as the two above.
  
     If txtOutputbox.BorderStyle = BorderStyle.Fixed3D Then
  
       txtOutputbox.BorderStyle = BorderStyle.None
  
     Else
  
       txtOutputbox.BorderStyle = BorderStyle.Fixed3D
  
     End If
  
   End Sub
  
   Private Sub btnText_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnText.Click
  
     If txtOutputbox.Text = "If heaven was a mile away" Then
  
       txtOutputbox.Text = " "
  
     Else
  
       txtOutputbox.Text = "If heaven was a mile away"
  
     End If
  
   End Sub
  
 End Class
  

in this post i will Show how manipulate events on a button

These lines of code will change the location of the button.

Public Class Form1Dim var As Integer 

var += 1
LblCounter.Text = var
Private Sub form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ClickEnd Sub



Private Sub button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnterDim p1 As New Point(52, 214) 'changes the point of the button when the mouuse is entered Dim p2 As New Point(227, 10)If Button1.Location = p1 Then  'if the buttons location doesnt equal the 1st point then the second locations is enabledButton1.Location = p2
ElseButton1.Location = p1 ' (Else If) the point goes back to the 1st point
End If 
 

End
End Sub Class

Monday, February 7, 2011

How to add a button, and a textbox to a page programmatically.

I will demonstrate how to add a textbox to a program programatically.

Dim textbox1 As New TextBoxtextbox1.Size =
TextBox8.ReadOnly = True  'makes the text box Read-onlytextbox1.Name = "TextBox1" 'Creates a name for the textboxTextBox1.Location =
TextBox8.Width = AutoSize
TextBox8.Height = AutoSize


'These lines of code Place a button of code Dim button As New Button 'adds a button to the formbutton.AutoSize = Truebutton.Text = "Exit" 'Places a name on the button
button.Location =

'This code adds a list box to the form
Dim lstShoes As New ListBox
Me.Controls.Add(button) 'Adds button to controlsNew Point(5, 239) ' Places the button in a specific area on the form.
Me.Controls.Add(textbox1) 'Adds textbox1 to the control
New Point(60, 185)'this operation sets the location of the new textboxes
New Size(150, 20)' sets size