HTML Tutorial General Help Visual Basic Splash Screen A splash screen is the startup screen to establish some basic information about the application such as Title, Author, Version number, etc. It can be added to the application just like any other form. See Instructions and more information here: How to Specify a Splash Screen for an Application. You change the information contained on the Splash Screen in the Assembly Information Window(see Specify Assembly Information). About Box The About Box is special type of form which is displayed on command to provide additional information about an application. This is equivalent to the About Box found in most commercial applications. You add it just like you would add any other form, by going to Project / Add Windows Form and looking for the About Box template. You change the information contained on the AboutBox in the Assembly Information Window (see Specify Assembly Information). Application Information This relates to the information displayed in the Splash Screen and the AboutBox. Unlike other forms, you can not update the properties on these forms and have your settings show up when you run the application. You need to change these settings in the Assembly information Window (see Specify Assembly Information). Debugging Visual Studio provides a number of very useful tools to help debug your applications. Three Key ones are: Break Points, Stepping through the application, and the various Debug Windows (particularly the Watch Windows). Breakpoints allow you to stop the execution of the code, and then determine the value of your variables, and then step through the code to see how it operates. You can hover over a variable in break mode to determine its value, but a more efficient way is to use one of the Debug windows (go to Debug / Windows). The Locals and Autos, allow you to see different sets of variables which change as you move through the code. Watch Windows allow you to specify which variables you want to monitor. (see Use Debugger Variable Windows). Object/Variable Prefixes It is a best practice to add specific prefixes to your objects and variables. Form Properties/Behaviour All visual information on forms and the objects contained on them are controlled by their properties. You can Display the property window by going to View / Properties Window. Pin the window to keep it open. All objects have a Name property, which must be unique. Consistently using objects prefixes will make coding easier. The only exception to this is for Labels which are not used programmatically (i.e., their properties such as Text are not changed in the code). Any text that is displayed is set in the object's Text Property. Some object has a smart button that appears on the top right of the object when it is selected. This provides access to comment properties. Specific properties that are important for the form are:
  • Name - you ALWAYS should use a frm prefix. Hint - Either Name the form properly when creating it, or Rename it in the Solution Explorer. This will propagate the name to the properties window.
  • Accept && Cancel Buttons - Specifies what happens when the user hits Enter and Esc keys (the corresponding Buttons must be defined on form).
  • StartPosition - Location on screen that the application starts up (I prefer Center Screen)
  • BackColor - background color
  • Text - Displayed at the top of the form
  • When setting the Text property, you can incorporate Hotkeys by inserting an ampersand (&&) prior to the desired Hotkey letter. Unfortunately, the underscore on this hotkey does not show up until the user hits the Alt key. Coding Standards Coding standards are important to make it easier to maintain the code, and provide for code reuse. Studies show 80% of the effort used to support program code is done to maintain it, so it is important to do everything we can to make that easy. Key elements are Commenting Comments are needed to describe what the code is doing - EVEN FOR CODE THAT LOOKS OBVIOUS, such as a Sub called btnExit_Click, that only has the code Me.close. Stick in a comment that says "This closes the application". Here are some basic guidelines on commenting: Variables When writing a program, you have the objects on the form, which typically holds user input. This might be the users Name, Salary, Weight, Age, Number of Children, Married, and Hire date. If you are going to process this information and do something useful, a programmer will normally need to bring this information into the Program and assign the information to variables that they define. So the user name may go from the txtName.text in the textbox to a string variable defined as strName. You need to define the variables appropriately. Salary, Weight, Age, Number of Children are all typically numbers. But which of these could possible have decimal values? That would be Salary, Weight, and Age (although you might want to force age to be a whole number). These would need to be declared with a data type that supports decimal values. Number of children will never have a decimal value, so it should be declared as an Integer. Hire Date should be declared as a date variable to allow date functions to be used. Married would likely be a Boolean, but you may need to make it a String if you want to allow "I Don't Know" as a valid answer. Data Types All programming languages offer a broad selection of variable types. In most cases you can just use two numeric types Normally a program will use a mix of these data types. Data Structures Variables can be single variables or grouped together in an array. Here is some information about Arrays. Structures Structures are a way to build a custom data type. You define the structure to have whatever name fields you want, with whatever datatypes you want. Then you can define a variable or an array based on that structure. Say you have

    Structure MyStudent
    dim strName as string
    dim dblSalary as double
    dim intNumberOfKids as integer
    dim datHireDate as date
    dim boolMarried as boolean
    end Structure

    dim Students(100) as MyStudent
    You can reference the fifth student's salary as Students(4).dblSalary

    Name Spaces To simplify the working environment, Visual Studio limits which commands are available when you create an application. You can expand that namespace and add it extra functionality. You do this by Importing a namespace at the very top of the application. Here are three common name spaces you often have to add. String Formatting When you want to output a number of date, you often want to format the number. The first step is always to convert the number to a string, and then you format the string. You can convert a number to a string in two ways: either cstr() or .tostring. It is nearly always better to use the .tostring approach, because it supports number formatting see Standard Numeric Format String and Standard Date Format Strings. For more complicated formatting, use the String.Format command . String Concatenation Concatenation is the technical term for combining two strings. The concatenation operator is an ampersand (&). So strFullName = strFirstName & " " & strLastName, where the extra " " adds a space between the two names. WARNING, most of the time a plus sign will work, but it can provide odd results, so it is best practices to always use an ampersand to concatenate. Case Insensitive When comparing two test strings, it is normally important to make the comparison case insensitive (i.e., "Yes" = "yes" = "YES"). You do this by adding either .toUpper or .toLower to both strings (.toUpper forces to upper case, .tolower forces to lower case). This is particularly important when dealing with User input or reading from a file. Complex Comparisons Sometimes the triggers for an IF statement may depend on multiple factors. In this case you need to either nest the IF statements, or use an AND or OR. You could also use Nested IF Statements. And Don't forget the Else statement. It can be quite useful. Some examples here: If...Then...Else Statement