Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Problem adding the values of 2 TextBoxes

Can anyone tell me why these do not add together?

TextBox1 = TextBox13.Value + TextBox23.Value

Lets say the value of TextBox13 is 53 and the value of TextBox23 is 10.
Instead of returning 63 I get 5310.



Below is the code that generates the value of TextBox13

TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value))
* 24
TextBox13.Value = Format(TextBox13.Value, "0.0000")



TextBox12 value is entered by the user as a time without the : such as 1843
for 6:43 pm and then converted to the correct format by the code below


Private Sub TextBox12_AfterUpdate()

TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value, ":",
""), "00\:00"), "hh:mm")

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Problem adding the values of 2 TextBoxes

try cval(TextBox13.value) + cval(TextBox23.value)

--


Gary K



"Patrick C. Simonds" wrote in message
...
Can anyone tell me why these do not add together?

TextBox1 = TextBox13.Value + TextBox23.Value

Lets say the value of TextBox13 is 53 and the value of TextBox23 is 10.
Instead of returning 63 I get 5310.



Below is the code that generates the value of TextBox13

TextBox13.Value = (TimeValue(TextBox12.Value) -
TimeValue(TextBox11.Value)) * 24
TextBox13.Value = Format(TextBox13.Value, "0.0000")



TextBox12 value is entered by the user as a time without the : such as
1843 for 6:43 pm and then converted to the correct format by the code
below


Private Sub TextBox12_AfterUpdate()

TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value, ":",
""), "00\:00"), "hh:mm")

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Problem adding the values of 2 TextBoxes

sorry, don't know what I was thinking

CDbl(Me.TextBox2.Value) + CDbl(Me.TextBox1.Value)

--


Gary K



"Patrick C. Simonds" wrote in message
...
Can anyone tell me why these do not add together?

TextBox1 = TextBox13.Value + TextBox23.Value

Lets say the value of TextBox13 is 53 and the value of TextBox23 is 10.
Instead of returning 63 I get 5310.



Below is the code that generates the value of TextBox13

TextBox13.Value = (TimeValue(TextBox12.Value) -
TimeValue(TextBox11.Value)) * 24
TextBox13.Value = Format(TextBox13.Value, "0.0000")



TextBox12 value is entered by the user as a time without the : such as
1843 for 6:43 pm and then converted to the correct format by the code
below


Private Sub TextBox12_AfterUpdate()

TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value, ":",
""), "00\:00"), "hh:mm")

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Problem adding the values of 2 TextBoxes

Thanks Gary

But of course my problems continue. The full line of code is below, and my
problem is that if any one of those TextBoxes is blank, I get a Type
Mismatch error. I am trying to avoid using helper cells on the worksheet.

Any ideas on how I can get it to ignore blank TextBoxes?





TextBox1.Value = CDbl(TextBox13.Value) + CDbl(TextBox23.Value) +
CDbl(TextBox33.Value) + CDbl(TextBox43.Value) + CDbl(TextBox53.Value) +
CDbl(TextBox63.Value) + CDbl(TextBox14.Value) + CDbl(TextBox24.Value) +
CDbl(TextBox34.Value) + CDbl(TextBox44.Value) + CDbl(TextBox54.Value) +
CDbl(TextBox64.Value)


"Gary Keramidas" wrote in message
...
sorry, don't know what I was thinking

CDbl(Me.TextBox2.Value) + CDbl(Me.TextBox1.Value)

--


Gary K



"Patrick C. Simonds" wrote in message
...
Can anyone tell me why these do not add together?

TextBox1 = TextBox13.Value + TextBox23.Value

Lets say the value of TextBox13 is 53 and the value of TextBox23 is 10.
Instead of returning 63 I get 5310.



Below is the code that generates the value of TextBox13

TextBox13.Value = (TimeValue(TextBox12.Value) -
TimeValue(TextBox11.Value)) * 24
TextBox13.Value = Format(TextBox13.Value, "0.0000")



TextBox12 value is entered by the user as a time without the : such as
1843 for 6:43 pm and then converted to the correct format by the code
below


Private Sub TextBox12_AfterUpdate()

TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value,
":", ""), "00\:00"), "hh:mm")

End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Problem adding the values of 2 TextBoxes

TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + ...

But this won't help if those textboxes contain real text.

I'd check each textbox for numeric data

Dim mySum as double

mySum = 0
if isnumeric(me.textbox13.value) then
mysum = mysum + cdbl(me.textbox13.value)
end if
if isnumeric(me.textbox23.value) then
mysum = mysum + cdbl(me.textbox13.value)
end if
....
me.textbox1.value = mysum

or...

Dim iCtr as long
dim mySum as double

mysum = 0
for ictr = 13 to 63 step 10
if isnumeric(me.controls("textbox" & ictr).value) then
mysum = mysum + me.controls("textbox" & ictr).value
end if
if isnumeric(me.controls("textbox" & ictr + 1).value) then
mysum = mysum + me.controls("textbox" & ictr + 1).value
end if
next ictr
me.textbox1.value = mysum


"Patrick C. Simonds" wrote:

Thanks Gary

But of course my problems continue. The full line of code is below, and my
problem is that if any one of those TextBoxes is blank, I get a Type
Mismatch error. I am trying to avoid using helper cells on the worksheet.

Any ideas on how I can get it to ignore blank TextBoxes?

TextBox1.Value = CDbl(TextBox13.Value) + CDbl(TextBox23.Value) +
CDbl(TextBox33.Value) + CDbl(TextBox43.Value) + CDbl(TextBox53.Value) +
CDbl(TextBox63.Value) + CDbl(TextBox14.Value) + CDbl(TextBox24.Value) +
CDbl(TextBox34.Value) + CDbl(TextBox44.Value) + CDbl(TextBox54.Value) +
CDbl(TextBox64.Value)

"Gary Keramidas" wrote in message
...
sorry, don't know what I was thinking

CDbl(Me.TextBox2.Value) + CDbl(Me.TextBox1.Value)

--


Gary K



"Patrick C. Simonds" wrote in message
...
Can anyone tell me why these do not add together?

TextBox1 = TextBox13.Value + TextBox23.Value

Lets say the value of TextBox13 is 53 and the value of TextBox23 is 10.
Instead of returning 63 I get 5310.



Below is the code that generates the value of TextBox13

TextBox13.Value = (TimeValue(TextBox12.Value) -
TimeValue(TextBox11.Value)) * 24
TextBox13.Value = Format(TextBox13.Value, "0.0000")



TextBox12 value is entered by the user as a time without the : such as
1843 for 6:43 pm and then converted to the correct format by the code
below


Private Sub TextBox12_AfterUpdate()

TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value,
":", ""), "00\:00"), "hh:mm")

End Sub



--

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
Adding values in textboxes? Tom Ogilvy Excel Programming 0 July 27th 04 08:29 PM
Adding values in textboxes? Bob Phillips[_7_] Excel Programming 0 July 27th 04 06:26 PM
Adding values in textboxes... Tom Ogilvy Excel Programming 0 July 27th 04 05:42 PM
Adding values in textboxes... Jake Marx[_3_] Excel Programming 0 July 27th 04 05:38 PM
Adding the values of 2 textboxes Ben Allen Excel Programming 3 April 29th 04 09:05 PM


All times are GMT +1. The time now is 11:42 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"