vb.net - How do I enable a Calculate button in visual basic when i need 2 radio buttons selected and text in a text box -
alright i'm writing program converts celsius kelvin , fahrenheit. default have calculate button disabled until user puts in temperature , selects radio button corresponding temperature , temperature being converted to. having great deal of issues trying enable calculate button. i'm not sure since nested if statements in calculate area not working. here have far:
option strict on option explicit on public class fmmain 'yes understand program easy break private sub btncalc_click(sender object, e eventargs) handles btncalc.click try dim num1 decimal dim num2 decimal dim answer decimal dim flag integer dim flag2 integer dim t1 string 'this i'm trying enable calculate button if txtnum1.text <> "" if radc1.checked or radf1.checked or radk1.checked if radc2.checked or radf2.checked or radk2.checked btncalc.enabled = true btncalc.focus() end if end if end if 'this block of code makes sure input entered numerical , not break program. if txtnum1.text <> "" 'i won't need line once can calculate button enabled , disabled @ if isnumeric(txtnum1.text) if radf1.checked , radc2.checked flag = 1 elseif radf1.checked , radk2.checked flag = 2 elseif radc1.checked , radf2.checked flag = 3 elseif radc1.checked , radk2.checked flag = 4 elseif radk1.checked , radf2.checked flag = 5 else flag = 6 end if if radf2.checked flag2 = 1 elseif radc2.checked flag2 = 2 else flag2 = 3 end if answer = modcalc.temperature(num1, flag, num2) t1 = modcalc.temp(flag2) messagebox.show("the answer is: " & answer.tostring & " " & t1 & ".", "this message box", messageboxbuttons.ok, messageboxicon.information) else messagebox.show("please enter number", "bad input error", messageboxbuttons.ok, messageboxicon.error) end if else messagebox.show("please enter number", "bad input error", messageboxbuttons.ok, messageboxicon.error) end if catch ex exception end try end sub 'this ensures user can't click same radio button on both sides private sub radf1_checkedchanged(sender object, e eventargs) handles radf1.checkedchanged if radf1.checked radf2.checked = false radf2.enabled = false radc2.enabled = true radk2.enabled = true end if end sub private sub radc1_checkedchanged(sender object, e eventargs) handles radc1.checkedchanged if radc1.checked radc2.checked = false radc2.enabled = false radf2.enabled = true radk2.enabled = true end if end sub private sub radk1_checkedchanged(sender object, e eventargs) handles radk1.checkedchanged if radk1.checked radk2.checked = false radk2.enabled = false radf2.enabled = true radc2.enabled = true end if end sub end class
one-liner:
btncalc.enabled = txtnum1.textlength > 0 andalso (radc1.checked orelse radf1.checked orelse radk1.checked) andalso (radc2.checked orelse radf2.checked orelse radk2.checked)
that said, how can enabling btncalc
in own click
event handler? need when state of other controls changes. click
event can't raised if button
isn't enabled.
Comments
Post a Comment