calculating

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    calculating

    hello it's me again;

    i am having a problem with calculating some totals in my project. I have fields on my form that need to be calculated to get a percentage in the end
    I wish i could show you what my form looks like but don't know how to. so i will kinda show you this way:

    there are 11 textboxes going across the form with lables

    textboxnames are as followed

    date, neworders,new,u sed,replacement orders,newcontr acts,shortinbun dles,total,tota lnew,usedtotal, totalpercent

    what i need to calculate is this:

    neworders + replacementorde rs + newcontracts + shortinbundles) in the total

    to calculate the percentage i need:

    usedtotal / total) in the totalpercent

    how can i do this?

    lee123
  • lee123
    Contributor
    • Feb 2007
    • 556

    #2
    well this is what i have done:

    Code:
    Option Explicit
    Private Sub TotalPercent_LostFocus()
        Total.Text = Val(NewOrders.Text) + Val(ReplacementOrders.Text) + Val(Newcontracts.Text) + Val(ShortInBundles.Text)
        TotalPercent.Text = Val(UsedTotal.Text) / Val(Total.Text)
        TotalPercent.Text = FormatPercent(TotalPercent)
    End Sub
    Private Sub txtNew_LostFocus()
        Dim TotalNew As Integer
        frmQuarterly.TotalNew.Text = txtNew.Text
    End Sub
    Private Sub Used_LostFocus()
          Dim Used As Integer
        frmQuarterly.Used.Text = totalused.Text
    End Sub
    Private Sub txtUsed_LostFocus()
     Dim UsedTotal As Integer
     frmQuarterly.UsedTotal.Text = txtUsed.Text
    End Sub
    but in the percentages i get a weird number, i want whole percentages? instead of 39.28% i would like it to round off to 39.00% or 40.00%.

    lee123

    Comment

    • MikeTheBike
      Recognized Expert Contributor
      • Jun 2007
      • 640

      #3
      Originally posted by lee123
      well this is what i have done:

      Code:
      Option Explicit
      Private Sub TotalPercent_LostFocus()
          Total.Text = Val(NewOrders.Text) + Val(ReplacementOrders.Text) + Val(Newcontracts.Text) + Val(ShortInBundles.Text)
          TotalPercent.Text = Val(UsedTotal.Text) / Val(Total.Text)
          TotalPercent.Text = FormatPercent(TotalPercent)
      End Sub
      Private Sub txtNew_LostFocus()
          Dim TotalNew As Integer
          frmQuarterly.TotalNew.Text = txtNew.Text
      End Sub
      Private Sub Used_LostFocus()
            Dim Used As Integer
          frmQuarterly.Used.Text = totalused.Text
      End Sub
      Private Sub txtUsed_LostFocus()
       Dim UsedTotal As Integer
       frmQuarterly.UsedTotal.Text = txtUsed.Text
      End Sub
      but in the percentages i get a weird number, i want whole percentages? instead of 39.28% i would like it to round off to 39.00% or 40.00%.

      lee123
      Hi

      You coud try

      TotalPercent.Te xt = FormatPercent(R ound(TotalPerce nt,2))

      ??

      MTB

      Comment

      • lee123
        Contributor
        • Feb 2007
        • 556

        #4
        hello there MTB or anybody else who reads this post. I have a database in access and i am trying to build the same one in visual basic 6 i have the same fields as i do in the access database but in access you have a event name "continuous form" but in visual basic you don't you have to create you own boxes. so I have done this. each of the text boxes i have mentioned in the previous post stands for 1 week of data i have to fill in so I have put 44 textboxes for each week of a month, 11 textboxes going accross then under them i have 11 more etc. so there is 4 weeks worth (when it's a four week month)

        Then after i have filled these with the proper information i have two more textboxes one totals all the percentages and the other should give me the total percent of the whole thing. but i can't get these two text boxes to work right. how can i do this.

        lee123

        Comment

        • lee123
          Contributor
          • Feb 2007
          • 556

          #5
          oops i forgot to add this in the last post. in my access database in the "control source" box i have this code in it:

          Code:
          =Round(Sum([totalpercent])/Count([date]),2)
          how can i do something like this i visual basic. for the total percent of the whole thing

          lee123

          Comment

          Working...