Wat doe ik fout? [vb6]

Status
Niet open voor verdere reacties.

Semafoor

Gebruiker
Lid geworden
29 aug 2007
Berichten
129
Hallo,

Ik ben bezig met een applicatie te maken. Ik heb er een MRu aan toe gevoegd. Het enigste probleem is dat er wanneer je op een mru item klikt niks gebeurd.. tenminste.. Niet wat ik wil dat er gebeurt.

Dit is de code die ik gebruikt heb.
Ik dat als je op een mru item klikt label1.caption het woord krijgt. dim : lbl
en dat windowsmediaplayer1.url de url krijgt dim: player


Code:
Option Explicit

Private Const MaxMRU = 2  'Maximum number of MRUs in list (-1 for no limit)
Private Const NotFound = -1   'Indicates a duplicate entry was not found
Private Const NoMRUs = -1     'Indicates no MRUs are currently defined

Private MRUCount As Long      'Maintains a count of MRUs defined

Private Sub Form_Load()
   ' Initialize the count of MRUs
   MRUCount = NoMRUs
   
   ' Call sub to retrieve the MRU filenames
   GetMRUFileList
End Sub

Private Sub Form_Unload(Cancel As Integer)
   ' Call sub to save the MRU filenames
   SaveMRUFileList
End Sub

Private Sub Image1_Click()
Dim player As String
Dim lbl As String
Label1.Caption = "3fm"
player = WindowsMediaPlayer1.URL
lbl = Label1.Caption
WindowsMediaPlayer1.URL = "http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a=.asx"
AddMRUItem lbl & " - " & player
End Sub

Private Sub Image2_Click()
Dim player As String
Dim lbl As String
Label1.Caption = "538 40"
player = WindowsMediaPlayer1.URL
lbl = Label1.Caption
WindowsMediaPlayer1.URL = "http://www.klikradio.nl/asx/redirector.php?index=10"
AddMRUItem lbl & " - " & player
End Sub

Private Sub mnuMRU_Click(Index As Integer)
   Dim player As String
    Dim lbl As String
   ' Call sub to reorder the MRU list
   ReorderMRUList mnuMRU(Index).Caption, CLng(Index)
   WindowsMediaPlayer1.URL = player
   Label1.Caption = lbl
End Sub

Private Sub mnuOpen_Click()
   ' Show the file open common dialog
   Me.CommonDialog1.ShowOpen
   
   ' Call sub to add this file as an MRU
   AddMRUItem Me.CommonDialog1.FileName
End Sub

Private Sub AddMRUItem(NewItem As String)
   Dim result As Long
      
   ' Call sub to check for duplicates
   result = CheckForDuplicateMRU(NewItem)
   
   ' Handle case if duplicate found
   If result <> NotFound Then
      ' Call sub to reorder MRU list
      ReorderMRUList NewItem, result
   Else
      ' Call sub to add new item to MRU menu
      AddMenuElement NewItem
   End If
End Sub

Private Function CheckForDuplicateMRU(ByVal NewItem As String) As Long
   Dim i As Long
   
   ' Uppercase newitem for string comparisons
   NewItem = UCase$(NewItem)
   
   ' Check all existing MRUs for duplicate
   For i = 0 To MRUCount
      If UCase$(Me.mnuMRU(i).Caption) = NewItem Then
         ' Duplicate found, return the location of the duplicate
         CheckForDuplicateMRU = i
         
         ' Stop searching
         Exit Function
      End If
   Next i
   
   ' No duplicate found, so return -1
   CheckForDuplicateMRU = -1
End Function

Private Sub mnuQuit_Click()
   ' Close the program
   Unload Me
End Sub

