Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Confused by CDbl behaviour

Hi,

Can someone please tell me why this does not work (it throws up a type
mismatch):

Sub Cost_Update()

Dim dMitCost As Double

dMitCost = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
FmRiskCost.TextBox23.Value = dMitCost
End

I am trying to capture (up to) five values entered into textboxes on a form,
add them and then send the total value to another text box on the same form.
I can do this by replacing the CDbl with a Val, but the calculation then goes
haywire when lage numbers are inputted.

Is this a variation on the old thing of XL assuming that anything joined by
a '+' sign is a string not a number? If so, how do I get around it?

Hope this makes some sense!

TIA

Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,276
Default Confused by CDbl behaviour

Try
If IsNumeric(Me.FmRiskCost.TextBox9.Value) _
And IsNumeric(Me.FmRiskCost.TextBox10.Value) _
And IsNumeric(Me.FmRiskCost.TextBox11.Value) _
And IsNumeric(Me.FmRiskCost.TextBox12.Value) _
And IsNumeric(Me.FmRiskCost.TextBox13.Value) Then

Me.dMitCost.value = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
Me.FmRiskCost.TextBox23.Value = Me.dMitCost.Value
End




"Risky Dave" wrote:

Hi,

Can someone please tell me why this does not work (it throws up a type
mismatch):

Sub Cost_Update()

Dim dMitCost As Double

dMitCost = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
FmRiskCost.TextBox23.Value = dMitCost
End

I am trying to capture (up to) five values entered into textboxes on a form,
add them and then send the total value to another text box on the same form.
I can do this by replacing the CDbl with a Val, but the calculation then goes
haywire when lage numbers are inputted.

Is this a variation on the old thing of XL assuming that anything joined by
a '+' sign is a string not a number? If so, how do I get around it?

Hope this makes some sense!

TIA

Dave

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Confused by CDbl behaviour

Eduardo,

Thanks for the quick response.

I'm not quite sure what you mean with this (I'm not a programmer - just
learnign this stuff as I go along).

If I insert another IF statement around the existing code as per your
posting, XL throws back an error about invalid use of "Me." If I remove the
Me, then the code simply skips past the line intended to capture the input,
ie. the IF statement is false so it is just ignored so I don't get the output
I need.

Obviously, I'm missing something here.

TIA

Dave

"Eduardo" wrote:

Try
If IsNumeric(Me.FmRiskCost.TextBox9.Value) _
And IsNumeric(Me.FmRiskCost.TextBox10.Value) _
And IsNumeric(Me.FmRiskCost.TextBox11.Value) _
And IsNumeric(Me.FmRiskCost.TextBox12.Value) _
And IsNumeric(Me.FmRiskCost.TextBox13.Value) Then

Me.dMitCost.value = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
Me.FmRiskCost.TextBox23.Value = Me.dMitCost.Value
End




"Risky Dave" wrote:

Hi,

Can someone please tell me why this does not work (it throws up a type
mismatch):

Sub Cost_Update()

Dim dMitCost As Double

dMitCost = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
FmRiskCost.TextBox23.Value = dMitCost
End

I am trying to capture (up to) five values entered into textboxes on a form,
add them and then send the total value to another text box on the same form.
I can do this by replacing the CDbl with a Val, but the calculation then goes
haywire when lage numbers are inputted.

Is this a variation on the old thing of XL assuming that anything joined by
a '+' sign is a string not a number? If so, how do I get around it?

Hope this makes some sense!

TIA

Dave

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,276
Default Confused by CDbl behaviour

Hi Dave,
what version of excel are you using

"Risky Dave" wrote:

Eduardo,

Thanks for the quick response.

I'm not quite sure what you mean with this (I'm not a programmer - just
learnign this stuff as I go along).

If I insert another IF statement around the existing code as per your
posting, XL throws back an error about invalid use of "Me." If I remove the
Me, then the code simply skips past the line intended to capture the input,
ie. the IF statement is false so it is just ignored so I don't get the output
I need.

Obviously, I'm missing something here.

TIA

Dave

"Eduardo" wrote:

Try
If IsNumeric(Me.FmRiskCost.TextBox9.Value) _
And IsNumeric(Me.FmRiskCost.TextBox10.Value) _
And IsNumeric(Me.FmRiskCost.TextBox11.Value) _
And IsNumeric(Me.FmRiskCost.TextBox12.Value) _
And IsNumeric(Me.FmRiskCost.TextBox13.Value) Then

Me.dMitCost.value = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
Me.FmRiskCost.TextBox23.Value = Me.dMitCost.Value
End




"Risky Dave" wrote:

Hi,

Can someone please tell me why this does not work (it throws up a type
mismatch):

Sub Cost_Update()

Dim dMitCost As Double

