Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Type Mismatch Help

I have a userform with textbox1 and textbox2. The input into each is time as
hh:mm. I need to subtract the two. However I get a type mismatch for the
following formula:

ttltime2 = textbox2 - textbox1

ttltime2 is DIM as Double.

How do I correct this?

Another question I have is this: Is there a way to format the above
textboxes to
hh:mm so that I can enter 0823 and have it accepted as 08:23?

Thanks,
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Type Mismatch Help

I'd check the value to make sure that they are both numeric:

if isnumeric(me.textbox1.value) _
and isnumeric(me.textbox2.value) then
me.ttltime2.value = me.textbox2.value - me.textbox1.value
else
me.ttltime2.value = "Non-numerics in textbox1 or textbox2"
end if



WLMPilot wrote:

I have a userform with textbox1 and textbox2. The input into each is time as
hh:mm. I need to subtract the two. However I get a type mismatch for the
following formula:

ttltime2 = textbox2 - textbox1

ttltime2 is DIM as Double.

How do I correct this?

Another question I have is this: Is there a way to format the above
textboxes to
hh:mm so that I can enter 0823 and have it accepted as 08:23?

Thanks,
Les


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Type Mismatch Help

You could do something like:

Option Explicit
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

If InStr(1, Me.TextBox1.Value, ":", vbTextCompare) = 0 Then
'do some work
If IsNumeric(Me.TextBox1.Value) Then
Me.TextBox1.Value = Format(Me.TextBox1.Value, "00\:00")
Else
Beep
Me.TextBox1.Value = ""
Cancel = True
End If
End If

End Sub

But you may want to add a few more validity checks--so that 9876 doesn't end up
as 98:76.


WLMPilot wrote:

I have a userform with textbox1 and textbox2. The input into each is time as
hh:mm. I need to subtract the two. However I get a type mismatch for the
following formula:

ttltime2 = textbox2 - textbox1

ttltime2 is DIM as Double.

How do I correct this?

Another question I have is this: Is there a way to format the above
textboxes to
hh:mm so that I can enter 0823 and have it accepted as 08:23?

Thanks,
Les


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Type Mismatch Help

ps. I didn't notice that ttltime2 was a double.

if isnumeric(me.textbox1.value) _
and isnumeric(me.textbox2.value) then
ttltime2 = me.textbox2.value - me.textbox1.value
else
ttltime2 = 999999 'or 0???
end if

Dave Peterson wrote:

I'd check the value to make sure that they are both numeric:

if isnumeric(me.textbox1.value) _
and isnumeric(me.textbox2.value) then
me.ttltime2.value = me.textbox2.value - me.textbox1.value
else
me.ttltime2.value = "Non-numerics in textbox1 or textbox2"
end if

WLMPilot wrote:

I have a userform with textbox1 and textbox2. The input into each is time as
hh:mm. I need to subtract the two. However I get a type mismatch for the
following formula:

ttltime2 = textbox2 - textbox1

ttltime2 is DIM as Double.

How do I correct this?

Another question I have is this: Is there a way to format the above
textboxes to
hh:mm so that I can enter 0823 and have it accepted as 08:23?

Thanks,
Les


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Type Mismatch Help

It would be easier to Dim as Date and then input the times in a Date/Time
format such as 00:00am/pm or use 24 Hour times 08:00, 14:30. You can then
subtract one from the other to get ttltime worked. Then you would Dim
ttltime as Double to get the answer in decimal hours. ttltime = Hours(CkOut)
+ (Minutes(CkOut)/60) - Hours(CkIn) + (Minutes(CkIn)/60).

Mike F
"Dave Peterson" wrote in message
...
You could do something like:

Option Explicit
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

If InStr(1, Me.TextBox1.Value, ":", vbTextCompare) = 0 Then
'do some work
If IsNumeric(Me.TextBox1.Value) Then
Me.TextBox1.Value = Format(Me.TextBox1.Value, "00\:00")
Else
Beep
Me.TextBox1.Value = ""
Cancel = True
End If
End If

End Sub

But you may want to add a few more validity checks--so that 9876 doesn't
end up
as 98:76.


WLMPilot wrote:

I have a userform with textbox1 and textbox2. The input into each is
time as
hh:mm. I need to subtract the two. However I get a type mismatch for
the
following formula:

ttltime2 = textbox2 - textbox1

ttltime2 is DIM as Double.

How do I correct this?

Another question I have is this: Is there a way to format the above
textboxes to
hh:mm so that I can enter 0823 and have it accepted as 08:23?

Thanks,
Les


--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type mismatch... George[_4_] Excel Discussion (Misc queries) 7 December 19th 07 12:20 PM
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
type mismatch? Gixxer_J_97[_2_] Excel Programming 4 April 1st 05 03:20 AM


All times are GMT +1. The time now is 04:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"