Private Sub AddMenuElement(NewItem As String)
   Dim i As Long
   
   ' Check that we will not exceed maximum MRUs
   If (MRUCount < (MaxMRU - 1)) Or (MaxMRU = -1) Then
      'Increment the menu count
      MRUCount = MRUCount + 1
      
      ' Check if this is the first item
      If MRUCount <> 0 Then
         ' Add a new element to the menu
         Load mnuMRU(MRUCount)
      End If
      
      ' Make new element visible
      mnuMRU(MRUCount).Visible = True
   End If
   
   ' Shift items to maintain most recent to least recent
   For i = (MRUCount) To 1 Step -1
      ' Set the captions
      mnuMRU(i).Caption = mnuMRU(i - 1).Caption
   Next i
   
   ' Set caption for new item
   mnuMRU(0).Caption = NewItem
End Sub

Private Sub ReorderMRUList(DuplicateMRU As String, DuplicateLocation As Long)
   Dim i As Long
   
   ' Move entries previously "more recent" than the
   ' duplicate down one in the MRU list
   For i = DuplicateLocation To 1 Step -1
      mnuMRU(i).Caption = mnuMRU(i - 1).Caption
   Next i
   
   ' Set caption of newitem
   mnuMRU(0).Caption = DuplicateMRU
End Sub

Private Sub GetMRUFileList()
   Dim i As Long           'Loop control variable
   Dim result As String    'Name of MRU from registry
   
   ' Loop through all entries
   Do
      ' Retrieve entry from registry
      result = GetSetting(App.Title, "MRUFiles", Trim$(CStr(i)), "")
      
      ' Check if a value was returned
      If result <> "" Then
         ' Call sub to additem to MRU list
         AddMRUItem result
      End If
      
      ' Increment counter
      i = i + 1
   Loop Until (result = "")
End Sub

Private Sub SaveMRUFileList()
   Dim i As Long           ' Loop control variable
   
   ' Loop through all MRU
   For i = 0 To MRUCount
      ' Write MRU to registry with key as it's position in list
      SaveSetting App.Title, "MRUFiles", Trim$(CStr(i)), mnuMRU(i).Caption
   Next i
End Sub

Als je op een van de images klikt krijg je wel een mru item maar als je daar op klik stopt de player en krijgt label1 geen tekst.

Wat doe ik fout of is er een betere manier?

Met vriendelijke groet

Stefan
 
Laatst bewerkt:
Lijkt mij dat in je code de volgorde niet helemaal juist is:
Code:
player = WindowsMediaPlayer1.URL
lbl = Label1.Caption
WindowsMediaPlayer1.URL = "http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a=.asx"
AddMRUItem lbl & " - " & player

Je geeft aan dat de variabele 'player' dezelfde waarde moet hebben als de eigenschap 'WindowsMediaPlayer1.Url' en vervolgens geef je pas aan wat die eigenschap voor een waarde moet hebben. Dan is de variabele 'player' natuurlijk niet up-to-date...

Volgens mij moet het dus zijn:
Code:
WindowsMediaPlayer1.URL = "http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a=.asx"
player = WindowsMediaPlayer1.URL
lbl = Label1.Caption
AddMRUItem lbl & " - " & player
 
Dank je daar was ik ook nog mee an het worstelen..

Maar wanneer je op een mru item klikt wordt nog steeds de url niet afgespeeld..

Code:
Private Sub mnuMRU_Click(Index As Integer)
   Dim player As String
    Dim lbl As String
   ' Call sub to reorder the MRU list
   ReorderMRUList mnuMRU(Index).Caption, CLng(Index)
   WindowsMediaPlayer1.URL = player
   Label1.Caption = lbl
End Sub

Klopt dit wel?

Al bedankt..
 
Laatst bewerkt:
Maar wat doet deze code nou eigenlijk?
Code:
Private Sub mnuMRU_Click(Index As Integer)
    Dim player As String
    Dim lbl As String
   ' Call sub to reorder the MRU list
   ReorderMRUList mnuMRU(Index).Caption, CLng(Index)
   WindowsMediaPlayer1.URL = player
   Label1.Caption = lbl
End Sub

De variabele player bevat geen enkele waarde ("") en krijgt die verder op in de code ook niet. WindowsMediaPlayer1.URL bevat dus ook "" (niets dus). Het enige wat je tussendoor doet is de MRUList opnieuw ordenen. Maar daar schiet je verder niets mee op.

