Results 1 to 8 of 8

Thread: How to sum up?

  1. #1

    Thread Starter
    Junior Member skywalker01's Avatar
    Join Date
    Dec 2010
    Posts
    19

    How to sum up?

    hello there
    i created form in which we enter the hours employee work in each session in a day, now i want to calc the sum of all the values entered in each text box automatically..i dont want to use any command button to calc sum.
    for eg:
    Employee nameanny
    on base : 4
    On Fleet : 5
    total hrs : 9

    this is how my form will look like

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: How to sum up?

    if you want the textbox holding the total hrs to show the sum automatically you need to code each textbox holding entries (except the one holding the total hrs) to do the addition after the entry has changed. I'd suggest to use the _Lostfocus Event to hold the code.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: How to sum up?

    opus is correct. Another event you can try is _TextChanged depending on how you wish your app to respond.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  4. #4

    Thread Starter
    Junior Member skywalker01's Avatar
    Join Date
    Dec 2010
    Posts
    19

    Re: How to sum up?

    can you guys provide me with a sample code...it could help me alot!!!

  5. #5
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: How to sum up?

    Ok If I am understand right you have 4 textbox - one for name , one for base,one for fleet and one who have to show the sum of the hours - total hrs Then Your code will look like this:
    Code:
    Form Load:
    Dim Name As String
     txtName.Text = Name - after that you can call Name and the name will be saved but when you close the program will disappear.
    Timer 1 'cos you wan't it without button or something
    txtTotalhrs.Text = Val(txtBase) + Val(txtFleet)
    For the Val() I am agree to I just missed.
    Last edited by mitko29; Jan 5th, 2011 at 11:39 AM.

  6. #6
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: How to sum up?

    Quote Originally Posted by mitko29 View Post
    Ok If I am understand right you have 4 textbox - one for name , one for base,one for fleet and one who have to show the sum of the hours - total hrs Then Your code will look like this:
    Code:
    Form Load:
    Dim Name As String
    Name = txtName.Text - after that you can call Name and the name will be saved but when you close the program will disappear.
    Timer 1 'cos you wan't it without button or something
    txtBase + txtFleet = txtTotalhrs.Text
    WTH is that?

    All of that in Form_Load? That way any input after the Fom_load will not be calculated!
    With which code would that String be saved? I don't see any!
    What are you using Timer 1 for?
    At last you are trying to add two Strings, but do even that in the wrong order!

    @skywalker: disregard the previous post!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: How to sum up?

    assuming you have textboxes named "txtbxOnBase" and "txtbxOnFleet" and for the Result a textbox named "txtbxTotal".

    Code:
    Private Sub txtbxOnBase_LostFocus()
    txtbxTotal.Text = Val(txtbxOnBase.Text)+Val(txtbxOnFleet.Text)
    End Sub
    Private Sub txtbxOnFleet_LostFocus()
    txtbxTotal.Text = Val(txtbxOnBase.Text)+Val(txtbxOnFleet.Text)
    End Sub
    If you would have the textboxes in an array, you would need this Sub only once.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: How to sum up?

    He want something who will show result without clicking any button or something for that I put it in Timer, he said that the value in txtbxOnBase and txtbxOnFleet will be already entered with some value.
    There is nothing wrong in my code and my idea was the same,I don't write how to save it 'cos he can read it here in the forum,there is so many Topics.
    I said that "the String wouldn't be saved parmanent"
    And If he wan't to add more names - let's change it,what is the problem ?
    I am not here to write his homework or some home idea I just only give a example the same you do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width