vb.net - Checking if index is null and providing an error? -


i have following code:

 private sub button1_click(sender object, e eventargs) handles button1.click ' calculate button     if string.isnullorempty(textbox1.text)         msgbox("please enter value convert!")     end if      if currentindex = vbnull         msgbox("please select conversion!")     end if      select case currentindex         case 1             label2.text = textbox1.text & " celsius = " & math.round(((textbox1.text * 1.8) + 32), 2) & " fahrenheit"         case 2             label2.text = textbox1.text & " fahrenheit = " & math.round(((textbox1.text - 32) / 1.8), 2) & " celsius"         case 3             label2.text = textbox1.text & " kelvin = " & math.round((textbox1.text - 273.15), 2) & " celsius"         case 4             label2.text = textbox1.text & " celius = " & math.round((textbox1.text + 273.15), 2) & " kelvin"         case 5             label2.text = textbox1.text & " kelvin = " & math.round((((textbox1.text - 273.15) * 1.8) + 32), 2) & " fahrenheit"         case 6             label2.text = textbox1.text & " fahrenheit = " & math.round(((((textbox1.text - 32) * 5) / 9) + 273.15), 2) & " kelvin"         case 8             label2.text = textbox1.text & " miles p/h = " & math.round((textbox1.text * 1.609344), 2) & " kilometers p/h"         case 9             label2.text = textbox1.text & " kilometers p/h = " & math.round((textbox1.text / 1.609344), 2) & " miles p/h"         case 11             label2.text = textbox1.text & " kilograms = " & math.round((textbox1.text * 2.20462), 2) & " pounds"         case 12             label2.text = textbox1.text & " pounds = " & math.round((textbox1.text / 2.20462), 2) & " kilograms"         case 14             label2.text = textbox1.text & " meters = " & math.round((textbox1.text * 3.2808399), 2) & " feet"         case 15             label2.text = textbox1.text & " feet = " & math.round((textbox1.text / 3.2808399), 2) & " meters"     end select end sub 

as can see, have variable (currentindex) , have select case statement checking them against various conversions, problem lies in piece of code above this.

if currentindex = vbnull     msgbox("please select conversion!") end if 

i require spit error message out if index null, cannot work out way this. 0 cannot used first entry in index, , vbnull etc not seem work. can point me in right direction? thanks.

edit: how current index created:

dim currentindex integer 

and how assigned:

private sub listbox1_selectedindexchanged(byval sender object, byval e system.eventargs) handles listbox1.selectedindexchanged      ' selected index of item in list box.     currentindex = listbox1.findstring(currentitem) end sub 

i suggest using selectedindex instead.

in code:

    if listbox1.selectedindex = -1         msgbox("please select conversion!")     end if 

here reference property: http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selectedindex.aspx


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -