473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Easy way to pass a sender to a subroutine? Maybe I didn't word that right...

Hello - I'm working on a project to have 6 labels, each with a value of 0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.

What I want to do is have a routine that handles the Up Buttons, a routine
that handles the Down Buttons, both of them then call a subroutine called
ChangeRange that does the work. The way I have it is by doing a clumsy if
then else for every set of buttons, as below:

private handles down buttons
intModifier = -1
call ChangeRange

private handles up buttons
intModfier = 1
call ChangeRange

Sub ChangeRange
if sender is up1button or sender is down1button then....
intNumber1 = intNumber1 + (intModifier * 1)
if sender is up2button or sender is down2button then....
intNumber2 = intNumber2 + (intModifier * 1)
if sender up2button then...
End if

me.number1label.text = intNumber1
me.number2label.text = intNumber2
me.number3... etc

The problem is I know there has to be a way to have one calc that applies to
whatever button was sent and it's corresponding variable (up1button and
down1button both apply to intNumber1), but my knowledge is very limited
right now. Any help would be appreciated!
Nov 21 '05 #1
8 1151
Hi Patrick

You might want to start by creating a UserControl (in Visual Studio .NET a
Windows Control Library project). Put 1 label, and your two buttons on that.
Then put six of the user controls onto your form in your application.

HTH

Nigel Armstrong

"Patrick" wrote:
Hello - I'm working on a project to have 6 labels, each with a value of 0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.

What I want to do is have a routine that handles the Up Buttons, a routine
that handles the Down Buttons, both of them then call a subroutine called
ChangeRange that does the work. The way I have it is by doing a clumsy if
then else for every set of buttons, as below:

private handles down buttons
intModifier = -1
call ChangeRange

private handles up buttons
intModfier = 1
call ChangeRange

Sub ChangeRange
if sender is up1button or sender is down1button then....
intNumber1 = intNumber1 + (intModifier * 1)
if sender is up2button or sender is down2button then....
intNumber2 = intNumber2 + (intModifier * 1)
if sender up2button then...
End if

me.number1label.text = intNumber1
me.number2label.text = intNumber2
me.number3... etc

The problem is I know there has to be a way to have one calc that applies to
whatever button was sent and it's corresponding variable (up1button and
down1button both apply to intNumber1), but my knowledge is very limited
right now. Any help would be appreciated!

Nov 21 '05 #2
Hi Patrick

You might want to start by creating a UserControl (in Visual Studio .NET a
Windows Control Library project). Put 1 label, and your two buttons on that.
Then put six of the user controls onto your form in your application.

HTH

Nigel Armstrong

"Patrick" wrote:
Hello - I'm working on a project to have 6 labels, each with a value of 0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.

What I want to do is have a routine that handles the Up Buttons, a routine
that handles the Down Buttons, both of them then call a subroutine called
ChangeRange that does the work. The way I have it is by doing a clumsy if
then else for every set of buttons, as below:

private handles down buttons
intModifier = -1
call ChangeRange

private handles up buttons
intModfier = 1
call ChangeRange

Sub ChangeRange
if sender is up1button or sender is down1button then....
intNumber1 = intNumber1 + (intModifier * 1)
if sender is up2button or sender is down2button then....
intNumber2 = intNumber2 + (intModifier * 1)
if sender up2button then...
End if

me.number1label.text = intNumber1
me.number2label.text = intNumber2
me.number3... etc

The problem is I know there has to be a way to have one calc that applies to
whatever button was sent and it's corresponding variable (up1button and
down1button both apply to intNumber1), but my knowledge is very limited
right now. Any help would be appreciated!

Nov 21 '05 #3
Patrick,

Seeing this do I think that you are mixing a lot of things.

When you have one button event it is probably more easier and you do not
need more than that.

You can just make that by creating a button1.click event and than to add in
the end after the handler button1.click, the text , button2.click

Or when you want it even more easier when all the buttons are direct on the
form, than you can set your form load event (you have to make that button1
click event again)
\\\
for each btn as control on me.controls
if typeof btn Is Button then
AddHandler btn, AddressOf Button1_Click
end if
next
///
Than you can set in that event Button1 click event
\\\
Select case directcast(sender, button).name
case "button1"
'do your stuff for button1
case "button2"
'do your stuff for button2
etc
End select
///

