Adblock breaks this site

Help!

Discussion in 'Programming General' started by VBTR, Mar 11, 2008.

  1. VBTR

    VBTR Guest

    Referrals:
    0
    Help!

    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
     
  2. Elkins121

    Elkins121 Member

    Joined:
    Sep 18, 2007
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0
    Help!

    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...
     
  3. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    Help!

    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.
     
  4. demonavenger

    demonavenger Forum Addict
    $5 USD Donor

    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0
    Help!

    Why dont you take this to the VB 2005 Section >.> dont people read :eek:
     
  5. jdsfighter

    jdsfighter Forum Addict
    Visual Basic Programmers

    Joined:
    Jan 21, 2007
    Posts:
    603
    Referrals:
    0
    Sythe Gold:
    0
    Help!

    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)
     
  6. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Help!

    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
     
< Status code/ Old Version | A noob needs help in world swithcher >


 
 
Adblock breaks this site