I solved the problem by storing the item position of frmSetup.Lstsongs in a variable:
vb Code:
Private Sub Form_Load()
'Integer index of the song to be played
s = 0
End Sub
Sending the variable to the function:
vb Code:
Private Sub mnuPlay_Click()
'If cancel then close the program
'Else choose and play a song
Music1.ShowOpen
frmSetup.Lstsongs.AddItem Music1.FileName
Repeat:
x = MsgBox("Do you want to add more songs?", vbYesNo)
If x = vbYes Then
Music1.ShowOpen
frmSetup.Songopt(1).Value = True
frmSetup.Lstsongs.AddItem Music1.FileName
GoTo Repeat
ElseIf x = vbNo Then
play (s)
End If
End Sub
The "play" function:
vb Code:
Private Function play(s)
frmSetup.Lstsongs.Selected(s) = True
MediaPlayer1.URL = frmSetup.Lstsongs.Text
End Function
Finally checking inside a timer to check if the player had stopped, there was more than one song in the list and whether or not s was greater than the value of the number of songs in the listbox. If all those conditions were met then I would add 1 to the value of s and send the new value back to the play function.
vb Code:
Private Sub tmrDuration_Timer()
If MediaPlayer1.playState = wmppsStopped And frmSetup.Songopt(1).Value = True And Not s > frmSetup.Lstsongs.ListCount Then
'Play the next song in the list
s = s + 1
play (s)
End If
End Sub