OH DEAR LORD I am loosing my mind!

# Thread: OH DEAR LORD I am loosing my mind!

1. Member
Join Date
Dec 1969
Posts
51

## OH DEAR LORD I am loosing my mind!

Ok please tell me WHY I am getting this message.<BR><BR>First this is what I am doing.<BR><BR>I have a var - lets call it var1<BR><BR>When i assign certaint hings to it like this it is fine:<BR><BR>var1 = var2 + "-" + var3 + "-"<BR><BR>This works fine - but for some reason whenever I try to assign it a specifc var that I created using a recordset I get a Type Mismatch error.<BR><BR>I have no idea why but this is what I mean.<BR><BR>var5 is created by doing a recordset count <BR><BR>As long as I do this it is fine:<BR><BR>var1 = var5<BR><BR>BUT If I do this:<BR><BR>var1 = var2 + var5 <BR><BR>then i get the error. I have no idea why because both var2 and var5 are numbers. ?????<BR><BR>PLEASE PLEASE tell me what could be causing this.

2. Senior Member
Join Date
Dec 1969
Posts
5,104

## RE: OH DEAR LORD I am loosing my mind!

Try var1 = CLng(var2) + CLng(var5)<BR><BR>If that still gives you an error (on that line), try moving them to individual lines and then adding them:<BR>var2 = CLng(var2)<BR>var5 = CLng(var5)<BR>var1 = var2 + var5<BR><BR>That might help you narrow down your error.<BR><BR>As for your original string concatenation, you shouldn&#039;t use the plus (+), you should use the ampersand (&). Pluses should be used only when doing arthimetic.<BR><BR>-Doug

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## Tie it up!

Don&#039;t let it run loose!<BR><BR>Oh...you meant *losing* your mind....<BR><BR>&#060;snicker /&#062;<BR><BR>&nbsp; &nbsp; var1 = var2 + "-" + var3 + "-"<BR><BR>Use & to concatenate strings! Never never never use + when working with strings in VBScript. *Sometimes* it works, but when it doesn&#039;t...<BR><BR>&nbsp; &nbsp; var1 = var2 + var5 <BR>&nbsp; &nbsp; both var2 and var5 are numbers. <BR><BR>Are you *sure*? Try this:<BR><BR>&nbsp; &nbsp; Response.Write "TypeName(var2) is " & TypeName(var2) & "&#060;P&#062;"<BR>&nbsp; &nbsp; Response.Write "TypeName(var5) is " & TypeName(var5) & "&#060;P&#062;"<BR><BR>Betcha a quarter that at least one of those is not a number. Hmmm??<BR><BR><BR>

4. Member
Join Date
Dec 1969
Posts
51

## RE: OH DEAR LORD I am loosing my mind!

AH the plus was the problem. Thanks man!

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Great minds...

...run in the same gutter.<BR><BR>But I said that already today.<BR><BR>No, wait! I said "grated minds" before. Heh. Either way.<BR><BR>

6. Member
Join Date
Dec 1969
Posts
51

## RE: Tie it up!

Yea I just found that out. The sad thing is I knew that - I am just tired and completely missed it :-(

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## On second thought...

What happens if his var2 contains 3.14159265 and his var5 contains 2.718281828?<BR><BR>CLNG just *might* be a mistake in that case.<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
5,104

## RE: On second thought...

Bill, you are correct. Great minds are great minds.<BR><BR>I haven&#039;t brushed up on VBScripts usage of numeric types. Would CDBL be a better choice?<BR><BR>I guess I should pull one of the books of the shelf at home and look that up...<BR><BR>-Doug

9. Senior Member
Join Date
Dec 1969
Posts
96,118