Solved

Display the smallest and largest number entered

Posted on 2012-04-09
3
397 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

832 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