[VBA] Time in a textBox

Solved
Noodlesnood Posted messages 33 Status Member -  
 Lorenzozo -
Hello,

Here is my problem: I would like to transpose into a textBox my number of hours from my cell C96, but it gives me a decimal number with this part of the code:

UsfNew2.TextBox10.Value = Feuil12.Range("C96").Value

Should I convert it to a string? How should I do that?

Nood
Configuration: Windows XP Firefox 2.0.0.1

8 answers

blux Posted messages 2033 Registration date   Status Moderator Last intervention   3 455
 
Hi,

it's normal, EXCEL saves time as multiples of days:

12:00 -> 0.5
01:00 -> 0.041666667
24:00 -> 1

So you need to use the functions that return hours, minutes, and seconds from a serial number:
UsfNew2.TextBox10.Value = HOUR(Feuil12.Range("C96").Value) & ":" & MINUTE(Feuil12.Range("C96").Value) & ":" & SECOND(Feuil12.Range("C96").Value)

Would that work?

--
See you, Blux
"The idiots, they dare everything. That's even how you recognize them"
0
Noodlesnood Posted messages 33 Status Member 2
 
Hi blux,

I tried your method and I have an error message 'Sub or Function not defined' (cursor on TIME). Thanks for your help ; )

Nood
0
Noodlesnood Posted messages 33 Status Member 2
 
Up

I still can't transfer the time into the TextBox. Do I need to declare the functions HOUR, MINUTE, and SECOND before using them? How?
0
blux Posted messages 2033 Registration date   Status Moderator Last intervention   3 455
 
Sorry, I didn't realize it was VBA...

So it's in English: hour, minute, second...

--
See you, Blux
 "You can’t underestimate the stupidity of a good chunk of the population." 
0
Noodlesnood Posted messages 33 Status Member 2
 
I should have thought of that: D ... Anyway, thank you blux, you are a great help for me as a beginner; ).
0
Daranc
 
The following instruction:
TextBox1.Value = Format(Range("a1").Value, "hh:mm:ss AMPM")
returns the value of cell A1 in the format hour minute seconds PM or AM
Daranc
0
Daranc
 
In your case
UsfNew2.TextBox10.Value = format(Feuil12.Range("C96").Value,"hh:mm:ss AMPM")
Daranc
0
Lorenzozo
 
Hello,

I'm trying to use the codes below, but where should I position this code sequence? In the main procedure that uses this textbox or in the procedure that manages the opening of the dialog box where the textbox is located???? Help please.

Thank you in advance

Lorenzozo
0