I typed everything in this message so keep track of typos

I hope this helps?

Cor

"Patrick" <pa*****@hello.com>
Hello - I'm working on a project to have 6 labels, each with a value of
0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled
down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.

What I want to do is have a routine that handles the Up Buttons, a routine
that handles the Down Buttons, both of them then call a subroutine called
ChangeRange that does the work. The way I have it is by doing a clumsy if
then else for every set of buttons, as below:

private handles down buttons
intModifier = -1
call ChangeRange

private handles up buttons
intModfier = 1
call ChangeRange

Sub ChangeRange
if sender is up1button or sender is down1button then....
intNumber1 = intNumber1 + (intModifier * 1)
if sender is up2button or sender is down2button then....
intNumber2 = intNumber2 + (intModifier * 1)
if sender up2button then...
End if

me.number1label.text = intNumber1
me.number2label.text = intNumber2
me.number3... etc

The problem is I know there has to be a way to have one calc that applies
to
whatever button was sent and it's corresponding variable (up1button and
down1button both apply to intNumber1), but my knowledge is very limited
right now. Any help would be appreciated!

Nov 21 '05 #4
Patrick,

Seeing this do I think that you are mixing a lot of things.

When you have one button event it is probably more easier and you do not
need more than that.

You can just make that by creating a button1.click event and than to add in
the end after the handler button1.click, the text , button2.click

Or when you want it even more easier when all the buttons are direct on the
form, than you can set your form load event (you have to make that button1
click event again)
\\\
for each btn as control on me.controls
if typeof btn Is Button then
AddHandler btn, AddressOf Button1_Click
end if
next
///
Than you can set in that event Button1 click event
\\\
Select case directcast(sender, button).name
case "button1"
'do your stuff for button1
case "button2"
'do your stuff for button2
etc
End select
///

I typed everything in this message so keep track of typos

I hope this helps?

Cor

"Patrick" <pa*****@hello.com>
Hello - I'm working on a project to have 6 labels, each with a value of
0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled
down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.

What I want to do is have a routine that handles the Up Buttons, a routine
that handles the Down Buttons, both of them then call a subroutine called
ChangeRange that does the work. The way I have it is by doing a clumsy if
then else for every set of buttons, as below:

private handles down buttons
intModifier = -1
call ChangeRange

private handles up buttons
intModfier = 1
call ChangeRange

Sub ChangeRange
if sender is up1button or sender is down1button then....
intNumber1 = intNumber1 + (intModifier * 1)
if sender is up2button or sender is down2button then....
intNumber2 = intNumber2 + (intModifier * 1)
if sender up2button then...
End if

me.number1label.text = intNumber1
me.number2label.text = intNumber2
me.number3... etc

The problem is I know there has to be a way to have one calc that applies
to
whatever button was sent and it's corresponding variable (up1button and
down1button both apply to intNumber1), but my knowledge is very limited
right now. Any help would be appreciated!

Nov 21 '05 #5
Thanks for the help both of you, and just out of curriousity, is there a way
to ask the system what button has the focus, and return the button name or
act on it somehow?

Thanks,

Patrick

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Patrick,

Seeing this do I think that you are mixing a lot of things.

When you have one button event it is probably more easier and you do not
need more than that.

You can just make that by creating a button1.click event and than to add in the end after the handler button1.click, the text , button2.click

Or when you want it even more easier when all the buttons are direct on the form, than you can set your form load event (you have to make that button1
click event again)
\\\
for each btn as control on me.controls
if typeof btn Is Button then
AddHandler btn, AddressOf Button1_Click
end if
next
///
Than you can set in that event Button1 click event
\\\
Select case directcast(sender, button).name
case "button1"
'do your stuff for button1
case "button2"
'do your stuff for button2
etc
End select
///

I typed everything in this message so keep track of typos

I hope this helps?

Cor

"Patrick" <pa*****@hello.com>
Hello - I'm working on a project to have 6 labels, each with a value of
0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled
down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.

What I want to do is have a routine that handles the Up Buttons, a routine that handles the Down Buttons, both of them then call a subroutine called ChangeRange that does the work. The way I have it is by doing a clumsy if then else for every set of buttons, as below:

private handles down buttons
intModifier = -1
call ChangeRange

private handles up buttons
intModfier = 1
call ChangeRange

