Solved

Display the smallest and largest number entered

Posted on 2012-04-09
3
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

696 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