attn: VB programmers

Discussion in 'OT Technology' started by poopies4u, May 8, 2003.

  1. poopies4u

    poopies4u Active Member

    Joined:
    Nov 26, 2001
    Messages:
    49,122
    Likes Received:
    3
    Location:
    Baltimore, MD
    can you help me debug this bastard
    Code:
    Option Explicit
    
    Private Sub cmdCalc_Click()
        Dim intX As Integer, intNumber As Integer
        Dim intTotNum As Integer, sngAverage As Single
        Cls     'clears text printed by the Print method
        For intX = 1 To 2 Step 1
            intNumber = Val(InputBox("Enter a number", "Number Entry"))
            Print intNumber
            intTotNum = intNumber + intNumber
        Next intX
    
        sngAverage = intTotNum / (intX - 1)
        Print "The average number is: "; sngAverage
    End Sub
    
    Private Sub cmdExit_Click()
        Unload frmDebug3
    End Sub
    
    Private Sub Form_Load()
        frmDebug3.Left = (Screen.Width - frmDebug3.Width) / 2
        frmDebug3.Top = (Screen.Height - frmDebug3.Height) / 2
    End Sub
    
    when I do the average of 5 and 7 it comes to 7
     
  2. RaginBajin

    RaginBajin Have you punched a donkey today?

    Joined:
    Dec 24, 2001
    Messages:
    8,740
    Likes Received:
    0
    Location:
    NoVA
    It looks to me and I am not a VB person is that when you go through to get another number the program is not remembering what the first number was..

    Hopefully it helps but here's what I would do.. Syntax might not be right
    Code:
    
    intTotNum =0
    For intX = 1 To 2 Step 1
            intNumber = Val(InputBox("Enter a number", "Number Entry"))
            Print intNumber
            intTotNum = intTotNum + intNumber
        Next intX
    
    
    And when you are doing your average whey are you subtracting one from your iteration number. It should be still 2..


    Hope it gets you going..
     
  3. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    That's what I was thinking too, but wouldn't the old code calculate the average to be 14 then?
     
  4. HardTech

    HardTech hungry

    Joined:
    May 5, 2000
    Messages:
    28,103
    Likes Received:
    1
    Location:
    NorCal
    first iteration - input = 5

    intTotNum = 5 + 5
    intTotNum = 10

    second iteration - input = 7
    inTotnum = 7 + 7
    intTotnum = 14

    average = 14 / (3-1) = 7

    try this:
    Code:
    intTotNum = 0
        For intX = 1 To 2 Step 1
            intNumber = Val(InputBox("Enter a number", "Number Entry"))
            Print intNumber
            intTotNum = intTotNum + intNumber
        Next intX
    
        sngAverage = intTotNum / (intX - 1)
    
     
  5. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    I swear this forum is full of people who don't bother reading previous responses.
     
  6. HardTech

    HardTech hungry

    Joined:
    May 5, 2000
    Messages:
    28,103
    Likes Received:
    1
    Location:
    NorCal
    I read the first message, didn't see any "Thanks! It works now!" message or anything, so I posted what I think is the correct code. sorry
     
  7. RaginBajin

    RaginBajin Have you punched a donkey today?

    Joined:
    Dec 24, 2001
    Messages:
    8,740
    Likes Received:
    0
    Location:
    NoVA
    WOOT.. I was right then.. This whole crazy programming thing is starting to make sense.. Even though I don't use VB... Woo Hoo
     
  8. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    That's true, but why not say, I agree, instead of writing out duplicate code? And if it's not duplicate (and it isn't obvious if it isn't), then what exactly is different? Regardless, because there is no mention of the code that was written already, you have to waste time figuring out which one is correct.
     

Share This Page