1) Clearly define what the application is to do.
This can be accomplished by filling out this simple formula:
-Purpose:
-Input:
-Process:
-Output:
2) Visualize the application running on the computer and design its user interface.
Before the coding process starts, draw a few sketches of what you visualize the GUI will look like and how the user will interact with the program.
3) Determine the controls needed.
Make a list of all the controls, such as forms, labels, picture boxes, buttons, etc.
4) Define the values of each control's relevant properties.
For each control, write out the properties associated with the its function.
Ex. Form
Name: Form1
Text: "Directions"
5) Start Visual Basic and create the forms and other controls.
This is where you start creating your program in Visual Basic. Remember to follow the instructions from Chapter 1 on the rules for naming different controls (i.e.if you're calling up the control in your code, make sure to change the name to describe it's function. It'll be easier to understand your code later).
Design Mode: This is the mode where you create an application. Also known as "design time".
Run Mode: This lets you execute the program in Visual Basic. You can either click the F5 key, click "Debug", or press the play button (Start debugging).
Break Mode: This allows you to suspend a running application for test/debug purposes.
Closing a project: To close your current project, click file on the menu bar and then "close project".
Solutions/Projects: A solution is a container that holds Visual Basic projects. Every Visual Basic project you create has its own solution.
Save Project: When you save your project, a folder you title will be created where the solution is stored.
Contents of Solution Folders: The solution file itself is saved as a ".sln" file. Other various file-types, such as ".vbproj" are saved here. We don't need to interact with these files, but Visual Basic must have these to read/access a project.
Open project: Click file, then open project.
Properties window: The box that appears at the top of the Properties window shows the name of the selected control. Known as the "object box".
Alphabetical Button: Click this and all controls are displayed in alphabetical order.
Categorized button: Click this and all controls are displayed according to category.
2.2 Focus on Problem Solving: Responding to Events
In the book, we added an event handler to display directions when the "Display Directions" button is clicked. The label (where the text is written) is always present on the program, but is invisible when the button hasn't been clicked. This is because the Visible property has been set to "false" (it's a Boolean property, meaning it can only be "true" or "false"). You can change the visible property by finding it in the properties window. After changing the names of both the button and the label, double-click the button to get to the code. In the space, type "lbldirections.Visible=True". This will tell the program to set the visible property of the "lbldirections" to true once the button is clicked. This works because this is known as an assignment statement. The equal sign is the assignment operator. What this does is it assigns the value that appears on the right side of the equal sign (true) to the item that appears on the left side (lbldirections). It must be in that formula, or the assignment operator will not work.
To close the application by the click of a button (and not the Windows "X" button), double-click the button to again access the code. Type in "Me.Close( )". This is known as a method call. Me is a keyword that refers to the current form. On the right side of the period, the keyword Close is the name of the method that you are calling. The set of parentheses always appear after the name of the method in a method call.
Comments: Comments are important when writing code as they'll help you understand what each line of code is doing. To write comments without breaking code, put an apostrophe (') at the start of a line of code. This tells the compiler to ignore everything after the apostrophe.
Changing Text Colors: Font style/size can be changed through the properties window, but to change the text background and foreground color, use the BackColor and ForeColor properties.
FormBorderStyle Property: This property lets you customize how the user interacts with the program. You can prevent the user from resizing, minimizing, maximizing, or even closing a form with the Close (X) button.
Locking Controls: Right click over an empty spot on the form and right-click. Click "Lock Controls" to lock their place to the form.
Intellisense: Much like Google trying to guess what you're typing and giving suggestions, Visual Basic will give you a drop down list with potential code that you're writing.
2.3 Modifying a Control's Text Property with Code
To change text while a program is running, call up the control in code and use an assignment statement. Example: lblMessage.Text="Programming is fun!". This will change the control "lblmessage" text property to the new text when it is executed. The quotation marks are known as a string literal.
2.4 AutoSize, BorderStyle, and TextAlign
AutoSize Property: It's a Boolean property that is set to true by default. This will auto resize a label's bounding box to accommodate the text. If set to false, you can manually change the bounding box.
BorderStyle Property: Has three settings 1) None (no border) 2) FixedSingle (single-pixel-wide border) and 3) Fixed3D (recessed 3D appearance).
Text Alignment: Change the TextAlign property to change the alignment in a control. You can do this with the Properties Window, or with code by using an assignment statement such as "lblReportTitle.TextAlign=ContentAlignment.TopLeft".
2.5 Displaying Message Boxes
Message Box: A small window, referred to as a Dialog Box, that displays a message. "MessageBox.Show("Hello World!")" is a method call to bring up a message box.
2.6 Clickable Images
Just as buttons can have click-event handlers, other controls such as PictureBoxes and labels can also have click-event handlers.
In the book, the example was clicking on a picture of the USA flag to display the text "United States of America". To do this, click the image to access the code page. Then write "lblMessage.Text="United States of America".
2.7 Using Visual Studio Help
The MSDN Library contains a ton of information about Visual Studio and Visual Basic. Context-sensitive help aids in finding information about what you are currently working on. Pressing F1 while selecting an item will bring up a browser, displaying help on the selected item.
2.8 Debugging Your Application
Compile Errors: These are syntax errors (i.e. there is some error in your written code). Each programming language has its own syntax as you recall from Chapter 1. Each compile error is underlined with a jagged blue line. Review your code and make corrections.
Runtime Errors: Errors found while the application is running. These are not syntax errors, but results from attempting to execute an operation that Visual Basic can't execute.
No comments:
Post a Comment