dMitCost = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
FmRiskCost.TextBox23.Value = dMitCost
End

I am trying to capture (up to) five values entered into textboxes on a form,
add them and then send the total value to another text box on the same form.
I can do this by replacing the CDbl with a Val, but the calculation then goes
haywire when lage numbers are inputted.

Is this a variation on the old thing of XL assuming that anything joined by
a '+' sign is a string not a number? If so, how do I get around it?

Hope this makes some sense!

TIA

Dave

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Confused by CDbl behaviour

Office '07 under Vista

"Eduardo" wrote:

Hi Dave,
what version of excel are you using

"Risky Dave" wrote:

Eduardo,

Thanks for the quick response.

I'm not quite sure what you mean with this (I'm not a programmer - just
learnign this stuff as I go along).

If I insert another IF statement around the existing code as per your
posting, XL throws back an error about invalid use of "Me." If I remove the
Me, then the code simply skips past the line intended to capture the input,
ie. the IF statement is false so it is just ignored so I don't get the output
I need.

Obviously, I'm missing something here.

TIA

Dave

"Eduardo" wrote:

Try
If IsNumeric(Me.FmRiskCost.TextBox9.Value) _
And IsNumeric(Me.FmRiskCost.TextBox10.Value) _
And IsNumeric(Me.FmRiskCost.TextBox11.Value) _
And IsNumeric(Me.FmRiskCost.TextBox12.Value) _
And IsNumeric(Me.FmRiskCost.TextBox13.Value) Then

Me.dMitCost.value = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
Me.FmRiskCost.TextBox23.Value = Me.dMitCost.Value
End



"Risky Dave" wrote:

Hi,

Can someone please tell me why this does not work (it throws up a type
mismatch):

Sub Cost_Update()

Dim dMitCost As Double

dMitCost = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
FmRiskCost.TextBox23.Value = dMitCost
End

I am trying to capture (up to) five values entered into textboxes on a form,
add them and then send the total value to another text box on the same form.
I can do this by replacing the CDbl with a Val, but the calculation then goes
haywire when lage numbers are inputted.

Is this a variation on the old thing of XL assuming that anything joined by
a '+' sign is a string not a number? If so, how do I get around it?

Hope this makes some sense!

TIA

Dave



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,276
Default Confused by CDbl behaviour

Hi Dave,
I am not an expert as well but some nice people has helped me a lot and the
code is working beautifully to me, there is only one difference and it is I
don't include the form name and I missed some Me in the totals, sorry, try
this
Try
If IsNumeric(Me.TextBox9.Value) _
And IsNumeric(Me.TextBox10.Value) _
And IsNumeric(Me.TextBox11.Value) _
And IsNumeric(Me.TextBox12.Value) _
And IsNumeric(Me.TextBox13.Value) Then

Me.dMitCost.value = (CDbl(Me.TextBox9.Value) +
CDbl_(Me.TextBox10.Value) + CDbl(Me.TextBox11.Value) +
CDbl_(Me.TextBox12.Value) + CDbl(Me.TextBox13.Value))_
Me.TextBox23.Value = Me.dMitCost.Value
End



"Risky Dave" wrote:

Office '07 under Vista

"Eduardo" wrote:

Hi Dave,
what version of excel are you using

"Risky Dave" wrote:

Eduardo,

Thanks for the quick response.

I'm not quite sure what you mean with this (I'm not a programmer - just
learnign this stuff as I go along).

If I insert another IF statement around the existing code as per your
posting, XL throws back an error about invalid use of "Me." If I remove the
Me, then the code simply skips past the line intended to capture the input,
ie. the IF statement is false so it is just ignored so I don't get the output
I need.

Obviously, I'm missing something here.

TIA

Dave

"Eduardo" wrote:

Try
If IsNumeric(Me.FmRiskCost.TextBox9.Value) _
And IsNumeric(Me.FmRiskCost.TextBox10.Value) _
And IsNumeric(Me.FmRiskCost.TextBox11.Value) _
And IsNumeric(Me.FmRiskCost.TextBox12.Value) _
And IsNumeric(Me.FmRiskCost.TextBox13.Value) Then

Me.dMitCost.value = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
Me.FmRiskCost.TextBox23.Value = Me.dMitCost.Value
End



"Risky Dave" wrote:

Hi,

Can someone please tell me why this does not work (it throws up a type
mismatch):

Sub Cost_Update()

Dim dMitCost As Double

dMitCost = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
FmRiskCost.TextBox23.Value = dMitCost
End

I am trying to capture (up to) five values entered into textboxes on a form,
add them and then send the total value to another text box on the same form.
I can do this by replacing the CDbl with a Val, but the calculation then goes
haywire when lage numbers are inputted.

