I have this string for example
when i run this i get a run time error for type mismatch![]()
dim junk1 as string dim junk2 as long junk1 = "" junk2=clng(junk1)
any ideas? is it because the string is empty?
I have this string for example
when i run this i get a run time error for type mismatch![]()
dim junk1 as string dim junk2 as long junk1 = "" junk2=clng(junk1)
any ideas? is it because the string is empty?
Last edited by welchs101; 06-05-2011 at 06:13 AM.
Hi welchs101,
The short answer is "you can't do that". You are trying to change a string into a number. You should get the same answer if you wanted to know the numeric value of "Bob". You have a Type of Variable mismatch.
The VBA editor or runtime has no idea how to deal with this and gives you back an error.
One test is worth a thousand opinions.
Click the * Add Reputation below to say thanks.
Use Val, it is a super robust conversion function
Val("") = 0
Val("smith") = 0
Val("123cat") = 123
Val("3.14159")=3.14259
Val("-23.8") = -23.8
Val("5/23/2001") = 5
If you definatly need a data type long
use CLng(Val(someString)) to buffer against errors.
Last edited by mikerickson; 06-04-2011 at 11:19 PM.
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
thanks for the info guys! very helpful.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks