Programming : The Form

Synopsis: An example of the handshaking between the code and the design along with form properties.


The program used in this example has a multitude of errors. Can you find any? Some errors are listed at the bottom of the page.

One hand of the handshake is the Design Form. The design form is the operator user interface (OUI), the Human Machine Interface (HMI), the Operator Interface Terminal (OIT), or a host of other terms. Starting a program gives just an empty form in a default grayish background. The few updates already done are adding an icon and setting up the form to start in the center of the screen.

Code for the following display:

Public Class Form1

    '  Define global variables for use on this form only
    Dim x_Value As Double = 0.0
    Dim x_Raised As Double = 0.0
    Dim x_Powered As String = ""

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        '  In the Code view, x will receive a value either from the an the 
        '  running Form Or defined in the program.
        '  The x value is defined at runtime
        x_Value = 2.2
        x_Raised = 4.5
        '  Here, the values will be passed into a function also.
        '  x is passed into the function GetValueSquared and returned to the global varilable x_Squared
        x_Powered = GetValueRaised(x_Value, x_Raised)
        '  The returned value is sent to a textbox on the Design form
        TextBox1.Text = x_Powered
    End Sub

    '  The function receives the value from the calling code and the expected return variable will be an integer
    Private Function GetValueRaised(ByVal myX As Double, ByVal myExponent As Double) As Double
        '  Set the function value to 1
        GetValueRaised = 1
        '  Within the function, the value is rasied to the passed in exponent value.
        '  The loop count is determined by the exponent passed in.
        For i As Integer = 1 To myExponent
            '  The value is multiplied to itself myExponent times
            GetValueRaised *= myX
        Next
        '  The function title does not need to be directly assigned to the return result.
        '  Return is commonly used .
        Return GetValueRaised
    End Function
End Class
Starting a Form
Running The Form With a Textbox – This is the same program where Functions are Reviewed.

The following example will show property changes on the form and the text box. These changes can also be accomplished programmatically.

  • Form
    • Add an Icon – Icon discussion is towards the end of this blog.
    • Background Color
    • Title – I usually change the form description in the Solution Explorer to maintain the Form sequence and its description.
Modifications on the Form’s Back Color and Title
  • Textbox
    • Back Color
    • Font Size, which also changes the textbox height.
    • Width
    • Tabstop set to false so the cursor would not automatically select the textbox contents.
    • Text Align Center – Not shown as the property scrolled below the screen.
Text Box Properties Changes (*)

Running the program gave this result.

Runing the Form After Property Changes

Practicing with properties assists the programmer with creating an astatically pleasing program.

Project Properties

after right-clicking on the project title in the Solution Explorer, click on the Properties option in the Pop-up Menu.

Adding an Icon to the Program

Under this selection, an Icon can be added to the project.

VS is able to create icons. I found the icon creation process easier with a Sib Icon Studio.

Sib Icon Studio

If the above code was to be evaluated closely, a few faults would be found. The program is simplistic. The return from the function is an error. The passed in exponent is a double used in a loop expecting an integer. The programmer should always test program results before releasing programs to users.

Leave a Comment

Your email address will not be published. Required fields are marked *