Discussion:
Functions
(too old to reply)
Tim^^BOB
2003-12-07 16:46:49 UTC
Permalink
I would like to create a function that runs everytime the user clicks
one control in a control array. The problem is that I need to be able
to tell which control has been clicked. I would also like to do this
without puting different code in each control if possible. If anyone
has any ideas about my problem, please post.

Thanks in Advance to all repliers.
Martin Trump
2003-12-07 19:01:34 UTC
Permalink
Post by Tim^^BOB
I would like to create a function that runs everytime the user clicks
one control in a control array. The problem is that I need to be able
You have a control array so in the click event use (untested):-

Select Case Index
Case 0
<whatever>
Case 1
<whatever>
Case 2
z = myfunction(whatever)
etc.
End Select

That's it. HTH.

Regards
--
Martin Trump
Tim^^BOB
2003-12-08 19:59:10 UTC
Permalink
Thanks Martin, that does help, but that would mean I would need to
write a different case for each control right? I have 64 different
controls, so I was wondering if there would be another way to get the
index value and put it into a variable? Sort of like a way to tell
which control called the function in the first place.

Thanks to all repliers.

Tim
Martin Trump
2003-12-08 20:37:50 UTC
Permalink
Post by Tim^^BOB
Thanks Martin, that does help, but that would mean I would need to
write a different case for each control right? I have 64 different
controls, so I was wondering if there would be another way to get the
index value and put it into a variable? Sort of like a way to tell
which control called the function in the first place.
Hi Tim.

Perhaps I misunderstood you. You previously said:-
Post by Tim^^BOB
I would like to create a function that runs everytime the user clicks
one control in a control array. The problem is that I need to be able
I took that to mean that only one of the controls would run your
function.

How about in the control array click event you use:-

z = myfunction(Index)

then in myfunction test Index with

Select Case Index
Case 0
<whatever>
Case 1
etc.

Rather vague but HTH. Please post again if need be, I'll do what I can.

Regards
--
Martin Trump
Tim^^BOB
2003-12-10 00:33:31 UTC
Permalink
Thanks, but actually I figured out my own problem shortly after I
posted! I decided not to use a function, but rather another Sub that I
had in the form -> general. I call it and it does it's thing, and all
I needed was a way to pass the index value of the control clicked to
the sub. I just did it with a global variable and it works fine. (It
seems all the questions I post in this NG are related to either types
or arrays...) Thank you Martin, for both your replies. If I have
anymore questions I will be sure to put them here.

Thanks again!
Demosthenes
2003-12-23 00:18:34 UTC
Permalink
What do you gain by using a global variable?

Private Sub YourControl_Click(Index as Integer)
YourFunction(Index);
End Sub

Public Function YourFunction(intIndex as Integer) as Whatever
'Do Whatever - intIndex is the index value of your button.
End Function
Post by Tim^^BOB
Thanks, but actually I figured out my own problem shortly after I
posted! I decided not to use a function, but rather another Sub that I
had in the form -> general. I call it and it does it's thing, and all
I needed was a way to pass the index value of the control clicked to
the sub. I just did it with a global variable and it works fine. (It
seems all the questions I post in this NG are related to either types
or arrays...) Thank you Martin, for both your replies. If I have
anymore questions I will be sure to put them here.
Thanks again!
Tim^^BOB
2003-12-27 17:52:30 UTC
Permalink
Post by Demosthenes
What do you gain by using a global variable?
Instead of having certain variables required by the function, I use
global variables and just call them inside the function. It makes it
easier to share changing information all through the program. I guess
I don't actually NEED it, but it's just more comfortable for me in a
one person project.

Continue reading on narkive:
Loading...