Passing Information

C

cmdolcet69

The code below was written to determine the state of the .Image:

With tmpPic
.Location = New Point(5, 8 + (100 * (groupIndex)))
.Size = defaultPic1Size
.SizeMode = PictureBoxSizeMode.CenterImage
If showBatteryPic Then
If mPort = "-1" Then
.Image = Me.imageListBattery.Images(6)
Else
.Image = Me.imageListBattery.Images(0)
End If
Else
If mPort = "-1" Then
.Image = Me.imageListBattery.Images(6)
Else
.Image = Me.imageListBattery.Images(5)
End If
End If

.Tag = gType & "_" & cPort & "_" & mPort
End With
Me.panelBatteryLevel.Controls.Add(tmpPic)
tmpPic = Nothing
End Sub


I want to check the battery level based off the value return I wanted
to set the .Image with the correct battery level in the sub below. How
can I get the .Image in the above sub to equal the batteryImage ?



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
End Sub
 
A

Armin Zingler

cmdolcet69 said:
I want to check the battery level based off the value return I
wanted to set the .Image with the correct battery level in the sub
below. How can I get the .Image in the above sub to equal the
batteryImage ?

I've really tried to understand your intention but wasn't able. Could
you please describe it once more? Thanks.


Armin
 
C

cmdolcet69

I've really tried to understand your intention but wasn't able. Could
you please describe it once more? Thanks.

Armin

Sure.... the CheckBatteryLevel () get called in a timer to return a
battery image in my program. If the level > 3240 the picbattery.image
get assigned a specific image. The first bit of code in the previous
thread hard code the assigned batteryimage. How can can I assign the
result by the CheckBatteryLevel () to the .Image =
Me.imageListBattery.Images(6). I though i could just call it like
this: .Image = CheckBatteryLevel () but it return an error?

I hope this helps better explains, thanks in advance
 
A

Armin Zingler

cmdolcet69 said:
Sure.... the CheckBatteryLevel () get called in a timer to return a
battery image in my program. If the level > 3240 the
picbattery.image get assigned a specific image. The first bit of
code in the previous thread hard code the assigned batteryimage. How
can can I assign the result by the CheckBatteryLevel () to the
.Image =
Me.imageListBattery.Images(6). I though i could just call it like
this: .Image = CheckBatteryLevel () but it return an error?

I hope this helps better explains, thanks in advance


CheckBatteryLevel is not a function. It doesn't have a function return
value. The only argument that is declared ByRef is 'ByRef picBattery As
PictureBox'. However, you never assign a new PictureBox to this
argument. Therefore, the Sub doesn't return anything and you should
change the parameter to ByVal. The procedure only sets the image of the
Picturebox, and in some cases it changes the value of variable
'intBatteryLvl'.

If you wanted to have the procedure return a value, you would have to
declare it as a function. Example:

Public Function CheckBatteryLevel(...) As Image

If mux.MuxAnalogValues(muxPort) >= 4096 Then
'Mux Not Responding
intBatteryLvl = 4096
Return batteryImages.Images(5)
elseif ....


However, I'm not sure, if that's what you are looking for.


Armin
 
C

cmdolcet69

CheckBatteryLevel is not a function. It doesn't have a function return
value. The only argument that is declared ByRef is 'ByRef picBattery As
PictureBox'. However, you never assign a new PictureBox to this
argument. Therefore, the Sub doesn't return anything and you should
change the parameter to ByVal. The procedure only sets the image of the
Picturebox, and in some cases it changes the value of variable
'intBatteryLvl'.

If you wanted to have the procedure return a value, you would have to
declare it as a function. Example:

Public Function CheckBatteryLevel(...) As Image

If mux.MuxAnalogValues(muxPort) >= 4096 Then
'Mux Not Responding
intBatteryLvl = 4096
Return batteryImages.Images(5)
elseif ....

However, I'm not sure, if that's what you are looking for.

Armin

Armin thanks for the reply. I changed the CheckBatteryLevel sub to a
function and declared the function like you said in your above
response. Now when i call that function in another area of code.....
what do i put in between the (....) ?
 
A

Armin Zingler

cmdolcet69 said:
Armin thanks for the reply. I changed the CheckBatteryLevel sub to a
function and declared the function like you said in your above
response. Now when i call that function in another area of code.....
what do i put in between the (....) ?


I don't know where you got the code from, but I'd ask the person who
wrote the function. He should know the meaning of the arguments.


Armin
 
C

cmdolcet69

I don't know where you got the code from, but I'd ask the person who
wrote the function. He should know the meaning of the arguments.

Armin

Sorry i just really confused when it comes to passing variablefrom1
function or sub to another. Basically the other programmer told me
this:


The ByVal mux As LMIObjectLibrary.Multiplexor : is referencing a class
that he created in the LMI ObjectLibrary
The ByVal muxPort As Integer: is numberic number for an esy
explanation say 32

So there the mux.MuxAnalogValue(muxport) is looking for a numberic
number like 32.
then what it does is if that numeric port is greater or equal to 4096
then show a picture in this case its a new batteryimage.


My question is this I know this sub doesn;treturn anything,however if
i change it to return a function as ImageList I would i need to
delcare the CheckBattery Function?


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

end sub
 
A

Armin Zingler

cmdolcet69 said:
Sorry i just really confused when it comes to passing variablefrom1
function or sub to another. Basically the other programmer told me
this:


The ByVal mux As LMIObjectLibrary.Multiplexor : is referencing a
class that he created in the LMI ObjectLibrary
The ByVal muxPort As Integer: is numberic number for an esy
explanation say 32

So there the mux.MuxAnalogValue(muxport) is looking for a numberic
number like 32.
then what it does is if that numeric port is greater or equal to
4096 then show a picture in this case its a new batteryimage.


My question is this I know this sub doesn;treturn anything,however
if i change it to return a function as ImageList I would i need to
delcare the CheckBattery Function?


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

end sub


If I understand you right, you want to change the procedure from a Sub
to a Function. I am not sure what you want the function to return. If it
has to return an Image from the Imagelist, you must declare the return
type "As Image"

public function CheckBatteryLevel(...) As Image

'Inside the function, you can return an Image from the Imagelist
'by using the Return keyword, for example:

Return batteryImages.Images(5)

End function


Let me know if that's what you are looking for.


Armin
 
C

cmdolcet69

If I understand you right, you want to change the procedure from a Sub
to a Function. I am not sure what you want the function to return. If it
has to return an Image from the Imagelist, you must declare the return
type "As Image"

public function CheckBatteryLevel(...) As Image

    'Inside the function, you can return an Image from the Imagelist
    'by using the Return keyword, for example:

    Return batteryImages.Images(5)

End function

Let me know if that's what you are looking for.

Armin- Hide quoted text -

- Show quoted text -

yes it is however when i call that function CheckBatteryLevel(...) in
another sub or function it will prompt me to pass in information
(........) inside the parethesis. This is were i get hung up as to
what information i pass in here?
 
A

Armin Zingler

cmdolcet69 said:
yes it is however when i call that function CheckBatteryLevel(...)
in another sub or function it will prompt me to pass in information
(........) inside the parethesis. This is were i get hung up as to
what information i pass in here?


You have given the parameter description already on your own:

I don't have the information because I didn't write the function.

Armin
 
C

cmdolcet69

You have given the parameter description already on your own:


I don't have theinformationbecause I didn't write the function.

Armin

Armin sorry for not getting back to you however i have discovered that
when i declare those variables in the function, they are local to just
that function so when i call the function somewhere else in the class
it will ask for the variables to be passed. when i pass the vairables
it will say they are not delcared, how can i declare them?
 
A

Armin Zingler

Armin sorry for not getting back to you however i have discovered
that when i declare those variables in the function, they are local
to just that function so when i call the function somewhere else in
the class it will ask for the variables to be passed. when i pass
the vairables it will say they are not delcared, how can i declare
them?

I give you an example:

Sub Example()

Dim result As Double
Dim Input As String
Dim InputValue As Double

'first example
result = Math.Sin(17)
MsgBox(result)

'second example
Input = InputBox("Please enter a value")
InputValue = CDbl(Input)

result = Math.Sin(InputValue)
MsgBox(result)

'third example
result = Math.Sin(InputValue + 17)
MsgBox(result)

End Sub

In this case, Math.Sin is the function. The function has one argument.
The name of the argument does not matter. As you see above, you can pass
any value to the function. In the first call it is an integer literal,
in the second call, the value is taken from variable 'InputValue', and
it's the result of an expression in the third example.

The code that the compiler creates for the line "result =
Math.Sin(InputValue)" is:
1. Take the value stored in variable 'InputValue'
2. Push the value onto the stack
3. Call Math.Sin
4. Store the return value in variable 'result'.

Inside Math.Sin, the code can access the value that has been put on the
stack in step two by the name of the argument. The function does not
know where the value came from. The value can be an integer literal (17
in this example), it can be the content of a variable (second example)
or it can be the result of a (sometimes complex) expression like in
example three.

So, I can not answer your individual question. You have to know where
you get the values from on your own. Imagine I ask you "Where do I get
the argument value for calling Math.Sin"?. You can not answer this, just
like I can not answer where you get the values for calling your
function. It depends on what you want to do.


Armin
 

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