Je zou dus iets moeten opnemen in de trent van:
Code:
Private Sub mnuMRU_Click(Index As Integer)
    Dim player As String
    Dim lbl As String
  
   player = mnuMRU(Index).Caption

   ' Call sub to reorder the MRU list
   ReorderMRUList mnuMRU(Index).Caption, CLng(Index)
  
   WindowsMediaPlayer1.URL = player
   Label1.Caption = lbl
End Sub
 
Ook lbl heeft trouwens ook geen waarde (en die moet waarschijnlijk de naam krijgen van het liedje). Toch? :shocked:
 
naam v an het radiostation...

Dank je ik zal het eens uitproberen

[edit] Het wekt niet.. de mediaplayer krijgt nu als url : "3fm - http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a=.asx"

hoe kan dat splitsen of moet ik dit bij
Code:
AddMRUItem lbl & " - " & player
gedaan worden?
 
Laatst bewerkt:
Welke waarde komt waar vandaan? En hoe ziet een normale streamwaarde eruit?
 
Ik denk dat ik het al heb opgelost.. Met een If en een rename van de caption.
ik zal de source nog wel posten
 
Normaal ziet de stream er uit als: http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a=3fm.asx

Ik zou alleen "3fm" opslaan in de MRUlist. De rest plak je ervoor en erna:
Code:
Private Sub mnuMRU_Click(Index As Integer)
    Dim strPrefix as string
    Dim strPostfix as string
    Dim strPlayer As String
    Dim strLabel As String

    strPrefix = "http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a="
    strPrefix = ".asx"

   ' Call sub to reorder the MRU list
   ReorderMRUList mnuMRU(Index).Caption, CLng(Index)

   strLabel = mnuMRU(Index).Caption
   strPLayer = strPrefix & strLabel & strPostfix
   WindowsMediaPlayer1.URL = strPlayer
   Label1.Caption = strLabel
End Sub
 
Maar omdat niet alle streams met http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a= beginnen is dit helaas geen optie..

Ik heb het volgende gedaan..

Code:
Option Explicit

Private Const MaxMRU = 2  'Maximum number of MRUs in list (-1 for no limit)
Private Const NotFound = -1   'Indicates a duplicate entry was not found
Private Const NoMRUs = -1     'Indicates no MRUs are currently defined

Private MRUCount As Long      'Maintains a count of MRUs defined

Private Sub Form_Load()
   ' Initialize the count of MRUs
   MRUCount = NoMRUs
   
   ' Call sub to retrieve the MRU filenames
   GetMRUFileList
End Sub

Private Sub Form_Unload(Cancel As Integer)
   ' Call sub to save the MRU filenames
   SaveMRUFileList
End Sub

Private Sub Image1_Click()
Dim player As String
Dim lbl As String
Label1.Caption = "3fm"
WindowsMediaPlayer1.URL = "http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a=.asx"
player = WindowsMediaPlayer1.URL
lbl = Label1.Caption
AddMRUItem player
 mnuMRU(0).Caption = "3FM"

End Sub

Private Sub Image2_Click()
Dim player As String
Dim lbl As String
Label1.Caption = "538 40"
WindowsMediaPlayer1.URL = "http://www.klikradio.nl/asx/redirector.php?index=10"
player = WindowsMediaPlayer1.URL
lbl = Label1.Caption
AddMRUItem player
 mnuMRU(0).Caption = "538 40"

End Sub

Private Sub mnuMRU_Click(Index As Integer)
    Dim player As String
    Dim lbl As String
  
   player = mnuMRU(Index).Caption
   
   If player = "538 40" Then
   Label1.Caption = "538 40"
   WindowsMediaPlayer1.URL = "http://www.klikradio.nl/asx/redirector.php?index=10"
   mnuMRU(0).Caption = "538 40"
  
   ElseIf player = "3FM" Then
   Label1.Caption = "3FM"
   WindowsMediaPlayer1.URL = "http://switch.streamgate.nl/cgi-bin/streamswitch?streamid=46&a=.asx"
   mnuMRU(0).Caption = "3FM"
   Else
   Label1.Caption = "Niet in het systeem"
   End If

   ' Call sub to reorder the MRU list
   ReorderMRUList mnuMRU(Index).Caption, CLng(Index)
   
   

