• Log in or sign up for an account here: https://www.sythe.org/login

Help!

  • Thread starter Thread starter VBTR
  • Start date Start date
V

VBTR

Guest
Hello , im a student that is taking a pretty basic intro to VB 2005 class and we've now just got into loops. But for the life of me I cannot figure out how one of these problems works.. it says
"Create an application that when you press a button "Enter Numbers" a input box is shown. (Ive got that far). The input box should asks the user to enter a positive integer value. When the OK button is clicked , the application should display a message box with the sum of all the integers from 1 through the value entered by the user..so far example if the number 10 is entered it should display a message box saying " The sum of the numbers 1 through 10 is 55". Im having trouble with what loop to use and what to do. If anyone could help that would be great , Thanks
 
Well, I'm no genius, but in SCAR you can do stuff like:

Code:
x := UserChosenX;
for z := x downto 0 do
i := x + z;

But, idk if that would work in VB...
 
Apart from being in VB.net (WRONG FORUM)
What you're looking for is a for loop, as elkins has said.


VB6 code is;
Code:
Private Sub Command1_Click()
    Dim iNumbers As Integer
    Dim iSum As Integer
    Dim i As Integer
    
    Do
        iNumbers = InputBox("Enter Number of times", App.Title, 5)
    Loop Until iNumbers > 0
    
    For i = 1 To iNumbers
        iSum = iSum + i
    Next i
    
    MsgBox "The sum of the numbers 1 through to " & iNumbers & " is " & iSum

End Sub


This will NOT work with .NET code, so you will either have to convert it, or get someone else to convert it for you.
 
Why dont you take this to the VB 2005 Section >.> dont people read :o
 
Jazz why exactly would that not work in VB.Net, as far as I can tell it would work fine, except perhaps the format of the inputbox (not sure don't have .net on this comp)
 
Jazz's code in .net:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim iNumbers As Integer
        Dim iSum As Integer
        Dim i As Integer

        Do
            iNumbers = InputBox("Enter Number of times", Application.ProductName, 5)
        Loop Until iNumbers > 0

        For i = 1 To iNumbers
            iSum = iSum + i
        Next i

        MsgBox("The sum of the numbers 1 through to " & iNumbers & " is " & iSum)
    End Sub
 
Runescape Gamblingrunescape gambling
Back
Top