Lecture 9 Additional Topics in VB.NET 1 Timer Control • Invisible during runtime • Triggers an event after a specified period of time • The Interval property specifies the time period – measured in milliseconds • To begin timing, set the Enabled property to True • To stop timing, set the Enabled property to False • The event triggered each time is called Tick event 2 Timer Control (cont.) • Interval property • Between 0 and 65,535 milliseconds • 1,000 milliseconds = 1 second • Enabled property • False (default) ==> Do not run Tick event • True ==> Run Tick event at designated interval • Tick event • Runs each time the Timer's designated interval elapses, if Enabled = True 3 DateTimePicker & Calendar Controls • DateTimePicker • Takes less screen space • Displays only day and date unless user drops down the calendar • MonthCalendar • Displays calendar • Provide the ability to display calendars on your form 4 Calendar Controls (cont.) DateTimePicker MonthCalendar 5 Getting Input from an Input Dialog Box stringVar = InputBox(prompt, title) fileName = InputBox("Enter the name " _ & "of the file containing the " & _ "information.", "Name of File") 6 Using a Message Dialog Box for Output • Displays a message in a dialog box, waits for the user to click a button MsgBox(prompt) MsgBox("Nice try, but no cigar") 7 Some Built-In Functions Function Example Input Output Int Int(2.6) is 2 number number Chr Chr(65) is “A” number string Asc Asc(“Apple”) is 65 string number Math.Round Math.Round(2.7) is 3 number number Math.Sqrt Math.Sqrt(9) is 3 Number number 8 Built-in Functions (2) • Functions return a value IsNumeric(9) ' Returns True IsNumeric(459.95) ' Returns True IsNumeric(“45 help”) ' Returns False 9 Input Validation • Code If structure to determine if value falls within a range of acceptable values • Refer to lab 6 – Calculate Grade • Use single If for each value, Else for message to user, and execute Focus Method to reset focus to text box 10 Input Validation (2) • Check to see if valid values were entered by user in TextBox and use Message Box to notify user if invalid • IsNumeric function checks for numeric values • If IsNumeric(txtQuantity.Text) Then ... • Check for required data or not blank • If txtName.Text <> "" Then ... 11 Variables • Declaration: Dim speed As Double Variable name Data type • Assignment: speed = 50 12 Initial Value of a Integer • An integer is a whole number • Declaring an integer variable: Dim varName As Integer (Numeric variables are automatically initialized to 0) • To specify a nonzero initial value Dim varName As Double = 50 13 Initial Value of a String • By default the initial value is Nothing • Strings can be given a different initial value as follows: Dim today As String = "Monday" 14 Incrementing • To add 1 to the numeric variable var var = var + 1 • Or as a shortcut var +=1 15 Multiple Declarations Dim a As Integer Dim b As Integer Alternative method: Multiple-declaration Dim a, b As Integer 16 Remark Statement • Also known as Comment, used for documentation • Non-executable • Automatically colored Green in Editor • Begins with an apostrophe ( ' ) • On a separate line from executable code • At the right end of a line of executable code ' Display the Hello World message 17 Assignment Statement • Assigns a value to a property or variable • Operates from right to left • Enclose text strings in quotation marks (" ") lblMessage.Text=" Hello World " 18