transfering user input from a form to VBA code

J

Jan

This is a question to Steve and/or David:



To make my code ready for sending it to David, I need to provide an user
interface. I've built a form with several option buttons and two command
buttons Run and Quit. The option buttons, grouped in two frames, were to set
the values of two variables declared in ClassWithEvents, a member of Class
Modules: Public NrHA, NrHB As Integer



Then, my option buttons have code, say



Private Sub OptionButton1_Click()

NrHA = 1

'for debugging only:

MsgBox "btnOne" + vbCrLf + CStr(NrHA)

End Sub



Using MsgBox(es) I can see that the NrHA is properly set within Sub
OptionButton1 when the button is selected. However it is not defined outside
this Sub. It is not even defined within the form class, among others on my
command buttons.



It must be something very elemental, but after spending the weekend trying
to find what it is, finally I decided to post it. I am new to VBA, but I
have previous programming experience, mostly with Fortran, Algol, Pascal and
some assemblers.



My question and kind request: what should I do to pass the value of my
variables to my main code Private Sub FuctionShow_SlideShowNextSlide(ByVal
Wn As SlideShowWindow) sitting in ClassWithEvents. Also, please, what is the
rational behind the solution.



I will really appreciate your help. You may respond here or, if you prefer,
to jczATtelusplanet.net.nospamplease - I think you can figure it out easily.



Thanks a lot, JanAdam
 
D

David M. Marcovitz

Jan,

You are banging up against the limits of my VBA knowledge, so Steve will
have to give you a more definitive answer. However, I'll get the ball
rolling, and Steve can correct me.

Looking over your list of programmign languages, I don't believe that any
of them are object-oriented languages. Since you are creating classes,
you are running into the object-oriented nature of VBA. I don't generally
do much with this because I am aiming at people who are beginners, so I
tell them to put everything in one module, but I do have a bit of
experience in object-oriented programming.

A class defines a kind of object. Things in the class definition are not
generally accessible from the outside, except through the methods and
possibly the properties of the class. My guess is that variables defined
in the class module wouldn't be public.

Therefore, your public definition of a variable should probably go
outside your class module. I suspect it can go in just about any normal
module. Use the class module only for defining your class. If the
variable has to be a part of the class, it should probably be a property
of the class in which case it won't be a public variable but rather a
different thing associated with each instance of the class.

Does this make sense, Jan? Is this correct, Steve?

--David

--
David M. Marcovitz
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
J

Jan

It would not let me do this. If I declare them inside the sub, it comes with
a compiler error "invalid attribute ..." and help advises to move it up to
the module, i.e., exactly where it was before. On the margin, wherever in my
code I type nrha and move to another line it converts to NrHA, I thus deduce
(incorrectly perhaps) it is visible everywhere. Its value is not, somehow.
My animation works for my own presentation later this week. There, I do not
need to change variables, I can set them within the code. I have to learn
more on passing values of variables around and when ready I will finish the
thing.
JanAdam
 
J

JanAdam

Thanks Steve and Dave,

In the meantime I have made it to work. I have declared my global variables
in ClassWithEvents module, where my main code, a Sub with events was
located. When I moved the declarations to Module1, everything started
working just fine. In Module1 I only have the declarations and my
initialization routine that instantiate my show. And, I do have Option
Explicit everywhere.

After the fact, when I am now reading your explanations, it does make sense.
I couldn't find anything on it in my several books and MS helps are
routinely helpless. Help in PP 2000 is so so, but finding anything in PP
2003 is almost useless, unless you exactly know the key word under which the
information is stored. Sorry for venting my frustration.

On the object oriented programming: the main reason I am playing with those
things is to learn it and to get that intuitive feeling I've had with the
sequential programming. I simply like to understand things, that's all.

Thanks again, Jan
 

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