Help!

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

Help!
  1. Unread #1 - Mar 11, 2008 at 12:23 PM
  2. VBTR
    Referrals:
    0

    VBTR Guest

    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
     
  3. Unread #2 - Mar 11, 2008 at 4:51 PM
  4. Elkins121
    Joined:
    Sep 18, 2007
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    Elkins121 Member

    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...
     
  5. Unread #3 - Mar 11, 2008 at 5:36 PM
  6. Jazz00006
    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0

    Jazz00006 Apprentice
    Visual Basic Programmers

    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.
     
  7. Unread #4 - Mar 11, 2008 at 6:29 PM
  8. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    Help!

    Why dont you take this to the VB 2005 Section >.> dont people read :eek:
     
  9. Unread #5 - Mar 11, 2008 at 10:50 PM
  10. jdsfighter
    Joined:
    Jan 21, 2007
    Posts:
    603
    Referrals:
    0
    Sythe Gold:
    0

    jdsfighter Forum Addict
    Visual Basic Programmers

    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)
     
  11. Unread #6 - Mar 12, 2008 at 1:43 AM
  12. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    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 >

Users viewing this thread
1 guest


 
 
Adblock breaks this site