



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Severance
Windows Naming Conventions - we will only partially use!
All components associated with procedures have descriptive names with Windows© standard prefixes. The prefix is in lowercase and the first character of the descriptive name is capitalized. Multiply worded descriptive names have each word capitalized with no spaces between each word. Command buttons and other action components are given verb names. Text boxes and other data sources are given noun names. Forms should always be given meaningful names and captions. For example,
cmdName lstOutputData txtFrequency
Mathematical operations should not be performed by component properties. Only variables will be used to perform mathematical operations.
Variables that are identifiable from mathematical formulas should be given meaningful mathematical names. Generally the variable should be upper case, except for subscripts, which should be lower case. For example, the formulaic variable should be Xmin in Visual Basic.
Usually, Integer and Long variables should use the letters I, J, K L, M, N. The letters I, J, K are usually used for variable indices, while M, N are used for upper limits of subscripted variables. For example,
Dim I, J, K as Integer Dim M, N as Integer
For I = 0 to M For J = I to N Next J Next I
Single and double precision variables should be other letters. The letters U, V, W, X, Y, Z are usually Single or Double precision and are used for either temporal or spatial variable signals. Constants are usually denoted by A, B, C, D, E, F.
Certain variables will be universally reserved for special modeling purposes. For example,
T will stand for continuous time H will stand for a time increment K will stand for discrete time
Programming standards
Procedure headers and footers are not indented
Labels are generally to be avoided unless explicitly used in conjunction with state- machine programming. Exceptions, however, do exist, such as for error exception handling. In general labels are not indented.
The variant data type is never used.
Declarations for global variables are placed in the general module under the option explicit and defined as Public
Declarations for module or form variables are placed at the top with the option explicit of that form or module. These are defined as Private.
Declarations for local variables are defined at the top of that procedure. A line feed separates this declaration section from the executable section of the procedure.
Errors should be handled using message boxes and must describe the specific error so that the user can correct him or herself.
Structured Programming
In general, it is best to explicitly incorporate defaults in your program. These should be handled in the form load ( Form_Load ) procedure.
Text boxes are used for user inputs and Label boxes are used for outputs.
An initialize command button ( cmdInitialize_Click ) should be used to transfer input strings to variables using Csng, Cint, etc. commands to variables. Edits with respect to input data types and existence should be performed in this procedure.
A display subroutine ( Display ) or procedure ( cmdDisplay_Click ) should be used for all output, where variables are passed into the routine as parameters.
If files are to be loaded or closed, explicit open file or close file command buttons ( cmdOpenFile and cmdCloseFile ) should do this prior to or after processing. Within these procures, either the common dialog box (VB 6.0) or I/O-specific dialog boxes (VB.Net) should be used using prescribed “boilerplate” routines.
An execute command button ( cmdExecute ) should be used to do all computations and data processing. Since the input/output procedures are explicitly defined as above, the execute procedure should only refer to variables and not text or label boxes.
Note the following examples.
VB .Net Solution
Public Class Form Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Dim X1 As Single Dim X2 As Single Dim X3 As Single
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles MyBase.Load txtFirstNumber.Text = 52 txtSecondNumber.Text = 43 txtThirdNumber.Text = 80 End Sub
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles cmdExit.Click End End Sub
Private Sub cmdInitiate_Click(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles cmdInitiate.Click X1 = CSng(txtFirstNumber.Text) X2 = CSng(txtSecondNumber.Text) X3 = CSng(txtThirdNumber.Text) End Sub
Private Sub cmdExecute_Click(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles cmdExecute.Click Dim Xavg As Single
Xavg = (X1 + X2 + X3) / 3 Call Display(Xavg) End Sub
Public Sub Display(ByVal sngAnswer As Single) lblAverage.Text = CStr(sngAnswer) End Sub
End Class
Programming style
In general, the code should be user-proof. That is, there should never be a case where fatal errors occur... because of illegal operations, because of vacuous or illegal data types provided by users, because of appropriate order of execution on the part of users. In other words, it doesn’t take much to make your program work; success is in how your program fails! It should be designed to fail properly.
Imperative statements are single indents.
Loops processes are indented one level and nested accordingly.
e.g., For I = 1 to 5 For J = 1 to 4 Y = 2I + 3J Next J Next I
The conversion of data types will use the CSng , CInt , CStr and such functions.
The only conditional structures allowed are nested conditionals and imperatives.
Compound conditionals are to be avoided.
Conditionals use if/then/else and must be indented appropriately.
e.g., If X > 3 Then If X > 5 Then Y = 4 Else Y = 2 End if Else If X > 5 then Y = 5 Else Y = 6 End if End if
Conditional imperatives are acceptable only if nesting alternatives are vacuous
e.g., If X = 5 Then Y = 7