VB 6 – Choose() Function

Advertisements
Advertisements

The VB 6 Choose() function is another function that let you choose values based on an index. However, do not confuse it to be an array. The Choose () function is very useful in menu based program where you can display a menu and let user input there choice.

When the user makes a choice, the value corresponding to the choice is returned and stored in another variable. Let us see the syntax for Choose () function.

Dim Variable As String
Variable = Choose(indexNo, "Value1", "Value2", "Value")

The value in the above program could be numbers. We have chosen the string type to demonstrate the usage.

Example Program: Choose() Function

In this example, we will read an input number and based on the input, the program will find the name of the student and display it on the screen.

Private Sub Command1_Click()
Dim indexNo As Integer
Dim Student As String

indexNo = -1

indexNo = InputBox("Enter a Number between 1 - 5, Enter 0 to end")

If indexNo >= 1 Then

Student = Choose(indexNo, "Peter", "Ram", "Mary", "Abdul", "Lee")

End If

If indexNo = 0 Then

End

End If

MsgBox ("Student Name is" & " " & Student)

End Sub

User Input

Input - Choose() Function
Figure 1 – Input – Choose () Function

Output: Choose () Function

The output of the program is the name of the student whose index number matches in the Choose() function.

Advertisements
Output - Choose Function
Figure 2 – Output – Choose Function

Visual Basic 6 For Dummies 1st Edition

Create your own custom Visual Basic programs fast for Windows 95, Windows 98, and Windows NT!

If you want to develop business applications for Windows, then Microsoft’s Visual Basic 6 programming environment is for you. With its powerful and friendly object-oriented interface, Visual Basic 6 is the ideal tool for creating easy-to-use and attractive interfaces of your own. Whether you want to build original programs from the ground up or take advantage of existing wizards, Visual Basic 6 For Dummies will help you design and debug your work – and accomplish all your goals!

  • Covers using Visual Basic 6 with Windows 95, Windows 98, and Windows NT
  • Walks you through the ins and outs of object-oriented programming in Visual Basic and using the Visual Basic toolset
  • Shows you how to make use of menus and submenus, write subprograms that everyone can share, save and retrieve information in databases, integrate ActiveX controls into your applications, and build attractive user interfaces with buttons, boxes, and scroll bars

From the fundamentals of writing BASIC code to the thrill of distributing your very own custom applications, Visual Basic 6 For Dummies brings a fresh perspective to programming in Visual Basic 6 that everyone can understand.

Advertisements
Advertisements
Advertisements