How to get started with a new project
with validation.

Additions to previous version appear in pink.

It is not uncommon to be lost when you first start a new project. The following is a suggested plan to follow AFTER the interface has been drawn.

First

Determine which controls (probably textboxes) the user will use to enter input values.

Determine which control the main coding will be "behind". By "behind" I mean which control (probably a button)  you will click after entering input.

Double-click on this control. An event handler shell will be created. Much of the code you add will be added between the Private Sub... line and the End Sub  line.

Second

Declare variables variables for each numeric input value

To determine the appropriate data type think about the kind of number it will be. Will it always be a whole number? If so an Integer data type is probably appropriate. Does the value represent a dollar amount? If so Decimal would be an appropriate choice.

Declare variables to store the result of arithmetic expressions. (These are often output values)

To determine the data type remember that the data type of the result of an expression is often determined by the operands in the expression.

An Integer added, multiplied or subtracted from another Integer will produce an Integer.

Regular division (/) always results in a number with decimal positions.

Integer division (\) and modulus division (Mod) result in Integers.

Don't worry about declaring ALL the variables you will need. You can always declare more as you find the need for them.

Third

Clear out all output labels. We want to clear the labels so that output that has been displayed as a result of previous input values is not left. (kind of like erasing the black/white board at the beginning of a class)

Fourth

Validate the contents of the input control (usually a TextBox) to determine if the input value can be used.

If the input value needs to be numeric  use the IsNumeric function (Note: an empty Text value will not pass the numeric test)

If IsNumeric(txtInput.Text) = False Then

and display an appropriate message in a message box

MsgBox("Input value must be numeric")

Fifth

If the input passed the validation logic store all numeric input values (usually from the Text property of a TextBox) in the appropriate variables.  Use Convert.ToXXXX to convert the input value to the appropriate numeric data type.    

Else

intNumChildren = Covert.ToInt32(txtNumChildren.Text)

Sixth

Do necessary processing / calculations. (Note: This code will be in the path of the selection structure followed when input values are valid)

Seventh

Report output in output labels. Formatting as necessary. Note: This code will be in the path of the selection structure followed when input values are valid)

Example:  lblTotalCost.Text = decTotalCost.ToString("c")

Finally

Set focus back to an appropriate TextBox.

In addition:

Add code in GotFocus or Enter event handlers to select the contents of the TextBoxes when the TextBox receives Focus. Every TextBox needs such a procedure. Note: It would be a good idea to do this first so that you can reap the benefit of it while testing your program.