0% found this document useful (0 votes)
42 views2 pages

Example Program 2 - Adding User Numbers Program: Code When Btnadd Is Clicked

This program allows a user to repeatedly enter numbers, adds each number to a running total, and prompts the user to enter more numbers or end input. It initializes a total variable to 0, then loops while the user enters "Y" - in each loop, it gets a number from the user via input box, adds that number to the total, and asks if the user wants to enter another number. After the loop ends, it displays the final total to the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Example Program 2 - Adding User Numbers Program: Code When Btnadd Is Clicked

This program allows a user to repeatedly enter numbers, adds each number to a running total, and prompts the user to enter more numbers or end input. It initializes a total variable to 0, then loops while the user enters "Y" - in each loop, it gets a number from the user via input box, adds that number to the total, and asks if the user wants to enter another number. After the loop ends, it displays the final total to the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Example Program 2 - Adding

User Numbers Program


This program asks the user to enter a number. It then asks them
whether they want to enter another. If they do it will ask them another
and add it to the previous number, it will keep doing this until they say
they do not want to enter any more numbers. Finally it will output the
total.
Code when btnAdd is clicked

Dim total As Integer = 0

Dim another As String = "Y"

'the loop will repeat while the user types Y when asked if they want to enter another
number

While another = "Y"

#asks the user to enter a number

Dim number As Integer = InputBox("Enter a number")

'adds the number entered to the total

total = total + number

'asks the user if they want to enter another number

another = InputBox("Do you want to enter another number? Y/N ")

End While

'after the loop ends it outputs the total

MessageBox.Show("The total of your numbers was " & total.ToString)

This is what happens when the button is clicked:

You might also like