vb.net - ListBoxes in Visual Basic -
i have assignment user enter numbers list box. when user done entering numbers, compute average , standard deviation.(our professor not want use built in standard deviation functions) program have context menu , these guidelines creating menu: must create subroutine called setmenu. used enable , disable context menu based on contents of list. when list empty,clear disabled. when list has @ least 1 number in it,clear enabled. when nothing selected, delete item disabled. when selected, delete item enabled. need help, creating subroutine.
here code:
option strict on public class form1 private sub addbtn_click(byval sender system.object, byval e system.eventargs) handles addbtn.click listbox.items.add(inputbox.text) inputbox.text = "" end sub private sub computebtn_click(byval sender system.object, byval e system.eventargs) handles computebtn.click dim sum, x, number, numbersum, subtractednum integer dim average, insideroot, squaredroot double x = 0 listbox.items.count - 1 listbox.selectedindex = x number = integer.parse(listbox.selecteditem.tostring) sum = sum + number average = sum / listbox.items.count next averagelbl.text = average.tostring x = 0 listbox.items.count - 1 listbox.selectedindex = x number = integer.parse(listbox.selecteditem.tostring) subtractednum = cint((number - average) ^ 2) numbersum = numbersum + subtractednum insideroot = (numbersum / (listbox.items.count - 1)) squaredroot = insideroot ^ (1 / 2) next deviationlbl.text = squaredroot.tostring("n2") end sub private sub clearmenu_click(byval sender system.object, byval e system.eventargs) handles clearmenu.click clearmenu.enabled = false setmenu() listbox.items.clear() end sub private sub deletemenu_click(byval sender system.object, byval e system.eventargs) handles deletemenu.click listbox.items.remove(listbox.selecteditem) end sub private sub inputbox_textchanged(byval sender system.object, byval e system.eventargs) handles inputbox.textchanged if isnumeric(inputbox.text) , inputbox.text <> "" addbtn.enabled = true else addbtn.enabled = false end if end sub private sub setmenu() 'need here end sub
end class
how about:
private sub togglecontextmenuitems() cleartoolstripmenuitem.visible = (listbox1.items.count > 0) deletetoolstripmenuitem.visible = (listbox1.selectedindex > -1) end sub
then call method when needed.
Comments
Post a Comment