Problem with Left Function

Error: Mismatched Type

Tried using the code here:

Code
  1. 134 If Len(track) > TrackChar Then
  2. 135 Track = Left(Track, TrackChar)
  3. 136 DesktopX.Object("widget_itunes_track").Text = Track


The code keeps coming back as an error though

Type Mismatch: "Left"
Line: 135
Code: (not available)

What could be causing this error? I checked the VBScript website at Microsoft and I am using the function correctly.

Any ideas?
6,314 views 4 replies
Reply #1 Top
I'd think it's an invalid argument being passed on to Left. Debug the values that's being passed on. Try something like: Script.MsgBox "Len: " & Len(Track) & vbcrlf & "TrackChar: " & TrackChar. If TrackChar returns a number outside the length of "Track" or a non-numeric value you have to go through your preceding code.
Reply #2 Top
Thankyou thomassen for your reply. The problem seems to be with the Left function itself. TrackChar returns a numeric value and I've tried hard-coding the number as well with no results. The funny thing is both the Right and Mid function work fine.

Any other ideas???
Reply #3 Top
Hmm sometimes I had to do this:

var=var-0

then var is now a numeric value and not a string. No idea why it does that, however!
Reply #4 Top
var=var-0

Or use var=CInt(var) (assuming you are using an Integer) This ensures you get an Integer object. Use CSng or CDbl if you need a floating number.

Sranshaft:
So the values passed on to the Left function is 0 or more and less than the length of the Track string? Left will return an error if the length agrument is less than 0 or higher than the numbers of characters in the string being processed.