Friday, August 13, 2010

Friday, August 13th 2010

Alright, I am going to start with a tutorial by Michael Halvorson, looking at basic math operators.

What is the point of the Group box in Visual Basic? The tutorial uses a group box and I am not sure why, other than it looks cool.

The tutorial uses radio buttons which is cool


If rbtnAddition.Checked = True Then
TextBox1.Text = FirstNum + SecondNum
End If


I find it confusing - all the different variable types that are available


Dim FirstNum, SecondNum As Double


Next, I will do another tutorial by Mr. Halvorson on using Decision structures.

One of the neat features of this tutorial is the chance to use MaskedTextBox, in this case I will use one for Social Security numbers.

I changed the PIN from five digits to four, since that is more common in the States (?)


If MaskedTextBox1.Text = "340-92-7267" _
And mtxtPin.Text = "1234" Then
MsgBox("Welcome to the system!")
Else
MsgBox("I don't recognize this number!")
End If


Halvorson also introduces the AndAlso and the ElseIf - with AndAlso it basically means that if the first condition isn't true then the program does not even bother to test the second condition, reducing the chance of run time errors as well as speeding up the program - Dan Mabbutt writes, If you place the expression that is most likely to be false in the leftmost position when using AndAlso, you can prevent execution cycles from being used to evaluate the rightmost expression. Cool beans!

Halvorson also takes a look at Select Case Decision Structures

I changed his tutorial around a little, for one, I replaced Germany with France in the Form Load event procedure.


lstCountryBox.Items.Add("England")
lstCountryBox.Items.Add("France")
lstCountryBox.Items.Add("Mexico")
lstCountryBox.Items.Add("Italy")


I also changed the code for the SelectedIndexChanged even procedure for the list box


Select Case lstCountryBox.SelectedIndex
Case 0
lblGreeting.Text = "Hello, programmer."
lblGreeting.Font = New System.Drawing.Font("Times New Roman", 15)

Case 1
lblGreeting.Text = "Bonjour, programmeur."
lblGreeting.Font = New System.Drawing.Font("Algerian", 15)
Case 2
lblGreeting.Text = "Hola, programador."
lblGreeting.Font = New System.Drawing.Font("Garamond", 15, FontStyle.Italic)
Case 3
lblGreeting.Text = "Ciao, programmatore."
lblGreeting.Font = New System.Drawing.Font("Futura", 15, FontStyle.Bold)
End Select

No comments: