Problem with Left Function

Error: Mismatched Type

Sunday, May 15, 2005 by Sranshaft | Discussion: DesktopX

Tried using the code here:

[code]

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

[/code]

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?
thomassen
Reply #1 Sunday, May 15, 2005 11:15 AM
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.
Sranshaft
Reply #2 Sunday, May 15, 2005 8:21 PM
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???
XX
Reply #3 Sunday, May 15, 2005 11:15 PM
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!
thomassen
Reply #4 Monday, May 16, 2005 11:22 AM
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.

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01