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.

Monday, January 31, 2011

If Statements

This is a example of a If statement.
  Dim name, correct As String  
     name = "Dalonte"  
     If name = "Dalonte" Then  
       correct = "Yes"  
     End If  
     MessageBox.Show(correct)  

I just basically give name a value and put it in a if statement saying if name = the name i put in then it would output Yes.

This is a example of a If statment where its either or
  Dim name, correct As String  
     name = "Gibson"  
     If name = "Dalonte" Then  
       correct = "yes"  
     Else  
       correct = "no"  
     End If  
     MessageBox.Show(correct)  
This is just like my example above but the only thing i did different is that i added a "ELSE" so that if the name does not match up it was say no

This is a example of a if statement where many decisions are made
  Dim name, As String  
     name = "anderson"  
     If name = "Dalonte" Then  
       MessageBox.Show("First Name")  
     ElseIf name = "Gibson" Then  
       MessageBox.Show("last name")  
     ElseIf name = "anderson" Then  
       MessageBox.Show("Middle Name")  
     End If  
The only thing that i did different on this one is that i added a elseif statement which allows me to make more then 2 decisions.

This is a example of a case statement
 Select [ Case ] testexpression  
   [ Case expressionlist  
     [ statements ] ]  
   [ Case Else  
     [ elsestatements ] ]  
 End Select  

1st you have to make a Select case statement, then from there you can make as many cases as you want followed by a end Select

Friday, January 28, 2011

How to join a String with another String

  Dim FirstName As String  
     Dim LastName As String  
     Dim FullName As String  
     FirstName = "Bill"  
     LastName = "Gates"  
     FullName = FirstName & LastName  
     MessageBox.Show(FullName)  

first you have to declare your variables then you have to give each variable a value such as Bill and Gates. From there you add them together with a "&" sign then display it with a messagebox

Monday, January 24, 2011

How to set variables

This is how you set the following variables: String, Integer, Decimal

 Public Class Form1  
   Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click  
     Dim FirstName As String  
     Dim Age As Integer  
     Dim GPA As Decimal  
     Dim Result As DialogResult  
     FirstName = "Dalonte"  
     Age = "22"  
     GPA = "3.6"  
     Result = MessageBox.Show(FirstName & Age & GPA)  
   End Sub  
 End Class  

The Integer data type provides optimal performance on a 32-bit processor. The other integral types are slower to load and store from and to memory.

The Decimal data type provides the greatest number of significant digits for a number. It supports up to 29 significant digits and can represent values in excess of 7.9228 x 10^28. It is particularly suitable for calculations, such as financial, that require a large number of digits but cannot tolerate rounding errors.

The default value of Decimal is 0.

Use the String data type to hold multiple characters without the array management overhead of Char(), an array of Char elements.

The default value of String is Nothing (a null reference). Note that this is not the same as the empty string (value "").

The default value of Integer is 0.

This is how you set a Boolean variable:

 Dim runningVB As Boolean  
 ' Check to see if program is running on Visual Basic engine.  
 If scriptEngine = "VB" Then  
   runningVB = True  
 End If  

Use the Boolean data type to contain two-state values such as true/false, yes/no, or on/off.

The default value of Boolean is False.

When Visual Basic converts numeric data type values to Boolean, 0 becomes False and all other values become True. When Visual Basic converts Boolean values to numeric types, False becomes 0 and True becomes -1.


This is how to convert a number variable into a string

 Dim int As Integer = 789  
 Dim str As String = int.ToString()  
 str now holds 789 as a string.  

you start by declaring a int, then after you do that you have to declare a string = int.ToString()
so that what ever value you entered for your int will also be = to your string variable.

This is how you convert a int into a decimal

 Dim d=132.31223 as Double  

This is easy all you have to do is that when you declare your int follow it by as Double

This is how you join two strings

 Dim FirstName As String  
 Dim LastName As String  
 Dim FullName As String  
 FirstName = "Bill"  
 LastName = "Gates"  
 FullName = FirstName & LastName  
 Textbox1.Text = FullName  

For this one all you have to is declare to string and give them both a value. This declare another variable witch will be use to join them. Once you declare another string to add the other two you have to = is to String1 & String2

Wednesday, January 19, 2011

Repeatable Process examples

Calculate the final grade

30% Blog 40% assignments 10% peer evals 20% final

86/100 Blog, 345/450 assignment, 43/50 peer, 55/80 final

BlogTP = 100
BlogS = 86 86/100 x .3 = 23.8
BlogW = .3
BlogP = BlogS/BlogTP


AssignTP = 450
AssignS = 345
AssignP = AssignS/AssignTP(76.7) x .4 = 30.68

Grade = (BlogP x BlogW) + (AssignP x AssignW)