Solved

Display the smallest and largest number entered

Posted on 2012-04-09
3
368 Views
Last Modified: 2012-06-21
I havea majority of the program written and need assistant working the bugs out need to display the smallest and largest number entered to display. Working in VB6
0
Comment
Question by:gorean4u
  • 2
3 Comments
 

Author Comment

by:gorean4u
Comment Utility
Here is what i have so far


Private Sub cmdInput_Click()
    'Declare Variables
    Dim intNumber As Integer
    Dim intAverage As Integer
    Dim strAverage As String
    Dim lngSum As Long
    Dim strSum As String
    Dim intCounter As Integer
    Dim strCounter As String
    Dim strDisplayTotal As String
    Dim strDisplayAverage As String
    Dim strDisplaySum As String
    Dim strDisplayMin As String
    Dim strDisplayMax As String
    Dim strMin As String
    Dim strMax As String
    Dim intMin As Integer
    Dim intMax As Integer
    Dim varNumber As Integer
   
    'Initialize variables
    intCounter = 0
    lngSum = 0
   
   'Input Numbers
    Do
        intNumber = Val(InputBox("Enter an Integer (0 to Quit): ", _
            "input Number"))
       
        If (intNumber > 0) Then
            lngSum = lngSum + intNumber
            intCounter = intCounter + 1
        End If
       
        If intNumber > varNumber Then
            intNumber = intMax
        End If
       
        If intNumber < varNumber Then
            intNumber = intMin
        End If
           
     Loop Until (intNumber = 0)
   
    intAverage = lngSum / intCounter
   
    'Store results
    strAverage = Format(intAverage, "###")
    strCounter = Format(intCounter, "#####")
    strSum = Format(lngSum, "#####")
    strMin = Format(intMin, "#####")
    strMax = Format(intMax, "#####")
   
    strDisplayTotal = "numbers entered: " & strCounter
    strDisplaySum = "Sum of numbers: " & strSum
    strDisplayAverage = "Average of numbers: " & strAverage
    strDisplayMin = "Smallest Number entered: " & strMin
    strDisplayMax = "Largest Number entered: " & strMax
   
   
   
    'Display results
    lblTotal.Caption = strDisplayTotal
    lblSum.Caption = strDisplaySum
    lblAverage.Caption = strDisplayAverage
    lblMin.Caption = strDisplayMin
    lblMax.Caption = strDisplayMax
    lblTotal.Visible = True
    lblSum.Visible = True
    lblAverage.Visible = True
    lblMin.Visible = True
    lblMax.Visible = True
   
End Sub
0
 

Author Comment

by:gorean4u
Comment Utility
Any takers, please
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
Change this:
        If (intNumber > 0) Then
            lngSum = lngSum + intNumber
            intCounter = intCounter + 1
        End If
        
        If intNumber > varNumber Then
            intNumber = intMax
        End If
        
        If intNumber < varNumber Then
            intNumber = intMin
        End If

Open in new window


To This:
        If (intNumber > 0) Then
            lngSum = lngSum + intNumber
            intCounter = intCounter + 1

            If intCounter = 1 Then
                intMin = intNumber
                intMax = intNumber
            Else
                If intNumber < intMin Then
                    intMin = intNumber
                End If

                If intNumber > intMax Then
                    intMax = intNumber 
                End If        
            End If
        End If        

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Articles on a wide range of technology and professional topics are available on Experts Exchange. These resources are written by members, for members, and can be written about any topic you feel passionate about. Learn how to best write an article t…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now