End Sub

Private Sub AddMRUItem(NewItem As String)
   
   Dim result As Long
      
   ' Call sub to check for duplicates
   result = CheckForDuplicateMRU(NewItem)
   
   ' Handle case if duplicate found
   If result <> NotFound Then
      ' Call sub to reorder MRU list
      ReorderMRUList NewItem, result
   Else
      ' Call sub to add new item to MRU menu
      AddMenuElement NewItem
   End If
End Sub


Private Function CheckForDuplicateMRU(ByVal NewItem As String) As Long
   Dim i As Long
   
   ' Uppercase newitem for string comparisons
   NewItem = UCase$(NewItem)
   
   ' Check all existing MRUs for duplicate
   For i = 0 To MRUCount
      If UCase$(Me.mnuMRU(i).Caption) = NewItem Then
         ' Duplicate found, return the location of the duplicate
         CheckForDuplicateMRU = i
         
         ' Stop searching
         Exit Function
      End If
   Next i
   
   ' No duplicate found, so return -1
   CheckForDuplicateMRU = -1
End Function

Private Sub mnuQuit_Click()
   ' Close the program
   Unload Me
End Sub

Private Sub AddMenuElement(NewItem As String)
   Dim i As Long
   
   ' Check that we will not exceed maximum MRUs
   If (MRUCount < (MaxMRU - 1)) Or (MaxMRU = -1) Then
      'Increment the menu count
      MRUCount = MRUCount + 1
      
      ' Check if this is the first item
      If MRUCount <> 0 Then
         ' Add a new element to the menu
         Load mnuMRU(MRUCount)
      End If
      
      ' Make new element visible
      mnuMRU(MRUCount).Visible = True
   End If
   
   ' Shift items to maintain most recent to least recent
   For i = (MRUCount) To 1 Step -1
      ' Set the captions
      mnuMRU(i).Caption = mnuMRU(i - 1).Caption
   Next i
   
   ' Set caption for new item
   mnuMRU(0).Caption = NewItem
End Sub

Private Sub ReorderMRUList(DuplicateMRU As String, DuplicateLocation As Long)
   Dim i As Long
   
   ' Move entries previously "more recent" than the
   ' duplicate down one in the MRU list
   For i = DuplicateLocation To 1 Step -1
      mnuMRU(i).Caption = mnuMRU(i - 1).Caption
   Next i
   
   ' Set caption of newitem
   mnuMRU(0).Caption = DuplicateMRU
End Sub

Private Sub GetMRUFileList()
   Dim i As Long           'Loop control variable
   Dim result As String    'Name of MRU from registry
   
   ' Loop through all entries
   Do
      ' Retrieve entry from registry
      result = GetSetting(App.Title, "MRUFiles", Trim$(CStr(i)), "")
      
      ' Check if a value was returned
      If result <> "" Then
         ' Call sub to additem to MRU list
         AddMRUItem result
      End If
      
      ' Increment counter
      i = i + 1
   Loop Until (result = "")
End Sub

Private Sub SaveMRUFileList()
   Dim i As Long           ' Loop control variable
   
   ' Loop through all MRU
   For i = 0 To MRUCount
      ' Write MRU to registry with key as it's position in list
      SaveSetting App.Title, "MRUFiles", Trim$(CStr(i)), mnuMRU(i).Caption
   Next i
End Sub

mnuMRU(0).Caption = "538 40" Maakt bij het klikken op het station van het recent geopent bestand een tekst

Vervolgens wordt bij het klikken op een MRU Item door if een andere url naar wmp gestuurd..

Ik hoop dat iemand hier iets aan heeft!

Stefan
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan