Share this Page URL

Chapter 5. Using Visual Basic to Automat... > Using Control Structures - Pg. 160

Using Visual Basic to Automate Your Database Public Sub SelectCase(intSales As Integer) Dim strSalesStatus As String Dim strStatusMessage As String strStatusMessage = "You've sold $" & " " & intSales & " " & "worth of products." Select Case intSales Case Is < 1000 strSalesStatus = strStatusMessage & " Keeping going" Case Is < 2000 strSalesStatus = strStatusMessage & " You're doing ok." Case Is < 3000 strSalesStatus = strStatusMessage & " Pretty good." Case Is < 4000 strSalesStatus = strStatusMessage & " Well done!" Case Is < 5000 strSalesStatus = strStatusMessage & " Almost there." Case Else strSalesStatus = strStatusMessage & " Take a vacation." End Select MsgBox strSalesStatus End Sub 160 Notice the statement int Sales as Integer, enclosed in parentheses in the declaration of Select- Case. This procedure requires an integer as an argument when you run it. If you are going to test SelectCase in the Immediate window, enter something like SelectCase (1500). The Call Statement If you need to execute a procedure from another procedure, you can use the Call statement. You don't need to include the keyword Call --you can just use the procedure's name--but including Call makes your code more understandable. Here's a simple procedure that uses the Call statement