Trouble getting an array to display my minimum and maximum inputs in VB.net -
i working on application user inputs 10 integers array , clicks button display integers in ascending or descending order highest lowest, not working intended. when click button should sort them, nothing happens. can give insight? here current code.
function intinput() integer const intmax integer = 9 dim intarray(intmax) integer dim intcount integer 'loop counter intcount = 0 intmax 'run intcount through intmax 10 times intarray(intcount) = cint(inputbox("please enter integer: ")) 'input integers , store them array element next lstarray.items.clear() intcount = 0 intmax lstarray.items.add(intarray(intcount)) 'add integers list next return intarray(intcount) end function function inthighest() integer const intmax integer = 9 dim intarray(intmax) integer dim intcount integer 'loop counter dim inthigh integer inthigh = intarray(0) intcount = 1 (intarray.length - 1) if intarray(intcount) > inthigh inthigh = intarray(intcount) end if next return inthigh end function function intlow() integer const intmax integer = 9 dim intarray(intmax) integer dim intcount integer 'loop counter dim intlowest integer intlowest = intarray(9) intcount = 1 (intarray.length - 1) if intarray(intcount) < intlowest intlowest = intarray(intcount) end if next return intlowest end function private sub btninput_click(sender object, e eventargs) handles btninput.click intinput() end sub private sub btnclear_click(sender object, e eventargs) handles btnclear.click lstarray.items.clear() end sub private sub btndisplay_click(sender object, e eventargs) handles btndisplay.click inthighest() intlow() end sub end class
there easier way find minimum , maximum values in array, , sort values in array.
dim arrnum() integer = {3, 1, 2} 'create integer array dim minnum integer = arrnum.min 'get minimum value dim maxnum integer = arrnum.max 'get maximum value array.sort(arrnum) 'sort array
Comments
Post a Comment