Results 1 to 8 of 8

Thread: [RESOLVED] [2008] Phunny Problem?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    3

    Resolved [RESOLVED] [2008] Phunny Problem?

    Wells, I'm working on a program for work. I'll give a quick lo-down and then get to my problem.

    I work at a FM/Online Radio station (Music Director) and, since I'm currently also doing a BA Engineering / IT degree at uni, I was asked if I would be able to make a Vista Sidebar Gadget and an executable program.. both have pretty much the same purpose - connect to the online stream. The gadget is done and happily available, although I haven't released the latest version

    Ok. Not focusing on the gadget as it doesn't employ any VB..
    The stand-alone program which I've started is 90% complete. Everything required is there. It plays the stream, and grabs the currently playing track info. As well as a few other nifty abilities.
    This is where the problem lies. I've decided to include a Recently Played window.
    Ex. The user is happily listening to the sexy choons, the tracks change and each time, I keep the previous 5 tracks' info as well as the currently playing track.
    The user clicks the Recently Played link, up pops the window, and.. well, it is suppose to be displaying the 5 recently played tracks and now playing..

    Hmmm.. but it's not.

    The way I coded this is:
    The application checks our server every 'update'. This is based on the user setting (I've coded Options). If the currently displayed info (application side) if different to the currently playing info (our server side) then it will call this:
    Code:
    'IN MAIN.FORM
        Public Sub getCompare()
            Try
                If tempInfo1 IsNot RecentlyPlayed.nowPlaying = True Then
                    tempInfo1 = RecentlyPlayed.nowPlaying
                    RecentlyPlayed.nowPlaying = artistInfo.ToUpper & " - " & titleInfo.ToUpper
    
                    tempInfo2 = RecentlyPlayed.firstPreviousSong
                    RecentlyPlayed.firstPreviousSong = tempInfo1
    
                    tempInfo3 = RecentlyPlayed.secondPreviousSong
                    RecentlyPlayed.secondPreviousSong = tempInfo2
    
                    tempInfo4 = RecentlyPlayed.thirdPreviousSong
                    RecentlyPlayed.thirdPreviousSong = tempInfo3
    
                    tempInfo5 = RecentlyPlayed.fourthPreviousSong
                    RecentlyPlayed.fourthPreviousSong = tempInfo4
    
                    tempInfo6 = RecentlyPlayed.firstPreviousSong
                    RecentlyPlayed.fithPreviousSong = tempInfo5
    
                    RecentlyPlayed.finishCompare()
                End If
            Catch
                    'yeah yeah blah
            End Try
        End Sub
    The TRY is in-case the return string is NULL, we all know what happens there.. sigh.

    You'll notice I have tempInfoX. I presume that everything in that part of code is correct!?
    The tempInfoX variables are changed to save the 'data of the previous song' .. thus allowing for the next info to be used as the one above?
    Hopefully this is making sense.. it's 11:40pm..

    So, a new track is played, and the variables are changed.. you'll notice it is calling RecentlyPlayed.finishCompare()
    This is because, after much frustration of it not working, I coded the hell out of it and tried anything.. it's working better than it did without this sub.
    NB: RecentlyPlayed is another form.

    Code:
    'IN RECENTLYPLAYED.FORM
    Public Class RecentlyPlayed
    
        Public nowPlaying As String = "No Information Available.."
        Public firstPreviousSong As String = "No Information Available.."
        Public secondPreviousSong As String = "No Information Available.."
        Public thirdPreviousSong As String = "No Information Available.."
        Public fourthPreviousSong As String = "No Information Available.."
        Public fithPreviousSong As String = "No Information Available.."
    
        Private Sub RecentlyPlayed_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Main.getCompare()
            finishCompare()
        End Sub
    
        Public Sub finishCompare()
            nowPlaying = Main.lbl_ArtistInfo.Text & " - " & Main.lbl_TitleInfo.Text
            lbl_NowPlaying.Text = nowPlaying
            lbl_Previous1.Text = firstPreviousSong
            lbl_Previous2.Text = secondPreviousSong
            lbl_Previous3.Text = thirdPreviousSong
            lbl_Previous4.Text = fourthPreviousSong
            lbl_Previous5.Text = fithPreviousSong
        End Sub
    That's it all..
    I have no idea why it isn't working.

    When I first open Recently Played - Now Playing, FirstPrevious and SecondPrevious are the currently playing songs.. then I close it and only NP and FirstPrevious are the same..
    But if I keep the window open, it works fine.. then I close it, re-open and its still working.. however! If I have closed the window and then the track changes, I open Recently Played and it's back to only displaying Now Playing and FirstPrevious (where FirstPrevious is the same as Now Playing)

    Screenie of the app being a wang..


    Screenie of the app actually working.. (this is when I keep the window open and the tracks change and stuff like..)



    Well! That was a huge first post.
    Hopefully someone has enough time to read it all, and hopefully my jaber is understandable
    lol..

    If you are confused, which I'm presuming you potentially maybe, then please ask - I'll try and be 'un-tired' for my response and make it a reasonable reply

    Also!
    I was reading about PING. I would like to include a PING metre showing the response time between our server and the user.. just to make it look fancy.
    I had a look, and boy was it heaps of code!!
    Is there a short way of pinging a www server and getting the response time to use??
    Don't want any in-between bits :P

    Thanks!
    Clancy Bird.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Phunny Problem?

    I do notice the little typo in the first snippet. The one where you use FirstPrevious song instead of FifthPrevious, but that is not related to the main problem.

    The actual answer is not clear from what you have posted, but there is certainly a likely issue: Each form is hardcoded to a specific instance. In both cases, it looks like the instance is the horrid default instance of the form. I really detest the default instance, but it might work....assuming that you are actually USING the default instance, and it is not clear that you are.

    I would suggest adding a class that does nothing but acquire the previous songs, hold them (probably in a queue object rather than five variables), and offer them up on demand. The forms would interact with a single global instance of this class.

    However, if you prefer the present situation, show the code you used to show any form other than the startup form.
    My usual boring signature: Nothing

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Phunny Problem?

    I agree with Shaggy... Your problem seems to be causing by using default form instances. Also using a queue to hold the recently played songs is much cleaner way to manage the list.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    3

    Re: [2008] Phunny Problem?

    Oh, lol. Yes I see that typo too - thanks :P

    Well, when the user clicks the Recently Played link, I use:
    Code:
    recentlyPlayed.Show()
    As to the Default Instance? Not quite sure of this horrid thing?

    I'm up for anything cleaner. My code is already really messy.. I just kept adding stuff and yeah. I dunno what to take out anymore haha

    I'll try the class. How would I go about using the queue? My VB class was pretty.. basic should I say haha. I've had to research alot of material to get the application this far. We never covered queues in the first course.

    Thinking about using the one class for the two forms to interact with seems alot easier. Makes me happy to think I might be able to finish.. lol
    Wonder why I didn't think of it earlier.. it all makes sense!

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Phunny Problem?

    The Queue object was only added with framework version 2.0, so your class had to be really recent to have even known about it. It's also a bit obscure, as there are other ways to do the same thing, though not quite as cleanly. The class can be found in the collections.generics (or generics.Collections, I forget the order) namespace, as it is really Queue (of T).

    A Queue is kind of like....uh...a hose? Ok, that metaphor really sucks. You Enqueue items, and dequeue them. They are like a list, but you stick items in with Enqueue, and pull out the oldest item with dequeue, so if you have a queue of 5 songs, and as you play each song you Enqueue the song, then if you Dequeue a song, it will be the oldest song in the queue. That's pretty much what you are trying to do. The only question I would have (I have only used the Queue object once, and I never looked into this) is what happens when you try to put item 6 into a Queue of 5 items. If the fifth item is dropped off the end, then that is exactly what you are doing. If the Queue just grows, or if the 6th item can't be added until an item is Dequeued, then a bit of extra work would be needed to check the size, and if it is 5, Dequeue one before you Enqueue the next one (doggone is that a hard word to spell with all those e's and u's).

    As for the default instances, they were also added with .NET 2005. Prior to that, if you had a form called recentyPlayed, then to create an instance you had to do something like this:

    Public rP as New recentlyPlayed

    Once the default instances were added, you could still do that, but there was already an instance of recentlyPlayed created when the program started, and it was called recentlyPlayed. As far as I am concerned, that just confuses people (it was done because VB6 works like that, so it would be familiar to VB6 programmers). The confusion comes from blurring the line between a class type and an instance of a class. You can't do that with anything other than forms. For all other classes you have to have an instance, but now, forms are 'special'. Might be convenient for people, but it sows confusion, as well.

    At this point, I've forgotten the question.

    Oh yes. After that rant about default instances, are you using a default instance, or is the recentlyPlayed in your code snippet, an instance? It may not matter, because if you use a third class to supply data for the other two (and receive data, I guess), then the problem you are having currently will be replaced by whatever problem comes next.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    3

    Re: [2008] Phunny Problem?

    Ok, sorry I didn't reply. Was away.

    Hmm. Well, ok. The RecentlyPlayed is a different form from Main.Form.. it is not within the Main.Form code snippet if that's what you asked? So I'm presuming it is a default instance since it is not in the code snippet?
    Other than that, I have no idea.

    But! I have fixed the problem..
    Not using the Queue object either.
    To explain..
    I have the Main.Form load. The 'Track Info' is gathered and is stored in the RecentlyPlayed.Form as the label text.. yes I know.
    Ok. So, it used to be that once you closed the RecentlyPlayed window, it would close. But, I've caught CloseOnX event and cancelled it to keep RecentlyPlayed open. I did this because I saw that (when it wasn't working) if I kept the RecentlyPlayed window open it would work fine. If you had the window closed, and the song changed, it would be a wang and go all wacky.

    I really hope that this solution isn't hugely problematic. I can see that my coding and code principles make the application a bit more heavy than it should.

    So, it works. Everything is complete and functioning.

    I've submitted it, as I feel it is ready for release 1.
    In the mean time, I'll be cleaning up the code base to try and make it more efficient, and I'll also try and include a ping network status indicator (three green bars for strong connection, two green bars for adequate, and one red bar for poor)
    I've seen the coding for Ping.. and boy is it quite lengthy. I'll grab the code and try and cut out the not-so-useful parts which I can see wont be needed for what I need.

    Thanks guys!!

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Phunny Problem?

    Quote Originally Posted by Shaggy Hiker
    The Queue object was only added with framework version 2.0, so your class had to be really recent to have even known about it. It's also a bit obscure, as there are other ways to do the same thing, though not quite as cleanly. The class can be found in the collections.generics (or generics.Collections, I forget the order) namespace, as it is really Queue (of T).
    Just one point to note. Just as the ArrayList has existed since .NET 1.0 and was superseded by the List(Of T) in .NET 2.0, so too the Queue has existed since .NET 1.0 and was superseded by the Queue(Of T) in .NET 2.0.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [RESOLVED] [2008] Phunny Problem?

    Nice. Though just as I detested Arraylist in .NET 1.0, I probably would have detested Queue in .NET 1.0.
    My usual boring signature: Nothing

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