How to concatenate multiple textboxes

Solved
coupidon Posted messages 98 Status Member -  
Ant049 Posted messages 157 Status Member -
Hello,

I have 3 textboxes where I input:
- hours in the first
- minutes in the second
- seconds in the third
I chose this configuration for aesthetics, anyway

I would like to perform a calculation in VBA on Excel using the current date and time with the function

now()

but how can we concatenate the 3 textboxes to allow this calculation?

Thanks to anyone who can help.....

1 answer

  1. Ant049 Posted messages 157 Status Member 22
     
    Hello,

    To concatenate your text boxes:
    Nomdetavariable = TextBox1.Value & ":" & TextBox2.Value & ":" & TextBox3.Value


    What operation do you want to perform?

    --
    When the wise man points to the moon, the fool looks at the finger.
    0
    1. coupidon Posted messages 98 Status Member 1
       
      I want to use today's date with now() in this date normally there is the date, the day, the year and the hours, minutes, seconds.

      I want to enter in three textboxes, the hours in one, the minutes in the other and the seconds in the last
      and with that I want to perform the calculation of the three textboxes with the now() at the moment and have it add those hours, you see?

      An example:
      textbox1: 5 hours
      textbox2: 20 minutes
      textbox3: 41 seconds

      Let’s say that right now "now()" we are on Thursday, September 08, 2016, 10:06:06
      and a textbox4 for example displays the result:

      15:26:47

      There you go, it seems simple in Excel but in VBA I’m struggling, so I thought about concatenation.
      0
    2. Ant049 Posted messages 157 Status Member 22
       
      Alright, I've given you a concatenation option in my first post.
      For the addition, you need to use the Time function in VBA, which will return the time with minutes and seconds.
      Be careful with the formats! To add the two, you'll need to adjust the format; I'll let you figure that out and come back if you get stuck.
      0
      1. coupidon Posted messages 98 Status Member 1 > Ant049 Posted messages 157 Status Member
         
        Good evening,

        I tested your code, so here it is, like this it works, but I can't figure out how to use the Time function in this code.
        When I use the variable H and want to perform calculations, it gives me errors, so I'm stuck...
        I searched for VBA courses on the Time function, but with my concatenation, it bugs.
        I'm not sure if it's treated as a time, so I can actually do the calculation.


        Private Sub TextBox10_AfterUpdate()


        Dim H As String
        H = TextBox8.Value & ":" & TextBox9.Value & ":" & TextBox10.Value

        TextBox16.Value = H
        End Sub
        0
    3. coupidon Posted messages 98 Status Member 1
       
      but for this subject you met my expectations, so I consider this question resolved, thank you
      0
    4. Ant049 Posted messages 157 Status Member 22
       
      Hello,

      You have the method to concatenate your textboxes.
      Regarding adding the two times:
      - try playing with the formats:
      Format(value, "desired format")

      - look at functions like DateAdd.
      0