vb.net - Is there an alternative method to using 15 If statements? -
i have 15 items in combobox
, when user selects item want present different in textbox
.
at moment have:
if cb_dropdown.selectedindex = 0 rtb_sql.text = "update access set accessdesc = 'less 5' accessid < '5'" else if cb_dropdown.selectedindex = 1 rtb_sql.text = "update access set accessdesc = 'more 5' accessid > '5' , < '10' " else if cb_dropdown.selectedindex = 2 rtb_sql.text = ""
etc....
is there nicer , more methodical way approach looks quite scruffy?
yes, called select.
select case cb_dropdown.selectedindex case 0 4 rtb_sql.text = "update access set accessdesc = 'less 5' accessid < '5'" case 5 rtb_sql.text = [...] case else rtb_sql.text = [...] end case
although in case think looking < (less than) , > (greater than).
if cb_dropdown.selectedindex < 5 rtb_sql.text = "update access set accessdesc = 'less 5' accessid < '5'" elseif cb_dropdown.selectedindex < 10 rtb_sql.text = "update access set accessdesc = 'more 5' accessid > '5' , < '10' " end if
not sure trying though. maybe if explain in more detail can provide better answer. let me take wild guess:
dim n integer = cb_dropdown.selectedindex * 5 rtb_sql.text = "update access set accessdesc = 'more " + n + "' accessid > '" + n + "' , < '" + (n+6) + "' "
this give following result based on selectedindex:
- 0 = 1 including 5
- 1 = 6 including 10
- etc...
if want shift down 1 (include 0 , not 5 in first batch) change > >= , 6 5.
Comments
Post a Comment