Presentation is loading. Please wait.

Presentation is loading. Please wait.

Department Array in Visual Basic

Similar presentations


Presentation on theme: "Department Array in Visual Basic"— Presentation transcript:

1 Department Array in Visual Basic
Please use speaker notes for additional information! This shows the department array implemented in Visual Basic.

2 This shows the output when the user entered a dept code
This shows the output when the user entered a dept code. When the user entered 2, WOMENS was retrieved from the array. When the user entered 3, GIRLS was retrieved. Entering 4 got BOYS and entering 1 got MENS.

3 This shows the form that is used in this program
This shows the form that is used in this program. Note that it also shows the properties for the form.

4 This shows the form and properties for the Dept Code label.

5 This shows the textbox for the department code
This shows the textbox for the department code. It is called txtDeptCode. It also shows the properties associated with this textbox field.

6 This is the Command Button that will retrieve the name from the array based on the code the user enters. Again, I am showing the properties associated with the Command Button.

7 This shows the code in the program
This shows the code in the program. Note that the code is grouped into Procedures. Some of the procedures are called by Clicking a Button on the form. The procedure Form_Load() is executed when the form is loaded. This procedure fills the array with the department names. These names can then be extracted from the array using the department number that the user inputs.

8 This defined the DeptName array as containing string data.
Dim DeptName(4) As String Option Explicit Private Sub cmdClear_Click() txtDeptCode.Text = "" txtDeptName.Text = "" txtDeptCode.SetFocus End Sub Private Sub cmdExit_Click() End Private Sub cmdGetName_Click() Dim Indx As Integer If Val(txtDeptCode.Text) > 0 And Val(txtDeptCode.Text) < 5 Then Indx = Val(txtDeptCode.Text) txtDeptName.Text = DeptName(Indx) Else txtDeptName.Text = "Invalid Department Code" End If Private Sub Form_Load() DeptName(1) = "MENS" DeptName(2) = "WOMENS" DeptName(3) = "GIRLS" DeptName(4) = "BOYS" This defined the DeptName array as containing string data. The Dim statement defined the index that will hold the txtDeptCode that the user entered. When the txtDeptCode is valid it is put into Index and Index is used to go to the array and take the DeptName and move it to the text box for the name. In this example, the code that is entered is moved to text if it is in the valid range of 1 to 4. Then it is used to index the array name, DeptName to get the correct department from the array. Note that if the code is not valid, an error message is moved to the text box. This shows the data in the array.


Download ppt "Department Array in Visual Basic"

Similar presentations


Ads by Google