Wednesday, February 16, 2011

Loops

This is a example of a FOR LOOP. The For is the keyword you use to start the loop.

  For i = 1 To 10 Step 1  
       Print("programmershelp")  
     Next i  
   End Sub  

basically what is happening is that it is going to step threw by 1 until it gets to 10

This is a example of Do (While last)

 Public Class Form1  
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
     Dim x As Integer  
     Do  
       Debug.Print("hello")  
       x = x + 1  
     Loop Until x = 10  
   End Sub  
 End Class  

Loop check when the loops ends. So this code means that the loop is going to continue to run until x = 10 then it will stop.

This is a example of Do (While first)

 Public Class Form1  
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
     Dim x As Integer  
     Do Until x = 10  
       Debug.Print("hello")  
       x = x + 1  
     Loop  
   End Sub  
 End Class  

Do checks when the loop starts.

This is a example of a For Each

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
     Dim siteName As String  
     Dim singleChar As Char  
     siteName = "HTTP://NET-INFORMATIONS.COM"  
     For Each singleChar In siteName  
       MsgBox(singleChar)  
     Next  
   End Sub  

This is going to display each letter one by one until it spells the whole thing out.

Monday, February 14, 2011

Practice 3 assignment

1.
 Public Class Form1  
   Private Sub btnMove_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMove.MouseHover  
     Dim P1 As New Point(5, 239)  
     Dim P2 As New Point(39, 215)  
     If btnMove.Location = P1 Then  
       btnMove.Location = P2  
     ElseIf btnExit.Location = P2 Then  
       btnMove.Location = P1  
     Else  
       btnMove.Location = P1  
     End If  
     'btnMove.Location = New Point(39, 151)  
   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  

2.
 Public Class Form1  
   Private Sub btnColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColor.Click  
     'to change the color back and forth i just used a if statement so that if i click the button and it is Black then it will  
     'change to White but if it is not already Black then it would change to black  
     If txtTest.BackColor = Color.Black Then  
       txtTest.BackColor = Color.White  
     Else  
       txtTest.BackColor = Color.Black  
     End If  
   End Sub  
   Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnText.Click  
     'I did this one the same as the color one the only change i made was that i am using text now so the second one is just a  
     'empty string  
     If txtTest.Text = "hello" Then  
       txtTest.Text = " "  
     Else  
       txtTest.Text = "hello"  
     End If  
   End Sub  
   Private Sub btnBorder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorder.Click  
     'This one it the same as the two above.  
     If txtTest.BorderStyle = BorderStyle.Fixed3D Then  
       txtTest.BorderStyle = BorderStyle.None  
     Else  
       txtTest.BorderStyle = BorderStyle.Fixed3D  
     End If  
   End Sub  
   Private Sub btnDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisable.Click  
     'This one is also the same  
     If txtTest.Enabled = False Then  
       txtTest.Enabled = True  
     Else  
       txtTest.Enabled = False  
     End If  
   End Sub  
 End Class  

3.
 Public Class Form1  
   Dim lbl1, lbl2, lbl3 As New Label  
   Dim WithEvents txt1, txt2, txt3 As New TextBox  
   Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click  
     lbl1.AutoSize = True  
     lbl1.Text = "Hi"  
     Me.Controls.Add(lbl1)  
     lbl1.Location = New Point(8, 163)  
     lbl2.AutoSize = True  
     lbl2.Text = "Good"  
     Me.Controls.Add(lbl2)  
     lbl2.Location = New Point(5, 236)  
     lbl3.AutoSize = True  
     lbl3.Text = "Morning"  
     Me.Controls.Add(lbl3)  
     lbl3.Location = New Point(1, 6)  
     txt1.Location = New Point(65, 6)  
     Me.Controls.Add(txt1)  
     txt1.Name = "txt1"  
     txt2.Location = New Point(125, 240)  
     Me.Controls.Add(txt2)  
     txt2.Name = "txt2"  
     txt3.Location = New Point(54, 166)  
     Me.Controls.Add(txt3)  
     txt3.Name = "txt3"  
   End Sub  
   Private Sub txthightlight1() Handles txt1.MouseEnter  
     txt1.BackColor = Color.Blue  
   End Sub  
   Private Sub txthightlight1B() Handles txt1.MouseLeave  
     txt1.BackColor = Color.White  
   End Sub  
   Private Sub txthightlight2() Handles txt2.MouseEnter  
     txt2.BackColor = Color.Black  
   End Sub  
   Private Sub txthightlight2B() Handles txt2.MouseLeave  
     txt2.BackColor = Color.White  
   End Sub  
   Private Sub txthightlight3() Handles txt3.MouseEnter  
     txt3.BackColor = Color.Red  
   End Sub  
   Private Sub txthightlight3B() Handles txt3.MouseLeave  
     txt3.BackColor = Color.White  
   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  

Practice 2 assignment

1.
 Public Class Form1  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
     Dim total, cost As Integer  
     cost = 60  
     If cost < 50 Then  
       total = cost + 5  
     ElseIf cost > 50 Then  
       total = cost  
     End If  
     MessageBox.Show(total)  
   End Sub  
 End Class  

2.
 Public Class Form1  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
     Dim temp As Integer  
     temp = 72  
     If temp < 72 Then  
       MessageBox.Show("The Heat is on")  
     ElseIf temp > 76 Then  
       MessageBox.Show("The AC is on")  
     ElseIf temp > 77 & temp < 71 Then  
       MessageBox.Show("Idle")  
     End If  
   End Sub  
 End Class  

3.
 Public Class Form1  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
     Dim size As String  
     Dim shirt As String  
     size = 5  
     shirt = size  
     Select Case shirt  
       Case 0 To 2  
         size = "XS"  
       Case 3 To 5  
         size = "S"  
       Case 6 To 8  
         size = "M"  
       Case 9 To 11  
         size = "L"  
       Case Is < 11  
         size = "XL"  
     End Select  
     MessageBox.Show(size)  
   End Sub  
 End Class  

Friday, February 4, 2011

This is some code that allows you to add buttons, labels, textbox, and listbox

     Dim Button1 As New Button  
     Dim textbox1 As New TextBox  
     Dim label1 As New Label  
     Dim listbox1 As New ListBox  
   
     Button1.Text = "Go"  
     Me.Controls.Add(Button1)  
   
     textbox1.Text = "Hello"  
     textbox1.BackColor = Color.Chocolate  
     Me.Controls.Add(textbox1)  
   
     label1.Text = "Good Morning"  
     label1.BackColor = Color.Aqua  
     Me.Controls.Add(label1)  
   
     listbox1.BackColor = Color.Black  
     listbox1.Location = New System.Drawing.Point(77, 162)  
     Me.Controls.Add(listbox1)  

First you have to declare then control then from there you have to set what ever you want like the size, back color, or any thing like that. Once you done with that you have to follow it with a Me.Controls.Add() to add it to the form.