Monday, August 9, 2010

Monday, August 9 2010

Still working on the Toolbar tutorial written by Michael Halvorson


label1.Text = TimeString


and


label1.Text = DateString


I left the name of the label as the default label1 since that is how it is written in the tutorial. Both of these are what I think of as "onClick" events since that is how they are defined in html / CSS which is what I am most familiar with. With VB, they are called click event procedure I believe (?) For both of these click events the label1.text's Text property is changed to whatever the Time and Date are converted to strings.

There are a number of System Clock Properties and Functions which are important and useful to know. Particularly intriguing is the Now property which returns "an encoded value representing the current date and time." This property is used when making arguments for other system clock functions - comparing now to some other time, making if/then statements, etc.

As well as having a MenuStrip control VB has a ToolStrip control which is just what you would think it would be - it adds a tool bar to your program that the user can use.

Jumping ahead, I took a looking at the tutorial dealing with statements. The tutorial Mr. Halvorson has written.

The tutorial emphasizes that a variable holds its value or scope only within the event procedure being used, for instance:


Dim LastName As String

LastName = "Jensen"
Label1.text = LastName

LastName = "Zimbardo"
Label1.text = LastName


Label1.text = LastName shows us one of the most important uses for a variable - transferring data to a property.

It's worth noting that you can declare two or more variables in one line as long as they are the same type, for instance


Dim FirstName, LastName as String


InputBox is a function. A function usually uses an argument, and can even have more than one argument separated by commas. For instance:


MsgBox(First Name, Last Name)


I wrote my own variation of the tutorial as


Dim PromptFirstName, PromptLastName, FirstName, LastName As String
PromptFirstName = "Please enter your first name."
PromptLastName = "Please enter your last name."

FirstName = InputBox(PromptFirstName)
LastName = InputBox(PromptLastName)
MsgBox(FirstName & " " & LastName, , "Input Results")


I then rewrote this variation as a nifty little username generator


Dim PromptFirstName, PromptLastName, FirstName, LastName, UserName As String
Dim UserNameNumber As Integer
PromptFirstName = "Please enter your first name."
PromptLastName = "Please enter your last name."

UserNameNumber = Int(Rnd() * 100) Note:This doesn't actually generate a random number, like I was hoping, it just generates .7055 each time!

FirstName = InputBox(PromptFirstName)
LastName = InputBox(PromptLastName)

UserName = FirstName & LastName & UserNameNumber
MsgBox("Your user name is, " & "" & UserName, , "Input Results")


If you wanted to generate a random number 1-9, you could write


Dim MyValue As Integer
MyValue = CInt(Int((9 * Rnd()) + 1))
Why would you use CInt instead of Int?


I'm not going to worry too much about random number generation at the moment.



Const Pi As Double = 3.14159265


or



Public Const Pi As Double = 3.14159265

No comments: