3.1
Gathering Text Input
Text box-rectangular area on a form that accepts keyboard input.
You can access the Text property of a TextBox control just like you would access any other properties.
(ex. txtInput.text)
To clear a text box, we use the formula of "Object.Method", object being the name of the object and method being the name of the method being called. In this case, it would be TextBoxName.Clear( ). This clears any input in that specific textbox.
Another way of clearing a text box is using "String.Empty" to clear the contents. In this case, we'd use an operator in the code. TxtBoxName.Text=String.Empty
String Concatenation
String concatenation is a way of combining different elements of input by using an operator. The ampersand (&) operator is used to combine two different inputs.
Example: lblMessage.Text = Good Morning " & "Charlie". This would assign "Good Morning Charlie" to the text property of the lblMessage control. Make sure to include the proper spaces in the code, or else the text may end up reading "GoodMorning Charlie" or "GoodMorningCharlie".
Aligning Controls in Design Mode
This section talks about the various methods and tools used to properly align controls on a form. Whenever a control is aligned with another control, certain color guide lines appear.
Blue guide line: Controls are aligned vertically.
Lavender guide line: Controls are aligned horizontally.
Both lines can appear at the same time too. This takes a lot of the guesswork out of making sure everything is properly aligned in a visually appealing manner.
The Focus Method
Focuse: The control that is receiving user input. One control at any time always has the focus when a program is running.
To tell what control has the focus in realtime, look for several different signs. If a text-box has a blinking cursor, it has the focus. If a button has the focus, it'll have a thin dotted line around it.
To actively assign a control the focus (in the book tutorial, it showed how to make a text-box cursor flash again after all text-boxes had been cleared), we can call the focus method. To do this, we use "ControlName.Focus( )".
TabIndex
Just like on a webpage, pressing the tab button shifts the focus around to different controls. The order this goes in is known as the tab order. By default, the tab order is assigned in the order in which you created the controls. However, this might not always be the exact order you'd like (due to rearragning, deleting, adding new controls, etc). You can modify the tab order by using the TabIndex Property. Each control is assigned a number which indicates its order. By changing this, you can change the tab order. An easier way of changing each TabIndex Property (instead of individually changing all) can be found by clicking "View" on the menu bar, and then "Tab Order". This displays the form in tab order selection mode, where you can click on the specific order you'd prefer.
If you don't want a control to get the focus when cycling through the tab order, assign it's TabStop property to "false".
Assigning Keyboard Access Keys to Buttons
Access Key: Also known as "mnemonic", is a key pressed in combination with the alt key. You can assign an access key to a button through its Text property. Book Example: A text property is set to "exit" for a button. To assign the access key "Alt+X" to close the application, change "Exit" in the text property to "E&xit".
Accept Button: is a button that is automatically clicked when "Enter" is pressed.
Cancel Button: is a button that is automatically clicked when "Esc" is pressed.
3.2
Variables/Data Types
Variable: a storage location in computer memory that holds data while a program is running. It's basically name which you assign that represents a location in the computer's RAM. Example: "intLength=112" stores the value 112 in that variable.
Variable Declaration: is a statement that creates a variable in memory when a program executes.
The general form for this is "Dim VariableName As DataType" Book Example: Dim intLength As Integer.
-Dim tells VB that a variable is being declared.
-intLength is variable name.
-Integer indicates the data type. Integer is used to hold numbers. To declare multiple variables, use commas in-between each VariableName.
Variable Names: Rules: 1) First character must be letter or an underscore. 2) May use letters, numberic digits, and underscores after first character (no spaces,periods, or other punctuations). 3) Names cannot exceed 1023 character. 4) Names cannot be already established VB Keywords.
Type Prefix: Generally a good idea for future reference to start with a type prefix. We already do this when naming controls, i.e. a text-box we use "txt" before the name. See table 3-1 on page 124 for more details.
Assigning Values to Variables: Use the = operator to assign variable names to values. Example: inUnitsSold = 20.
Integer Data Types: Integers are whole numbers.
-Byte: holds a vaue ranging from 0-255
-Short: Value range of -32,768-+32,767
-Integer: Value range of -2,147,483,648-+2,147,483,647
-Long: Ridiculous value range.
More in-depth breakdown, see pages 126-131.
Default Values/Initialization
When a variable is assigned, it's given a default value. An integer variable is automatically assigned "0". To initalize it, you can specify a starting value using the dim statement, ex: Dim intUnitsSold As Integer = 12.
Local Variable: When a variable is declared inside of a procedure (such as an event handler) it is referred to as a local varaible. An error will occur if one procedure attempts to access a local variable of another procedure.
Scope: refers to the part of a program in which a variable may be accessed. Restates the local variable bundaries. Different scopes allow for variables to have the same names.
3.3
Performing Calculations
Binary Operator: works with two operands. Example: 5 + 10 adds the values of two numbers.
Different operating signs include subtraction (-), multiplication (*), floating-point division (/) integer division (\), and exponentiation (^).
Date/Time
To get the date/time of the computer, you can use the dim statement to bring up either date, time, or both.
"Dim dtmSystemDate=Now" brings up the current date and time of the system.
All of the other calculations would be tedious to write down, so read this section!
This is getting too long, so I'll just pick key topics from the other sections
Type Conversion: This occurs when assigning various things to variables. When a variable is assigned, VB tries to convert it to another data type. For example, assigning a real number (12.5) to "intCount", VB will convert it to an integer variable, rounding up to 13.
Option Strict: Only widening conversions are allowed, where no data is lost.
Function: special type of procedure where data is sent to the function as input. The function performs an operation on the data, then sends it back as output.
Exceptions: These are ways to recover from errors beyond a programmer's control (i.e. the user inputs wrong data). To "gracefully" recover from these, exception handlers are used.
A try-catch statement is the format used for exceptions. These are formatted as
Try
Statement
Statement
Catch
Statement
Statement
End Try
These execute in the order that they appear in. If a statement in the try block causes an exception, it'll jump to the catch clause and execute a statement from there.
In the book example, the user entered "four thousand" instead of a numerical value. This threw an exception for the try clause, and jumped to the catch clause, which saved the error.
I started writing this blog as I was reading through the chapter. I had no idea how long this chapter was, so about half-way through I realized it'd be pointless to cover every single thing. I'll make sure to just cover the major points in Chapter 4.
No comments:
Post a Comment