vb.net - Function call from Arraylist element not working -


i trying function class assignment work program hits specific line in question dies off , nothing after line execute. program not lock up, current execution path dies.

i have tried running debugging same happens. once hit link should call function object stored in arraylist element break point @ actual function should called not hit , nothing further happens.

public structure appliances      ' create new appliance object     public sub new(name string, pusage double)         aname = name         apusage = pusage     end sub      ' create new washer object     public sub new(name string, pusage double, wusage double)         aname = name         apusage = pusage         awusage = wusage     end sub      ' functions     public function getaname()         return aname     end function      public function getapusage()         return apusage     end function      public function getawusage()         return awusage     end function      dim aname string ' appliance name     dim apusage double ' appliane power usage     dim awusage double ' appliance water usage  end structure  ...  public class form1  ...     dim applist new arraylist() ' create arraylist appliance objects     public apptemp appliances ' store appliance objects until can added arraylist  ...     private function getappinfo()         getappinfo = nothing          while finstream.peek() <> -1              s = finstream.readline() ' line file , set s              dim words string() = s.split(new char() {","c}) ' split line contents along commas , set parts words              words(0) = words(0).replace("_", " ") ' reaplce underscores spaces              if (words.count = 3) ' if words contains washer appliance                 apptemp = new appliances(words(0), double.parse(words(1)), double.parse(words(2)))                 applist.add(apptemp)              else ' other appliances                 apptemp = new appliances(words(0), double.parse(words(1)))                 applist.add(apptemp)              end if          loop     end function      private function setusage(name string)         setusage = nothing          ' find appliance         = 0 applist.count             if (name = applist(i).getaname())                 if (name = "washer")                     s = applist(i).getwusage() ' !!!this line execution dies at, nothing after line processed , function call not completed                     txtbgph.text = s                 end if                  msgbox("test 1")                 exit              elseif (i = applist.count)                 msgbox("appliance not found")             end if         next     end function  end class 

use list(of x) instead of arraylist if going insert 1 type:

dim applist new list(of appliances) 

and recommend declare temp var inside methods unless necessary. anyway, in case don't need it, can add var in way:

applist.add(new appliances(words(0), double.parse(words(1)))) 

with use (using lists) won't need use arraylistobj.item(i).method() , can use common way:

s = applist(i).getwusage() 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -