Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

Passing Information

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cmdolcet69 - 07 Feb 2008 18:29 GMT
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
Armin Zingler - 07 Feb 2008 18:55 GMT
> 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
cmdolcet69 - 07 Feb 2008 19:51 GMT
> > 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
[quoted text clipped - 5 lines]
>
> 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
Armin Zingler - 07 Feb 2008 20:04 GMT
> On Feb 7, 1:55 pm, "Armin Zingler" <az.nos...@freenet.de> wrote:
> >
[quoted text clipped - 18 lines]
>
> 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
cmdolcet69 - 25 Feb 2008 19:57 GMT
> > > > 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
[quoted text clipped - 39 lines]
>
> 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  (....) ?
Armin Zingler - 25 Feb 2008 20:46 GMT
> > Public Function CheckBatteryLevel(...) As Image
> >
[quoted text clipped - 12 lines]
> 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
cmdolcet69 - 28 Feb 2008 16:36 GMT
> > > Public Function CheckBatteryLevel(...) As Image
>
[quoted text clipped - 17 lines]
>
> 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
Armin Zingler - 28 Feb 2008 19:28 GMT
> On Feb 25, 3:46 pm, "Armin Zingler" <az.nos...@freenet.de> wrote:
> >
[quoted text clipped - 49 lines]
>
> 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
cmdolcet69 - 29 Feb 2008 18:46 GMT
> > > > > Public Function CheckBatteryLevel(...) As Image
>
[quoted text clipped - 67 lines]
>
> - 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?
Armin Zingler - 29 Feb 2008 19:04 GMT
> "cmdolcet69" <colin_dolcetti@hotmail.com> schrieb
> > Let me know if that's what you are looking for.
[quoted text clipped - 3 lines]
> (........) 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:

> > > 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

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

Armin
cmdolcet69 - 21 Mar 2008 20:07 GMT
> > "cmdolcet69" <colin_dolce...@hotmail.com> schrieb
> > > Let me know if that's what you are looking for.
[quoted text clipped - 14 lines]
>
> 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?
Armin Zingler - 21 Mar 2008 22:02 GMT
"cmdolcet69" <colin_dolcetti@hotmail.com> schrieb
On Feb 29, 3:04 pm, "Armin Zingler" <az.nos...@freenet.de> wrote:
> > > "cmdolcet69" <colin_dolce...@hotmail.com> schrieb
> > > > Let me know if that's what you are looking for.
[quoted text clipped - 21 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.