请老师帮我实现一个功能!
我想做个收音机,由于连接的网址比较多,而窗体的菜单编辑器最多只能添加250个项目,多了就不行,我想用列表框来读取ini文件,然后点击列表框里的项目就可以在WindowsMediaPlayer1里播出,请各位老师帮我改改,首先我在这里祝福大家五一节快乐!谢谢大家了
收音机.rar
(1.98 KB)
Private Type 数据结构类型 名字 As String URL As String End Type Dim dat() As 数据结构类型 Private Sub Form_Load() Dim file As String Dim fj() As String Dim i As String Dim fr As Long Dim k As Boolean Dim j As Long fr = FreeFile file = "1.ini" Open file For Input As fr Do While Not EOF(fr) Line Input #fr, i If i = "[网络广播电台]" Then '只有读到头,才算结束 k = True End If If UCase(i) = "END" Then '读到 end ,算文件结束 Exit Do End If If k Then '只有读到头后,才开始分析网址 If InStr(1, i, "=") > 0 Then j = j + 1 '首次要计数 End If End If Loop Close #fr ReDim dat(j) j = 0 Open file For Input As fr Do While Not EOF(fr) Line Input #fr, i If i = "[网络广播电台]" Then '只有读到头,才算结束 k = True End If If UCase(i) = "END" Then '读到 end ,算文件结束 Exit Do End If If k Then '只有读到头后,才开始分析网址 If InStr(1, i, "=") > 0 Then fj = Split(i, "=") dat(j).名字 = fj(0) dat(j).URL = fj(1) List1.AddItem dat(j).名字 j = j + 1 '首次要计数 End If End If Loop Close #fr Me.Caption = "网络收音机" List1.ToolTipText = "双击换台" End Sub Private Sub List1_DblClick() WindowsMediaPlayer1.URL = dat(List1.ListIndex).URL Me.Caption = "网络收音机--" & dat(List1.ListIndex).名字 End Sub
Dim sAdress() As String Private Sub Form_Load() Dim sTmpStr As String sTmpStr = TextGetByFile(App.Path + "\1.ini") Dim sNewStr() As String Dim sLanMu() As String sNewStr = Split(sTmpStr, vbCrLf) For i = 0 To UBound(sNewStr) - 1 sLanMu = Split(sNewStr(i), "=") If UBound(sLanMu) = 1 Then List1.AddItem sLanMu(0) ReDim Preserve sAdress(List1.ListCount - 1) sAdress(List1.ListCount - 1) = sLanMu(1) End If Next End Sub Public Function TextGetByFile(ByVal pFileName As String) As String Dim tOutText As String Dim tFileNumber As Integer Dim tBytes() As Byte tFileNumber = FreeFile Open pFileName For Binary As #tFileNumber If CBool(LOF(tFileNumber)) Then ReDim tBytes(LOF(tFileNumber) - 1) Get tFileNumber, 1, tBytes() tOutText = StrConv(tBytes, vbUnicode) Else MsgBox "警告:文件" & pFileName & "是空的!", vbOKOnly, "文件无内容" End If Close #tFileNumber TextGetByFile = tOutText End Function Private Sub List1_DblClick() '双击列表框换台 WindowsMediaPlayer1.URL = sAdress(List1.ListIndex) End Sub