Calling a Sub with passed variables

C

cmdolcet69

I have this Sub that I have passed 4 values to called check battery.

Public Sub CheckBatteryLevel(ByVal mux As
LMIObjectLibrary.Multiplexor, ByVal muxPort As Integer, ByRef
picBattery As PictureBox, ByVal batteryImages As ImageList)

End Sub


If I call the CheckBatteryLevel() inside another Sub It will give me
an error - argument not specified for parameters. Can anyone give me
an example of how to do this?
 
A

Armin Zingler

cmdolcet69 said:
I have this Sub that I have passed 4 values to called check battery.

Public Sub CheckBatteryLevel(ByVal mux As
LMIObjectLibrary.Multiplexor, ByVal muxPort As Integer, ByRef
picBattery As PictureBox, ByVal batteryImages As ImageList)

End Sub


If I call the CheckBatteryLevel() inside another Sub It will give me
an error - argument not specified for parameters. Can anyone give me
an example of how to do this?

Does your first sentence mean that you can successfully call it from
somewhere else? How do you call it there and where it fails? Please show
the code. Is CheckBatteryLevel your own sub? Does the sub return a new
PictureBox?


Armin
 
K

kimiraikkonen

I have this Sub that I have passed 4 values to called check battery.

Public Sub CheckBatteryLevel(ByVal mux As
LMIObjectLibrary.Multiplexor, ByVal muxPort As Integer, ByRef
picBattery As PictureBox, ByVal batteryImages As ImageList)

End Sub

If I call the CheckBatteryLevel() inside another Sub It will give me
an error - argument not specified for parameters. Can anyone give me
an example of how to do this?

Your arguments is function-specific.
Basically, inside your functions must have arguments declared in
function constructor.

eg:

CheckBatteryLevel(mux, muxport, picBattery....)
 
C

cmdolcet69

Does your first sentence mean that you can successfully call it from
somewhere else? How do you call it there and where it fails? Please show
the code. Is CheckBatteryLevel your own sub? Does the sub return a new
PictureBox?

Armin

Here's the Check BatteryLevel Sub

Public Sub CheckBatteryLevel(ByVal mux As
LMIObjectLibrary.Multiplexor, ByVal muxPort As Integer, ByRef
picBattery As PictureBox, ByVal batteryImages As ImageList)
Try
If mux.MuxAnalogValues(muxPort) >= 4096 Then
'Mux Not Responding
picBattery.Image = batteryImages.Images(5)
intBatteryLvl = 4096
ElseIf mux.MuxAnalogValues(muxPort) > 3720 Then
'Full battery
picBattery.Image = batteryImages.Images(0)
ElseIf mux.MuxAnalogValues(muxPort) > 3365 And
mux.MuxAnalogValues(muxPort) <= 3720 Then
'OK battery
picBattery.Image = batteryImages.Images(1)
ElseIf mux.MuxAnalogValues(muxPort) > 3240 And
mux.MuxAnalogValues(muxPort) <= 3365 Then
'Low battery
picBattery.Image = batteryImages.Images(2)
ElseIf mux.MuxAnalogValues(muxPort) > 3000 And
mux.MuxAnalogValues(muxPort) <= 3240 Then
'Critical battery
picBattery.Image = batteryImages.Images(3)
ElseIf mux.MuxAnalogValues(muxPort) > 100 And
mux.MuxAnalogValues(muxPort) <= 3000 Then
'Empty battery
picBattery.Image = batteryImages.Images(4)
Else
'AC Adapter in use
picBattery.Image = batteryImages.Images(6)
intBatteryLvl = 4096
End If
Catch ex As Exception
_TListener.AddMethodError(ex)
End Try

It fails when I try and call it in another Sub as CheckBatteryLevel()
 
A

Armin Zingler

The answer seems to be: no

Please show the code how you call it.

The Sub does not return a new picturebox => declare picBattery ByVal,
not ByRef.
Here's the Check BatteryLevel Sub

Public Sub CheckBatteryLevel(ByVal mux As
LMIObjectLibrary.Multiplexor, ByVal muxPort As Integer, ByRef
picBattery As PictureBox, ByVal batteryImages As ImageList)

Code:
It fails when I try and call it in another Sub as
CheckBatteryLevel()[/QUOTE]


Armin
 
J

Jack Jackson

Here's the Check BatteryLevel Sub

Public Sub CheckBatteryLevel(ByVal mux As
LMIObjectLibrary.Multiplexor, ByVal muxPort As Integer, ByRef
picBattery As PictureBox, ByVal batteryImages As ImageList)
Try
If mux.MuxAnalogValues(muxPort) >= 4096 Then
'Mux Not Responding
picBattery.Image = batteryImages.Images(5)
intBatteryLvl = 4096
ElseIf mux.MuxAnalogValues(muxPort) > 3720 Then
'Full battery
picBattery.Image = batteryImages.Images(0)
ElseIf mux.MuxAnalogValues(muxPort) > 3365 And
mux.MuxAnalogValues(muxPort) <= 3720 Then
'OK battery
picBattery.Image = batteryImages.Images(1)
ElseIf mux.MuxAnalogValues(muxPort) > 3240 And
mux.MuxAnalogValues(muxPort) <= 3365 Then
'Low battery
picBattery.Image = batteryImages.Images(2)
ElseIf mux.MuxAnalogValues(muxPort) > 3000 And
mux.MuxAnalogValues(muxPort) <= 3240 Then
'Critical battery
picBattery.Image = batteryImages.Images(3)
ElseIf mux.MuxAnalogValues(muxPort) > 100 And
mux.MuxAnalogValues(muxPort) <= 3000 Then
'Empty battery
picBattery.Image = batteryImages.Images(4)
Else
'AC Adapter in use
picBattery.Image = batteryImages.Images(6)
intBatteryLvl = 4096
End If
Catch ex As Exception
_TListener.AddMethodError(ex)
End Try

It fails when I try and call it in another Sub as CheckBatteryLevel()

Maybe I don't understand, but your sub requires 4 arguments, so you
must pass 4 arguments when you call it. It is an error if you pass
fewer arguments.

If it makes sense to sometimes call it with fewer arguments, you can
declare some or all of the argument Optional and supply a default
value or you can provide overloads with fewer arguments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top