vendredi 26 décembre 2014

vb.net simplify if statement

I have a rather large If Statement:



If Node1.IsSelected Then
CrumbBar1.SelectedItem = HomeNode
'Main Week Views
ElseIf Node2.IsSelected Then
CrumbBar1.SelectedItem = wk1
ElseIf Node3.IsSelected Then
CrumbBar1.SelectedItem = wk2
ElseIf Node4.IsSelected Then
CrumbBar1.SelectedItem = wk3
ElseIf Node5.IsSelected Then
CrumbBar1.SelectedItem = wk4
'Week 1
ElseIf Node6.IsSelected Then
CrumbBar1.SelectedItem = mon1
ElseIf Node7.IsSelected Then
CrumbBar1.SelectedItem = tue1
ElseIf Node8.IsSelected Then
CrumbBar1.SelectedItem = wed1
ElseIf Node9.IsSelected Then
CrumbBar1.SelectedItem = thu1
ElseIf Node10.IsSelected Then
CrumbBar1.SelectedItem = fri1
'Week 2
ElseIf Node11.IsSelected Then
CrumbBar1.SelectedItem = mon2
ElseIf Node12.IsSelected Then
CrumbBar1.SelectedItem = tue2
ElseIf Node13.IsSelected Then
CrumbBar1.SelectedItem = wed2
ElseIf Node14.IsSelected Then
CrumbBar1.SelectedItem = thu2
ElseIf Node15.IsSelected Then
CrumbBar1.SelectedItem = fri2
'Week 3
ElseIf Node16.IsSelected Then
CrumbBar1.SelectedItem = mon3
ElseIf Node17.IsSelected Then
CrumbBar1.SelectedItem = tue3
ElseIf Node18.IsSelected Then
CrumbBar1.SelectedItem = wed3
ElseIf Node19.IsSelected Then
CrumbBar1.SelectedItem = thu3
ElseIf Node20.IsSelected Then
CrumbBar1.SelectedItem = fri3
'Week 4
ElseIf Node21.IsSelected Then
CrumbBar1.SelectedItem = mon2
ElseIf Node22.IsSelected Then
CrumbBar1.SelectedItem = tue2
ElseIf Node23.IsSelected Then
CrumbBar1.SelectedItem = wed2
ElseIf Node24.IsSelected Then
CrumbBar1.SelectedItem = thu2
ElseIf Node25.IsSelected Then
CrumbBar1.SelectedItem = fri2
Else
CrumbBar1.SelectedItem = HomeNode
End If


I know about Select Case Statements, but can this If statement be simplified using one? I was taught in College while using Delphi that Case Selection only worked with single Characters and integers, is this the same across all/most languages?


To reassure people I will be renaming all of the Nodes and CrumbBar1 to something more meaningful, they're just temporary names.


Aucun commentaire:

Enregistrer un commentaire