How do I get the average either higher/lower in their textboxes?

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 1115 Views - Last Post: 26 March 2010 - 03:45 PM Rate Topic: -----

#16 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 590
  • Joined: 04-May 09

Re: How do I get the average either higher/lower in their textboxes?

Posted 26 March 2010 - 11:48 AM

Hi,

Did you tested my solution, see post #14.
I've added these two codes for you.

' look here how it should be 
 
        If Integer.TryParse(counter, total) Then 
            TextBox5.Text = TextBox3.Text / counter 
        End If 
        If Integer.TryParse(counter1, total1) Then 
            TextBox6.Text = TextBox2.Text / counter1 
        End If 


Should work now.
Was This Post Helpful? 0
  • +
  • -

#17 mbrother64  Icon User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 78
  • Joined: 30-August 09

Re: How do I get the average either higher/lower in their textboxes?

Posted 26 March 2010 - 11:59 AM

View Postemresutisna, on 26 March 2010 - 07:26 AM, said:

Just try this code :
        ListBox1.Items.Clear()
        ListBox2.Items.Clear()
        ListBox3.Items.Clear()
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
        TextBox5.Clear()
        TextBox6.Clear()
        Dim Subject As Integer
        Subject = Val(InputBox("How many products"))
        Dim i As Integer
        Dim j As Integer = 0
        Dim k As Integer = 0
        Dim num As Integer
        Dim total As Integer
        Dim average As Integer
        Dim total1 As Integer
        Dim total2 As Integer

        For i = 1 To Subject
            num = (Val(InputBox("Enter sales amount:")))
            total = total + num
            average = total / Subject
            ListBox1.Items.Add(word & ControlChars.Tab & num)
            Select Case num
                Case Is > 1200
                    total1 = total1 + num
                    j += 1
                    TextBox3.Text = total1
                    TextBox5.Text = total1 / j
                    ListBox2.Items.Add(word & ControlChars.Tab & num)
                Case Is <= 1200
                    ListBox3.Items.Add(word & ControlChars.Tab & num)
                    total2 = total2 + num
                    k += 1
                    TextBox4.Text = total2
                    TextBox6.Text = total2 / k
            End Select

        Next

        TextBox1.Text = total
        TextBox2.Text = average



Awesome, thanks emresutisna!!! Your code works great. All I needed was just those few lines of code to help me figure it out. Specifically the j & k parts.
Was This Post Helpful? 0
  • +
  • -

#18 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How do I get the average either higher/lower in their textboxes?

Posted 26 March 2010 - 12:03 PM

This is horrible programming practice

Dim Subject As Integer
Subject = InputBox("How many products")

For i = 1 To Subject