Sub ChangeRange
if sender is up1button or sender is down1button then....
intNumber1 = intNumber1 + (intModifier * 1)
if sender is up2button or sender is down2button then....
intNumber2 = intNumber2 + (intModifier * 1)
if sender up2button then...
End if

me.number1label.text = intNumber1
me.number2label.text = intNumber2
me.number3... etc

The problem is I know there has to be a way to have one calc that applies to
whatever button was sent and it's corresponding variable (up1button and
down1button both apply to intNumber1), but my knowledge is very limited
right now. Any help would be appreciated!


Nov 21 '05 #6
Thanks for the help both of you, and just out of curriousity, is there a way
to ask the system what button has the focus, and return the button name or
act on it somehow?

Thanks,

Patrick

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Patrick,

Seeing this do I think that you are mixing a lot of things.

When you have one button event it is probably more easier and you do not
need more than that.

You can just make that by creating a button1.click event and than to add in the end after the handler button1.click, the text , button2.click

Or when you want it even more easier when all the buttons are direct on the form, than you can set your form load event (you have to make that button1
click event again)
\\\
for each btn as control on me.controls
if typeof btn Is Button then
AddHandler btn, AddressOf Button1_Click
end if
next
///
Than you can set in that event Button1 click event
\\\
Select case directcast(sender, button).name
case "button1"
'do your stuff for button1
case "button2"
'do your stuff for button2
etc
End select
///

I typed everything in this message so keep track of typos

I hope this helps?

Cor

"Patrick" <pa*****@hello.com>
Hello - I'm working on a project to have 6 labels, each with a value of
0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled
down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.

What I want to do is have a routine that handles the Up Buttons, a routine that handles the Down Buttons, both of them then call a subroutine called ChangeRange that does the work. The way I have it is by doing a clumsy if then else for every set of buttons, as below:

private handles down buttons
intModifier = -1
call ChangeRange

private handles up buttons
intModfier = 1
call ChangeRange

Sub ChangeRange
if sender is up1button or sender is down1button then....
intNumber1 = intNumber1 + (intModifier * 1)
if sender is up2button or sender is down2button then....
intNumber2 = intNumber2 + (intModifier * 1)
if sender up2button then...
End if

me.number1label.text = intNumber1
me.number2label.text = intNumber2
me.number3... etc

The problem is I know there has to be a way to have one calc that applies to
whatever button was sent and it's corresponding variable (up1button and
down1button both apply to intNumber1), but my knowledge is very limited
right now. Any help would be appreciated!


Nov 21 '05 #7
On Fri, 12 Nov 2004 09:32:00 -0600, Patrick wrote:
Hello - I'm working on a project to have 6 labels, each with a value of 0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.


You might also look at the NumericUpDown control which does precisely as
you want.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #8
On Fri, 12 Nov 2004 09:32:00 -0600, Patrick wrote:
Hello - I'm working on a project to have 6 labels, each with a value of 0 -
9. Each label has a 2 buttons on the side, one labeled up, one labeled down.
I want the up button to increment til it hits 9, the down button to
decriment til it hits 0. That part I can do, but it's very ugly.


You might also look at the NumericUpDown control which does precisely as
you want.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
4
by: Michael Farber | last post by:
Not sure if this is the right group for this but anyways... I've got an ASP web application that uses a Visual Basic component to do some work. I instantiate the component in asp and then...
12
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though,...
8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
36
by: No Spam | last post by:
Dear fellow Access 2003 Users, Is there a way to trim all of the fields in a table in one swoop using VBA (preferred) or a query? Right now, I am using an update query and updating EACH field...
2
by: KevJB | last post by:
I must say I'm new to these Raw sockets in C# and unfortunantly I haven't met anyone who is a expert in them which makes trying to develop any rather difficult. What I've been doing is trying to...
0
by: Patrick | last post by:
Hello - I'm working on a project to have 6 labels, each with a value of 0 - 9. Each label has a 2 buttons on the side, one labeled up, one labeled down. I want the up button to increment til it...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
20
by: raylopez99 | last post by:
Inspired by Chapter 8 of Albahari's excellent C#3.0 in a Nutshell (this book is amazing, you must get it if you have to buy but one C# book) as well as Appendix A of Jon Skeet's book, I am going...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.