Results 1 to 22 of 22

Thread: Pivate Sub Form_Load ( )

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Pivate Sub Form_Load ( )

    I am getting errors with the Private Sub Form_Load coding. Sometimes it says "Method or Data not found". And other times it gives errors about the compiling. Here is the coding I'm talking about.


    PrivateSub Form_Load ()
    MediaPlayer1.FileName = App.Path & "\TRACK4~1.MP3"
    MediaPlayer1.Play
    On Error GoTo Form_Load_Error

    MkDir App.Path & "\Pictures\"
    'Test
    'MsgBox "file folder created"

    Form_Load_Error:
    If Err.Number <> 0 Then
    'Test
    'MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Load of Form frmStart"
    'MsgBox "folder already exists"
    Exit Sub
    End If

    End Sub

    **
    I am very new to Visual Basic, and would like to get this code working right!!! I just thought of something else, how do I put a line between two parts of the code to make it look organized??

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Pivate Sub Form_Load ( )

    1. Welcome to the Forum.
    2. I want you to open this link and see how this control works:
    http://www.vbtutor.net/vb_sample/winmediaplayer.html
    3. If you still have problems, by all means, return and ask your questions.

    Sam

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    Hi. when my partner was helping me, we put in the media player to play a lyric once the form1 started up, and quit when you went to other forms. I installed VB6 in Win 10, and it works good. I do want to be able to have it work in the IDE, so I can change things if the need is there!! Thanks for assisting me!

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Pivate Sub Form_Load ( )

    Pretty easy. Just put the .URL equal to the path of your mp3 file in Form_Load (like you have it, only the WMP does not have a .PLAY....see the example of it I showed you....use .URL.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    When I run my app, the "Private Sub Form_Load ( )" is marked in yellow, and the FileName is marked in blue. A window pops out, States "Compile Error, "Method or data member not found". I have all of this app on an XP Desktop, and transfered the project.vbp to a USB stick. There is a line that was in the code, but I don't think it is in the right segment of the code.

    This is the other extra line....... Private Sub MediaPlayer1_DVDNotify(ByVal EventCode As Long, ByVal EventParam1 As Long, ByVal EventParam2 As Long)

    End Sub

    I hope this might help out. And thanks again!!!

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Pivate Sub Form_Load ( )

    Post your Form_Load code again (the new stuff).

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    Private Sub Form_Load()
    MediaPlayer1.FileName = App.Path & "\TRACK4~1.MP3"
    MediaPlayer1.Play
    On Error GoTo Form_Load_Error

    MkDir App.Path & "\Pictures\"
    'Test
    'MsgBox "file folder created"

    Form_Load_Error:
    If Err.Number <> 0 Then
    'Test
    'MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Load of Form frmStart"
    'MsgBox "folder already exists"
    Exit Sub
    End If

    End Sub

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Pivate Sub Form_Load ( )

    ARGH.....did you see my earlier post? WindowsMediaPlayer does not have a .FileName....USE MediaPlayer1.URL

    Did you go to that link I included? Very good tutorial on how to use the WindowsMediaPlayer.

    ....and, you have a lot of stuff in that code which makes NO sense at all.

  9. #9
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Pivate Sub Form_Load ( )

    Quote Originally Posted by SamOscarBrown View Post
    ARGH.....did you see my earlier post? WindowsMediaPlayer does not have a .FileName....USE MediaPlayer1.URL

    Did you go to that link I included? Very good tutorial on how to use the WindowsMediaPlayer.

    ....and, you have a lot of stuff in that code which makes NO sense at all.
    Depends on the version of Windows Media Player you're using.
    It looks like from the code he is using the earlier .ocx version as opposed to the current .dll version as those properties and methods apply to that media player. They don't have a .URL property in the earlier version, and you call the .Play method to start playing the song. They don't have play lists in the older version either.

    The earlier version also was just called Media Player, rather than Windows Media Player, and the control name in the code also reflects that.
    Last edited by passel; Feb 20th, 2018 at 08:15 PM.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    Thank you all for helping a newbie! I just want the media player to play just the one tune. I know that the code is not the best. How would one code it to have media player play just the one tune, when the form 1 starts, and it only plays during the form 1 start form, not in any of the other forms! This was back in 2002, and it is still ticking away in win 10.

  11. #11
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Pivate Sub Form_Load ( )

    Quote Originally Posted by passel View Post
    Depends on the version of Windows Media Player you're using.
    It looks like from the code he is using the earlier .ocx version as opposed to the current .dll version as those properties and methods apply to that media player. They don't have a .URL property in the earlier version, and you call the .Play method to start playing the song. They don't have play lists in the older version either.

    The earlier version also was just called Media Player, rather than Windows Media Player, and the control name in the code also reflects that.
    Thanks for the knowledge....never used the 'old one'.

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Pivate Sub Form_Load ( )

    If you get rid of ALL code in Form_Load, except

    Code:
    MediaPlayer1.FileName = App.Path & "\TRACK4~1.MP3"
    MediaPlayer1.Play
    What happens?

    IS the mp3 file, TRACK4~1.MP3, in the same path as your saved project? Not the best place to put it, but it should work.

  13. #13

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    i'll give it a try, and let you know, and thanks again!! Sam, can you tell me how to place those lines to seperate code? I did what you said for me to do. The Form Start came up, and some parts of the this form did not work.

    Will code work if no line seperates each code segment one another??
    Last edited by Dakota2; Feb 21st, 2018 at 10:22 AM.

  14. #14
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Pivate Sub Form_Load ( )

    Quote Originally Posted by Dakota2 View Post
    When I run my app, the "Private Sub Form_Load ( )" is marked in yellow, and the FileName is marked in blue. ...
    When you say the FileName is marked in blue, do you mean "\TRACK4~1.MP3" or do you mean "MediaPlayer1" is highlighted blue.
    I suspect you mean MediaPlayer1 is "marked in blue".
    That would mean the Media Player component is not registered, which is quite likely as you're trying to run on Win10.

    {edit}. In regards to the p.s. below, I now think you mean the property ".Filename" is highlighted in blue. That would be an indication of what I mention below in the p.s., that the missing MediaPlayer1 control has been replaced with a Picturebox so that the form can be displayed and ".Filename" is highlighted blue because a Picturebox doesn't have a Filename property. {end edit}

    You have to manually register the component, assuming you have a copy of the component version of the msdxm.ocx. I believe a runtime version is included in Win10, which is why your existing executable will run, but if you want to work in the IDE, you have to have a component version (a much larger file size, i.e. the runtime version might be 7K in size, the component version that provides a control for the IDE is probably around 820k).

    Because of the challenges to work with the old (i.e. 1999) mediaplayer component, I switched over to using the current Windows Media Player component myself. It does work a bit different so is slightly more of a challenge than the old Media Player (e.g. you don't have a media ended event, you have to receive a PlayStateChange event and look for the proper condition to recognize the media has finished playing), but you'll likely get more help using the newer component, and it should be available from your Project component menu now, without you having to register anything.

    You might want to take this opportunity to switch controls and get your application working with the Windows Media Control.

    p.s. I'm assuming you probably got different errors earlier on, and have saved the project since then.
    When the program couldn't resolve the component, it would have replaced it with a "place holder" component, i.e. a Picturebox.
    So, if you look at the list of controls on your form, you'll probably find that MediaPlayer1 is now a picturebox, so it doesn't have any of the methods that a MediaPlayer control would have.

    If I have a problem with controls at startup, that is one thing I make sure I don't do, i.e. try to run it or save it, because the IDE will have "patched" things to try to get it to the point where it could show you the form in the IDE. If you have autosave on and try to run it, it may have saved that slightly mangled version. Or if you save it, you saved the slightly mangled version.

    When you load it again, it will no longer complain about the missing control, because it has been replaced with a Picturebox, but the code won't work either because a picturebox will not likely be a valid substitute for the missing component if you have component specific code written. Another drawback is now the reference to the control in the project is also gone.

    If you get the component you need registered, then you have to go through some hoops, to remove the picturebox and add the missing component, possibly renaming it, and positioning it where it should be, etc...
    Last edited by passel; Feb 21st, 2018 at 11:20 AM.

  15. #15

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    Wow, passed!!! You really hit the nail on the head!! It now is a picturebox. And yes, there are different errors also, some are compile errors, but the one in yellow is "Private Sub Form_Load", and the "FileName " is blue. I don't understand the code like you. But it is interesting for sure. So do you think it can be fixed?

    Andre,

    There was also this line floating in my Form Start code, is this one no good also?

    Private Sub MediaPlayer1_DVDNotify(ByVal EventCode As Long, ByVal EventParam1 As Long, ByVal EventParam2 As Long)

    End Sub
    Last edited by Dakota2; Feb 21st, 2018 at 02:29 PM. Reason: orrections

  16. #16
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Pivate Sub Form_Load ( )

    Quote Originally Posted by Dakota2 View Post
    Wow, passed!!! You really hit the nail on the head!! It now is a picturebox. And yes, there are different errors also, some are compile errors, but the one in yellow is "Private Sub Form_Load", and the "FileName " is blue. I don't understand the code like you. But it is interesting for sure. So do you think it can be fixed?
    ...
    Yes, as I said if you have the correct version of msdxm.ocx and register it with the system and then replace the picturebox with the MediaPlayer control once you've added to your toolbox, you can probably get the code to work from the IDE.

    But that is a lot of things to get in the right place. Rather than get the existing mediaplayer code to work, I think I would comment out all the code that references the MediaPlayer and then add the Windows Media Player control to the form instead, which should be available from your list of components (near the bottom of the list) if you select the "Project" menu and then the "Add Components..." menu item.

    Once you have that control in place, you'll need to refer back to SamOscarBrown's post and start replacing the code you commented out with comparable code for the WMP control. You can probably get more help with using that control, updating your project to use it in place of the old Media Player control.

  17. #17

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    Well SamOscarBrown, I ticked windows media player, Microsoft control tning also. But how do i get them on my Form Start_Form?? I want to attempt it on my own, but i might need a bit of help, if possible! I would appreciate it. Ok. I got the windows media player on my Form Start Form. I can't seem to find the Micorsoft Control one. But I will keep trying!
    Last edited by Dakota2; Feb 22nd, 2018 at 07:49 PM.

  18. #18

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    I got l the media player control on the form start, but I can't seem to find the Microsoft Common Dialog Contol 6.0. I ticked it in the Components window, just as I did for the media player. Where would it be, or is it a hidden thing??

  19. #19
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Pivate Sub Form_Load ( )

    The Common Dialog Control will appear in your list, just like the Windows Media Player does (along with the 'Common' controls like Command Button, Listbox, TextBox, etc. You can either drag the icon for the Command Dialog Control to your form, or double-click it.

    It looks like the attached icon...

  20. #20
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Pivate Sub Form_Load ( )

    Since you already know the song you want to play, you probably don't really need the Common Dialog Control anyway. You would ignore that code and just pull the pieces you need for your situation.

  21. #21
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Pivate Sub Form_Load ( )

    Dakota2---(in the Sioux language, your moniker means 'friend'. So, here's some friendly advice for you...please obtain (buy, borrow, download (but don't steal) at least one book on VB6...available on-line all over the place (try to get one with a CD(also, if you buy a book from a bookstore, make sure the CD is present.)) You will be ever so thankful you did this...will save you countless hours as you go about attempting to learn the (old) VB6 language. I like 'VB6's Little Black Book' available on line (no cd though...it's all in electrons). It a START until you can obtain a good book.

    Your friend,
    Sam

  22. #22

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    10

    Re: Pivate Sub Form_Load ( )

    Thanks SamOscarBrown, I'm not sure, but i might have a VB5 book, that was my son's, but I wasn't interested in it then. This is before we put together this app together, which was finished in 2002. I am going to try what you had posted!! Thanks, and I may have to come back here, good to know your welcomed to this forum, if I'm stuck!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width