i'm pretty new vb.net i'm not familiar how public functions called 1 form another. when hovering on "myinifile" , "initgpib" in class, frmreadtemp, error message - not declared. may inaccessible due protection level. however, function , sub public in class.
public class frmreadtemp private sub cmdrun_click(sender object, e eventargs) handles cmdrun.click dim err_code ecode = ecode.err_noner myinifile() err_code = initgpib() end sub end class public class powersupply_setup #region "variable declarations" dim myinifile inifile public instrinfo new arraylist public myiniobj iniobj withevents myps ipowersupply withevents mytestsystem new testsystemobj(4) #end region public sub loadinifile() dim tenable string 'power supply myiniobj.ps_addr.primaryaddress = myinifile.getinteger("gpib_instruments", "powersupply_addr", 6) myiniobj.ps_addr.cominterface = 1 myiniobj.ps_type = myinifile.getstring("gpib_instruments", "powersupply_type", "hp6632").toupper tenable = myinifile.getstring("gpib_instruments", "powersupply_available", "no") myiniobj.ps_available = iif(tenable.toupper.trim.startswith("no"), false, true) 'myiniobj.ps_available = iif((myinifile.getstring("gpib_instruments", "powersupply_available", 0)) = "0", false, true) myiniobj.ps_port = myinifile.getinteger("gpib_instruments", "powersupply_port", 1) myiniobj.ps_ov_offset = val(myinifile.getinteger("gpib_instruments", "powersupply_overvoltage_offset", "3.0")) myiniobj.ps_current_limit = val(myinifile.getinteger("gpib_instruments", "powersupply_current_limit", "3.0")) end sub public function initgpib() swierr.ecode dim err_code ecode = ecode.err_none if (instrinfo.count = 0) 'init power supply if (err_code = ecode.err_none , myiniobj.ps_available) dim iinfo2(1) string if (myiniobj.ps_type.toupper.contains("hp6632")) myps = new hp6632(myiniobj.ps_addr) err_code = myps.errcode elseif (myiniobj.ps_type.toupper.contains("e3631")) myps = new e3631a(myiniobj.ps_addr) err_code = myps.errcode elseif (myiniobj.ps_type.toupper.contains("e66311")) myps = new e66311b(myiniobj.ps_addr) err_code = myps.errcode elseif (myiniobj.ps_type.toupper.contains("e66319")) myps = new e66311b(myiniobj.ps_addr) err_code = myps.errcode elseif (myiniobj.ps_type.toupper.contains("scpi")) myps = new scpi_ps(myiniobj.ps_addr) err_code = myps.errcode else myps = nothing err_code = ecode.err_inst_ps_not_supported end if if (err_code = ecode.err_none) iinfo2(0) = myps.instrumentname iinfo2(1) = myps.gpibaddress.primaryaddress myps.selectport = me.myiniobj.ps_port instrinfo.add(iinfo2) myps.overvoltageoffset = myiniobj.ps_ov_offset myps.setpwroff() end if if (err_code = ecode.err_inst_gpib_search) err_code = ecode.err_inst_missing_pwrsupply else 'create object set availability false myps = new e3631a() end if me.mytestsystem.instrument.ps = myps end if return err_code end function end class
the variable myinifile , method initgpib indeed public, accessible outside of powersupply_setup class. however, since members of class, must referenced via object of class. instance:
dim mysetup new powersupply_setup() err_code = mysetup.initgpib() since instance members (not shared), must create instance (an object) of class , can access them via object. if create multiple objects of class, have multiple copies of members.
if ever need 1 copy of members, , don't want have create object use them, can alternatively decare them shared members of class:
public class powersupply_setup public shared sub loadinifile() ' ... end sub ' ... end class then can access them directly via class name:
err_code = powersupply_setup.initgpib() personally, recommend against doing so, unless necessary, because leads global state can dangerous. if want go down road, though, , don't want have use class name access members, put them in module rather in class.
Comments
Post a Comment