And if you turn on Option Explicit you will see that is does not work. If you're going to be a programmer please take the advice of those who have been in the industry for a while, we really do know what we're talking about (that's how we have made it so long in this industry)
Was This Post Helpful? 0
  • +
  • -

#19 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 458
  • View blog
  • Posts: 4,222
  • Joined: 25-March 09

Re: How do I get the average either higher/lower in their textboxes?

Posted 26 March 2010 - 12:08 PM

as PsychoCoder say. and go to Project->YourProject Properties. then from the tabs at the right side find references and turn off Microsoft.VisualBasic and see what happen. if your going to use VB.NET forget about VB6

This post has been edited by NoBrain: 26 March 2010 - 12:09 PM

Was This Post Helpful? 0
  • +
  • -

#20 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1959
  • View blog
  • Posts: 8,700
  • Joined: 29-May 08

Re: How do I get the average either higher/lower in their textboxes?

Posted 26 March 2010 - 12:35 PM

Seeing that someone caved in and hand out the code.

Here's a better way, it should be note I would use the vb6 InputBox but my own.
  ' Get number of products from user '
  Dim strNumberOfProducts As String = InputBox("How many products")
  ' Declare an variable to store the number of products '
  Dim NumberOfProducts As Integer
  ' Check to see if the user input is valid '
  If Integer.TryParse(strNumberOfProducts, NumberOfProducts) = False Then
   ' Error message because the user didn't input a valid number '
   MessageBox.Show("Please Enter a valid number.")
  Else

   ' Declare the threshold '
   Dim Threshold As Integer = 1200
   ' Declare Variable to store total, number of items below threshold value '
   Dim Below_Count As Integer
   Dim Total_Below As Integer
   ' Declare Variable to store total, number of items above threshold value '
   Dim Above_Count As Integer
   Dim Total_Above As Integer

   For i = 1 To NumberOfProducts
    ' Get Product Name from User '
    Dim ProductName = InputBox("Enter product name:")
    Dim SalesAmount As Integer
    ' Assume that the string (Sales Amount) is not valid  '
    Dim IsValid As Boolean = False
    ' Continue to ask for number, until input is valid. '
    While Not IsValid
     ' Get sales amount from user '
     Dim inString As String = InputBox("Enter sales amount:")
     ' Test to see if the input is valid '
     IsValid = Integer.TryParse(inString, SalesAmount)
     ' Is the input a valid number? '
     If IsValid Then Exit While
     ' No, the display error message '
     MessageBox.Show("Please Enter a valid number.")
    End While
    ' Having gotten a valid sales amount. '
    ' Is the value of sales amount above our thershold of 1200 '
    If SalesAmount > Threshold Then
     ' Yes, then increment the total above by this amount and increment above count by one '
     Total_Above += SalesAmount
     Above_Count += 1
     ' Add this product and sales amount to above list '
     lst_ItemsAbove.Items.Add(ProductName & ControlChars.Tab & SalesAmount)
    Else
     ' No, then increment the total below by this amount and increment below count by one '
     Total_Below += SalesAmount
     Below_Count += 1
     ' Add this product and sales amount to above list '
     lst_ItemsBelow.Items.Add(ProductName & ControlChars.Tab & SalesAmount)
    End If
    ' Continue Looping until all sales products have entered. '
   Next

   ' Done getting all the product names and sales amounts. '

   ' Calculate average for sales products above threshold '
   Dim Average_Above As Double = Total_Above / Above_Count
   ' Output average to textbox '
   txt_AverageAbove.Text = Average_Above.ToString
   ' Output total to textboc '
   txt_Total_Above.Text = Total_Above.ToString
   ' Calculate average for sales products below threshold '
   Dim Average_Below As Double = Total_Below / Below_Count
   ' Output total to textbox '
   txt_AverageBelow.Text = Average_Below.ToString()
   ' Output average to textbox '
   txt_Total_Below.Text = Total_Below.ToString()
   ' Calculate combined total '
   Dim total As Integer = Total_Above + Total_Below
   ' Calculate combine average for all sales products
   Dim average As Double = total / (Above_Count + Below_Count)
   ' Output combined total to textbox '
   txt_Total.Text = total.ToString
   ' Output combined average to textbox '
   txt_Average.Text = average.ToString

  End If

You should see it closely resembles to pseudocode (~The Comments).
Much easier to understand when you use meaningful names for the controls and variables.
Was This Post Helpful? 0
  • +
  • -

#21 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How do I get the average either higher/lower in their textboxes?

Posted 26 March 2010 - 02:57 PM

mbrother64 I just have to say something. You have a horrible attitude. I've been reading through some of your threads and replies in them and I can say in confidence that I'm 100% happy I will never have to work with you on any programming task ever, and I feel for anyone who ever has to.

You come here and beg for help, yet insult those who try and help if they dont give you the exact reply you're looking for. You vote them down when they point out any mistake you make, and try to point you in the right direction. You vote them down if they point out that you're doing something the wrong way and try to show a better, more acceptable way of doing something.

I honestly think you need to think long and hard before opening another thread looking for help. The kind of attitude you're exhibiting is gong to do nothing for you in the future, and is only going to hurt your future as a programmer in the real world, as no one on this planet wants to associate with someone with the type of attitude you're showing. So, go a head and vote me down again for this as I truly dont care, I dont help people for rep points, I help because I enjoy helping, but none of that help will ever be coming your direction.
Was This Post Helpful? 4
  • +
  • -

#22 mbrother64  Icon User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 78
  • Joined: 30-August 09

Re: How do I get the average either higher/lower in their textboxes?

Posted 26 March 2010 - 03:39 PM

So I'll create a new profile, its not that hard..

"You vote them down when they point out any mistake you make, and try to point you in the right direction. "

I never made any mistakes, my code was working perfectley!!!! He wasnt pointing me in the right direction, he was just dragging the topic off course. All I needed was these few simple lines:
            Dim j As Integer = 0
            Dim k As Integer = 0
            Dim total1 As Integer
            Dim total2 As Integer

                Select Case num
                    Case Is > 1200
                        total1 = total1 + num
                        j += 1
                        TextBox5.Text = total1 / j
                        TextBox3.Text = total1
                    Case Is <= 1200
                        total2 = total2 + num
                        k += 1
                        TextBox6.Text = total2 / k
                End Select

Was This Post Helpful? -3
  • +
  • -

#23 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How do I get the average either higher/lower in their textboxes?

Posted 26 March 2010 - 03:45 PM

Well you can think that all you want. If you create another account I'll still know it's you so dont go that route.

You did (and do) make mistakes, you're using horrible coding practices, and when someone tried to point it out and show you the right way to do something insult them then vote them down. I can guarantee you will not be getting much more here or anywhere else with that kind of attitude, no one likes an ungrateful person.

Just because it works in your environment doesn't mean it's right. If you turn on Option Explicit in your IDE your code will crash and crash hard, but you're obviously too good to listen to anyone so good luck with your programming career, no matter how short it may be.
Was This Post Helpful? 4
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2