By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,490 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,490 IT Pros & Developers. It's quick & easy.

Type mismatch error

P: 68
I'm getting an error 13 - Type Mismatch with the following code:

Expand|Select|Wrap|Line Numbers
  1. MsgBox "Total trip miles = " & lngTripMiles & _
  2.                 " and the status miles total = " _
  3.                 & (lngLoadedMiles + lngEmptyMiles + lngBobtailMiles) & ".", "Trip calculation error"
All the variables are defined as Long. What am I doing wrong?
Thanks
Dec 12 '13 #1

✓ answered by zmbd

that is because "Trip calculation error"
is in the position for the button/icon/msgtype

IMHO: It's usually better to build your string first and then insert it into the function.

In anycase, add another comma before the "Trip...", and I prefer to specify the button type; thus, you now have:
Expand|Select|Wrap|Line Numbers
  1. MsgBox "Total trip miles = " & lngTripMiles & _
  2.                 " and the status miles total = " _
  3.                 & (lngLoadedMiles + lngEmptyMiles + lngBobtailMiles) & ".", vbOKOnly, "Trip calculation error"
  4.  
IMHO Ideally you would
Expand|Select|Wrap|Line Numbers
  1. (...)dim strMsg as String
  2. strMsg = "Total trip miles = " & lngTripMiles & _
  3.                 " and the status miles total = " _
  4.                 & (lngLoadedMiles + lngEmptyMiles + lngBobtailMiles) & "."
  5. '
  6. MsgBox strMsg,vbOKOnly,"Trip calculation error"
  7. (...)
This way if you need to you can debug.print the string.

Share this Question
Share on Google+
3 Replies


zmbd
Expert Mod 5K+
P: 5,287
that is because "Trip calculation error"
is in the position for the button/icon/msgtype

IMHO: It's usually better to build your string first and then insert it into the function.

In anycase, add another comma before the "Trip...", and I prefer to specify the button type; thus, you now have:
Expand|Select|Wrap|Line Numbers
  1. MsgBox "Total trip miles = " & lngTripMiles & _
  2.                 " and the status miles total = " _
  3.                 & (lngLoadedMiles + lngEmptyMiles + lngBobtailMiles) & ".", vbOKOnly, "Trip calculation error"
  4.  
IMHO Ideally you would
Expand|Select|Wrap|Line Numbers
  1. (...)dim strMsg as String
  2. strMsg = "Total trip miles = " & lngTripMiles & _
  3.                 " and the status miles total = " _
  4.                 & (lngLoadedMiles + lngEmptyMiles + lngBobtailMiles) & "."
  5. '
  6. MsgBox strMsg,vbOKOnly,"Trip calculation error"
  7. (...)
This way if you need to you can debug.print the string.
Dec 12 '13 #2

P: 68
Thanks! I wasn't paying close enough attention to the prompts when I created it.
Dec 12 '13 #3

zmbd
Expert Mod 5K+
P: 5,287
if I had a dollar... (^_^)
Dec 12 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.