|
-
Jul 14th, 2015, 01:16 PM
#1
Thread Starter
Member
Function/Sub not declared . It may be inaccessible due to its protection level
Hi, I'm pretty new with vb.net so I'm not completely familiar with how public functions are called from one form to another. When hovering over "myIniFile" and "initGPIB" in the class, frmReadTemp, I get the error message - not declared. It may be inaccessible due to its protection level. However, that function and sub is Public in another class.
Imports ATE2014.swiErr
Code:
Public Class frmReadTemp
Private Sub cmdRun_Click(sender As Object, e As EventArgs) Handles cmdRun.Click
Dim err_code As eCode = eCode.ERR_NONEr
myInifile()
err_code = initGPIB()
End Sub
End Class
Imports ATE2014.swiErr
Code:
Public Class PowerSupply_setup
#Region "Variable Declarations"
Dim myIniFile As IniFile
Public instrInfo As New ArrayList
Public myiniObj As iniObj
WithEvents myPS As IPowerSupply
WithEvents myTestSystem As New testSystemObj(4)
#End Region
Public Sub loadIniFile()
Dim tenable As 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() As swiErr.eCode
Dim err_code As eCode = eCode.ERR_NONE
If (instrInfo.Count = 0) Then
'init Power Supply
If (err_code = eCode.ERR_NONE And myiniObj.ps_available) Then
Dim iInfo2(1) As String
If (myiniObj.ps_type.ToUpper.Contains("HP6632")) Then
myPS = New HP6632(myiniObj.ps_addr)
err_code = myPS.ErrCode
ElseIf (myiniObj.ps_type.ToUpper.Contains("E3631")) Then
myPS = New E3631A(myiniObj.ps_addr)
err_code = myPS.ErrCode
ElseIf (myiniObj.ps_type.ToUpper.Contains("E66311")) Then
myPS = New E66311B(myiniObj.ps_addr)
err_code = myPS.ErrCode
ElseIf (myiniObj.ps_type.ToUpper.Contains("E66319")) Then
myPS = New E66311B(myiniObj.ps_addr)
err_code = myPS.ErrCode
ElseIf (myiniObj.ps_type.ToUpper.Contains("SCPI")) Then
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) Then
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) Then err_code = eCode.ERR_INST_MISSING_PWRSUPPLY
Else
'create object but set availability to false
myPS = New E3631A()
End If
Me.myTestSystem.instrument.PS = myPS
End If
Return err_code
End Function
End Class
Am I missing something?
Thank you!
-
Jul 14th, 2015, 01:43 PM
#2
Re: Function/Sub not declared . It may be inaccessible due to its protection level
myInifile is declared using the Dim keyword in your PowerSupply_setup class but you're trying to access it from your frmReadTemp class. A quick fix is to declare it as Public and when accessing it, add the class identifier before the object:
Code:
Public myIniFile As IniFile
Code:
PowerSupply_setup.myInifile
Now something else to consider, you have myIniFile declared as an object, but you're trying to use it as a method. That just isn't going to work.
-
Jul 14th, 2015, 02:35 PM
#3
Re: Function/Sub not declared . It may be inaccessible due to its protection level
At first, I thought that myIniFile could be a delegate, but I see that IniFile really is just an object, so there is something off about the logic.
However,
PowerSupply_setup.myIniFile would only work if it was shared, which is not the case here. He would need to have an instance of the PowerSupply_setup class to be able to access members of that class...or else move the whole thing to a Module, since a class with a name of PowerSupply_setup and that design, looks like it might be more suitable as a Module than a class. The key question is whether or not there will be multiple PowerSupply_setup in the program. If there is only one, then a Module would suit.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|