|
-
Sep 22nd, 2007, 02:41 PM
#1
Thread Starter
Member
[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.
-
Sep 24th, 2007, 07:37 AM
#2
Re: [2005] Correct way of dealing with multiple options
-
Sep 24th, 2007, 12:51 PM
#3
Thread Starter
Member
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?
-
Sep 24th, 2007, 01:02 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|