Forum Moderators: open

Message Too Old, No Replies

Select Case

         

aax123

9:08 pm on Dec 1, 2005 (gmt 0)

10+ Year Member



I was trying to create a Select case statement and was wondering if you think this would work the way I have it? New to Case statements and was just wondering..

'** Use this
For l = 0 To ds3.Tables(0).Rows.Count - 1
Dim typeCode = ds3.Tables(0).Rows(l).Item("type_code").ToString()

Dim column_name = ds3.Tables(0).Rows(l).Item("column_name")

Select case column_name
Case vm.year
sb.Append("<td><input type=text size=4 style='background-color: #FFFFFF' onfocus=showPreview('" & vid & "') onblur=hidePreview('" & vid & "') onpropertychange=UpdateLinerLength('" & vid & "') class=copy name=liner_Year4_" & vid & " value=""" & Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_year").ToString()) & """>")
sb.Append("<input type=hidden size=4 style='background-color: #FFFFFF' class=copy name=liner_Year2_" & vid & " value=""" & Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_year").ToString()) & """></td>")
linerAd += Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_year").ToString())
linerAd += " "
Case vm.make
sb.Append("<div id='linerMake' style='visibility: ;'><td style='display: ;'><input type=text size=15 style='background-color: #FFFFFF' onfocus=showPreview('" & vid & "') onblur=hidePreview('" & vid & "') onpropertychange=UpdateLinerLength('" & vid & "') class=copy name=liner_Make_" & vid & " value=""" & Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_make").ToString()) & """></td></div>")
linerAd += Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_make").ToString())
linerAd += " "
Case vm.model
sb.Append("<div id='linerModel' style='visibility: ;'><td style='display: ;'><input type=text size=15 style='background-color: #FFFFFF' onfocus=showPreview('" & vid & "') onblur=hidePreview('" & vid & "') onpropertychange=UpdateLinerLength('" & vid & "') class=copy name=liner_Model_" & vid & " value=""" & Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_model").ToString()) & """></td></div>")
linerAd += Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_model").ToString())
linerAd += " "
End Select
Next

'** Instead of this

For l = 0 To ds3.Tables(0).Rows.Count - 1
Dim typeCode = ds3.Tables(0).Rows(l).Item("type_code").ToString()

If ds3.Tables(0).Rows(l).Item("column_name") = "vm.year" Then
sb.Append("<td><input type=text size=4 style='background-color: #FFFFFF' onfocus=showPreview('" & vid & "') onblur=hidePreview('" & vid & "') onpropertychange=checkLinerLength('" & vid & "') class=copy name=liner_Year4_" & vid & " value=""" & Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_year").ToString()) & """>")
sb.Append("<input type=hidden size=4 style='background-color: #FFFFFF' class=copy name=liner_Year2_" & vid & " value=""" & Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_year").ToString()) & """></td>")
linerAd += Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_year").ToString())
linerAd += " "
End If
If ds3.Tables(0).Rows(l).Item("column_name") = "vm.make" Then
sb.Append("<div id='linerMake' style='visibility: ;'><td style='display: ;'><input type=text size=15 style='background-color: #FFFFFF' onfocus=showPreview('" & vid & "') onblur=hidePreview('" & vid & "') onpropertychange=checkLinerLength('" & vid & "') class=copy name=liner_Make_" & vid & " value=""" & Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_make").ToString()) & """></td></div>")
linerAd += Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_make").ToString())
linerAd += " "
End If
If ds3.Tables(0).Rows(l).Item("column_name") = "vm.model" Then
sb.Append("<div id='linerModel' style='visibility: ;'><td style='display: ;'><input type=text size=15 style='background-color: #FFFFFF' onfocus=showPreview('" & vid & "') onblur=hidePreview('" & vid & "') onpropertychange=checkLinerLength('" & vid & "') class=copy name=liner_Model_" & vid & " value=""" & Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_model").ToString()) & """></td></div>")
linerAd += Server.HtmlEncode(ds.Tables(0).Rows(i).Item("liner_model").ToString())
linerAd += " "
End If
Next

Easy_Coder

9:17 pm on Dec 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As long as this stuff (vm.year, vm.make, vm.model) has an underlying value you should be good. Consider adding a Case Else to trap unintended values.

You should get a minor performance boost too. With the if statements everything gets evaluated. With a select case either the direct match or the default fire the others do not fire.

bigtoga

12:38 pm on Dec 22, 2005 (gmt 0)

10+ Year Member



Just a tip for future newsgroup posts, only post the necessary code. When I look at a post with that much code I'm more apt to close the page than read on.

Also, for big code samples on ASP.NET, why post them here and ask for advice? Find an ASP.NET-specific board and ask. You'll get a faster response every time

aspdaddy

1:15 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could rewrite the second example using else-if and it will perform the same as SELECT CASE.

But there is almost certainly a much easier way to do that using without SELECT or IF, probably a single line of code, try accessing the items by index instead of name.

Easy_Coder

6:05 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



for big code samples on ASP.NET, why post them here and ask for advice? Find an ASP.NET-specific board and ask

baloney... aax123 did post in the asp and .net forum here. Your response has no value only critique. That's never appreciated.

mattglet

6:15 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Find an ASP.NET-specific board and ask

Check out those 5 big black words at the top of this page. Looks pretty specific to me.

[edited by: mattglet at 6:17 pm (utc) on Dec. 22, 2005]