Hi!! I am EXTREMELY knew to Visual Basic. (You will be able to tell shortly!) I needed a computer programming class for school and my advisors put me into a class that uses Visual Basic! Ive been struggling!! My latest assignment is........

-Write a program to request positive numbers one at a time from the user in an input dialog box. The user should be instructed to enter -1 after all the positive numbers have been supplied. At that time, the program should display the sum of the numbers.

Here is my code so far...

Public Class frmSF

    Private Sub btnSF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSF.Click
        Dim response As Integer
        response = CInt(InputBox("Enter a couple positive numbers than enter -1."))
        Do While (response > 0)
            response = CInt(InputBox("Enter a couple positive numbers than enter -1."))
        Loop
        lstBox.Items.Clear()
    End Sub
End Class

I am able to get input boxes, but I do not know how to get the sum of the numbers that I have already entered.. Can some one PLEASE help me!

Yes... the sum of the numbers entered into the input box should be printed out in a list box

Private Sub btnSF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSF.Click

Dim response As Integer
Dim sumVar as long

sumVar = 0

response = CInt(InputBox("Enter a couple positive numbers than enter -1."))
'Check if the response value is positive/not
if response > 0 then
    sumVar = sumVar + response
end if
Do While (response > 0)
    response = CInt(InputBox("Enter a couple positive numbers than enter -1."))
    if response > 0 then
         sumVar = sumvar + response
    end if
Loop

'Now sumVar holds the sum of all the integers. u can use it to display it anywhere

lstBox.Items.Clear()
End Sub
This article has been dead for over six months. Start a new discussion instead.