Building the project in VB6
We will now build Visual Basic 6 code for a simple calculator program. The program has a form that loads when the application starts. The form contains a loop that prompts the user to input two numbers and an operator and then operates on the two numbers. The loop prompts the user until they enter X
to quit. Finally, the program displays the result of the operation in a message box. For example, if the user tries to divide by zero, a message box says, "Cannot divide by zero!"
. The program uses the Cint
function to convert the inputted numbers into integers and handles errors using message boxes:
Private Sub Form_Load() Dim n1, n2, res, operator, sentinel As String sentinel = False Do n1 = InputBox("Enter the first number or X to quit:") If n1 = "X" Then sentinel = True ...