Results 1 to 4 of 4

Thread: [2005] Correct way of dealing with multiple options

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Location
    Silly Clone Valley CA
    Posts
    47

    [2005] Correct way of dealing with multiple options

    In my program I need to change the available controls based on what the user does, so I have three different things to determine control visibility and play event.

    for the play event here is a sample of what happens when a user clicks on play:

    Code:
    Private Sub BtnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPlay.Click, StationsList.DoubleClick, FavoritesList.DoubleClick
    
            If My.Settings.ShowFavorites = True Then
                If My.Settings.PlayType = True Then
                    If (Player1.playState = WMPPlayState.wmppsPlaying) Then
                        If Player1.currentMedia.sourceURL = FavoritesList.CurrentRow.Cells(1).Value Then
                            Player1.Ctlcontrols.pause()
                        Else
                            Player1.URL = FavoritesList.CurrentRow.Cells(1).Value
                        End If
                    Else
                        Player1.URL = FavoritesList.CurrentRow.Cells(1).Value
                    End If
                Else
                    If (Player1.playState = WMPPlayState.wmppsPlaying) Then
                        Player1.Ctlcontrols.pause()
                    Else
                        Player1.Ctlcontrols.play()
                    End If
                End If
            Else
    
            End If
            If My.Settings.PlayType = True Then
                If (Player1.playState = WMPPlayState.wmppsPlaying) Then
                    If Player1.currentMedia.sourceURL = StationsList.CurrentRow.Cells(1).Value Then
                        Player1.Ctlcontrols.pause()
                    Else
                        Player1.URL = StationsList.CurrentRow.Cells(1).Value
                    End If
                Else
                    Player1.URL = StationsList.CurrentRow.Cells(1).Value
                End If
            Else
                If (Player1.playState = WMPPlayState.wmppsPlaying) Then
                    Player1.Ctlcontrols.pause()
                Else
                    Player1.Ctlcontrols.play()
                End If
            End If
        End Sub
    I can't figure out how to handle this with a case statement unless I define each state individually, and if I was how would I? Is there some better way?

    Trying to read this code is very hard and it looks a little like spaghetti code. Maybe Fettucini code.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] Correct way of dealing with multiple options

    Does what you have work?

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2007
    Location
    Silly Clone Valley CA
    Posts
    47

    Re: [2005] Correct way of dealing with multiple options

    No it doesn't, well it partly works, it's too confusing to figure out what I'm doing wrong. I'm not familiar with all the new .net oop styles and I think this could work better if I create a "playtype" class where I handle each option individually. But I'm not sure exactly how to do it (not how to make a class, but handle each situation).

    Maybe an interface?

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

    Re: [2005] Correct way of dealing with multiple options

    You may find that using a Select Case statement is easier to manage if you have tons of if/elseif/else statements...

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