Solved

Display the smallest and largest number entered

Posted on 2012-04-09
3
408 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
ID: 37825411
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
ID: 37825624
Any takers, please
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37825723
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally published Entrepreneur.com Booming numbers of freelancing professionals are changing the face of work. In the United States alone last year, the number of workers freelancing grew from 700,000 to 54 million, according to a Freelancers’…
With the shift in today’s hiring climate (http://blog.experts-exchange.com/ee-blog/5-tips-on-succeeding-in-the-new-gig-economy/?cid=Blog_031816), many companies are choosing to hire freelancers to get projects completed efficiently and inexpensively…

827 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