Is this a variation on the old thing of XL assuming that anything joined by
a '+' sign is a string not a number? If so, how do I get around it?

Hope this makes some sense!

TIA

Dave

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Confused by CDbl behaviour

Eduardo,

Still haven't been able to get it to work so I've just written it as a set
of If statements - really ugly (and inefficient I suspect) but it works

"Eduardo" wrote:

Hi Dave,
I am not an expert as well but some nice people has helped me a lot and the
code is working beautifully to me, there is only one difference and it is I
don't include the form name and I missed some Me in the totals, sorry, try
this
Try
If IsNumeric(Me.TextBox9.Value) _
And IsNumeric(Me.TextBox10.Value) _
And IsNumeric(Me.TextBox11.Value) _
And IsNumeric(Me.TextBox12.Value) _
And IsNumeric(Me.TextBox13.Value) Then

Me.dMitCost.value = (CDbl(Me.TextBox9.Value) +
CDbl_(Me.TextBox10.Value) + CDbl(Me.TextBox11.Value) +
CDbl_(Me.TextBox12.Value) + CDbl(Me.TextBox13.Value))_
Me.TextBox23.Value = Me.dMitCost.Value
End



"Risky Dave" wrote:

Office '07 under Vista

"Eduardo" wrote:

Hi Dave,
what version of excel are you using

"Risky Dave" wrote:

Eduardo,

Thanks for the quick response.

I'm not quite sure what you mean with this (I'm not a programmer - just
learnign this stuff as I go along).

If I insert another IF statement around the existing code as per your
posting, XL throws back an error about invalid use of "Me." If I remove the
Me, then the code simply skips past the line intended to capture the input,
ie. the IF statement is false so it is just ignored so I don't get the output
I need.

Obviously, I'm missing something here.

TIA

Dave

"Eduardo" wrote:

Try
If IsNumeric(Me.FmRiskCost.TextBox9.Value) _
And IsNumeric(Me.FmRiskCost.TextBox10.Value) _
And IsNumeric(Me.FmRiskCost.TextBox11.Value) _
And IsNumeric(Me.FmRiskCost.TextBox12.Value) _
And IsNumeric(Me.FmRiskCost.TextBox13.Value) Then

Me.dMitCost.value = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
Me.FmRiskCost.TextBox23.Value = Me.dMitCost.Value
End



"Risky Dave" wrote:

Hi,

Can someone please tell me why this does not work (it throws up a type
mismatch):

Sub Cost_Update()

Dim dMitCost As Double

dMitCost = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
FmRiskCost.TextBox23.Value = dMitCost
End

I am trying to capture (up to) five values entered into textboxes on a form,
add them and then send the total value to another text box on the same form.
I can do this by replacing the CDbl with a Val, but the calculation then goes
haywire when lage numbers are inputted.

Is this a variation on the old thing of XL assuming that anything joined by
a '+' sign is a string not a number? If so, how do I get around it?

Hope this makes some sense!

TIA

Dave

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Confused by CDbl behaviour

On Tue, 30 Dec 2008 08:20:05 -0800, Risky Dave
wrote:

Hi,

Can someone please tell me why this does not work (it throws up a type
mismatch):

Sub Cost_Update()

Dim dMitCost As Double

dMitCost = (CDbl(FmRiskCost.TextBox9.Value) +
CDbl_(FmRiskCost.TextBox10.Value) + CDbl(FmRiskCost.TextBox11.Value) +
CDbl_(FmRiskCost.TextBox12.Value) + CDbl(FmRiskCost.TextBox13.Value))_
FmRiskCost.TextBox23.Value = dMitCost
End

I am trying to capture (up to) five values entered into textboxes on a form,
add them and then send the total value to another text box on the same form.
I can do this by replacing the CDbl with a Val, but the calculation then goes
haywire when lage numbers are inputted.

Is this a variation on the old thing of XL assuming that anything joined by
a '+' sign is a string not a number? If so, how do I get around it?

Hope this makes some sense!

TIA

Dave


I would assume that one of the values is text that cannot be coerced to
represent a numeric value.
--ron
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
confused mdj0615 Excel Worksheet Functions 1 July 30th 09 03:33 AM
I'm Confused........................................ Jonathan Excel Programming 8 May 4th 05 12:37 PM
Sorry I am confused Desmond Excel Discussion (Misc queries) 7 April 24th 05 10:40 PM
dim a String A="2+3+5" A=cdbl(A)??? Andoni[_51_] Excel Programming 5 September 17th 04 02:37 AM
CDbl function snax500[_2_] Excel Programming 4 October 22nd 03 04:32 PM


All times are GMT +1. The time now is 02:44 AM.

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

About Us

"It's about Microsoft Excel"