Jump to content

Using Logic With Hex (or Dec?)


Recommended Posts

Hi All -

I'm new to DLL usage and interpreting the way data is returned to them. I'm doing what I believe is a fairly simple evaluation but after many tries I just can't get this to work. I was hoping someone with a little more experience in this arena could see what I'm doing wrong.

This uses the ITunes COM interface. Basically all I am trying to do with this small snippet of script is to determine if the user has any files selected (highlighted) in Itunes. According to the ITunes documentation, ".selectedTracks" returns "null" if there is nothing selected. I've tried using Hex, Dec, and a number of other permutations with no success.

$iTunesApp = ObjCreate("iTunes.application")

$numTracks = 0

$selectedTracks = $iTunesApp.SelectedTracks

MsgBox(0,"",Hex($selectedTracks,8))

if $selectedTracks <> Hex(00,8) Then  
   $numTracks = $selectedTracks.Count
EndIf

While $numTracks <> 0 
    
    $currentTrack = $selectedTracks.Item($numTracks)
    $currentTrackName = $currentTrack.Name
    
    MsgBox(0,"","Current Track is " & $currentTrackName)

    $numTracks = $numTracks - 1

WEnd

The reason I'm using this logic is because if there is nothing selected in the Itunes application, I get an error when the program tries to use ".Count". While the above logic statement shows me comparing the result against "Hex(00,8)", I've tried using 'hex' on $selectedTracks, comparing it against "" (empty quotes indicating null, not sure if it interprets it that way or not).

Any help would be appreciated!

Link to comment
Share on other sites

Instead of trying to compare it to NULL, try checking to see if it is an object. SelectedTracks returns a collection of tracks if it is sucessful.

$oITunes = ObjCreate("iTunes.Application")
If @error Then
    Msgbox (0,"iTunes","Error Getting an active iTunes Object. Error code: " & Hex (@error, 8))
    Exit
EndIf
    
$seltracks = $oITunes.SelectedTracks

If IsObj ($seltracks) Then
    MsgBox (0, "count", $seltracks.Count)
Else
    MsgBox (0, "none", "no selected tracks")
EndIf
Link to comment
Share on other sites

Instead of trying to compare it to NULL, try checking to see if it is an object. SelectedTracks returns a collection of tracks if it is sucessful.

Excellent! The thought of using IsObj didn't even cross my mind.. This solves my issue!

Once again, thanks for your help! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...