vb.net - Value of type '1-dimensional array of String' cannot be converted to '1-dimensional array of Integer' because 'String' is not derived from 'Integer' -
i getting error while trying use linear search name entered user array. here when declare array , input.
public const size_array = 9 public sub cmdstart_click(sender object, e eventargs) handles cmdstart.click dim myarray(size_array) string dim index integer public sub cmdstart_click(sender object, e eventargs) handles cmdstart.click dim count integer = 0 me.index = 0 size_array myarray(index) = inputbox("enter name, enter name") count = count + 1 next if count = 10 lblinstructions.visible = false cmdstart.visible = false lblinstructions2.visible = true txtsearch.visible = true lbloutput.visible = true cmdsearch.visible = true end if end sub
here use linear search.
public sub cmdsearch_click(sender object, e eventargs) handles cmdsearch.click dim found boolean dim name string name = txtsearch.text found = linearsearch(myarray, val(name)) if found lbloutput.text = name & " found @ cell " & index else lbloutput.text = name & " not found" end if end sub
and here linear search function
public function linearsearch(byval list() integer, byval searchvalue integer) boolean dim found boolean = false dim index integer while found = false , index <= ubound(list) if list(index) = searchvalue found = true else index += 1 end if end while return found end function
myarray
string
array, method linearsearch
expects 2 arguments: integer
array , integer
. assume require array search of type string
, , search value of type string
my vb.net rusty, here untested code linear search.
public function linearsearch(byval list() string, byval searchvalue string) boolean each item string in list if item = searchvalue return true end if next return false end function
Comments
Post a Comment