|
-
Feb 1st, 2002, 08:40 AM
#1
Thread Starter
Hyperactive Member
carrying data between forms
I have a form on which the user makes a selection.
The selection prompts another form to open. The form is used for two variations of the selection.
The user has these options:
x1
x2
y
If x1, then some of the textboxes are disabled, etc.
How do I get the value (1 or 2) to the new form? I could use a global variable I suppose, but isn't there a better *cleaner* way? If it was a procedure running I would pass the value byval or byref, but how do you do this for a form_load()?
-
Feb 1st, 2002, 08:56 AM
#2
Maybee not what you want...
I don't know exacly what you mean when the user have the
options x1, x2, y but if selection is in a control you can
alway from the other form read
frmFirstform.Text1.Text, frmFirstform.check1.Value, frmFirstform.option1.Value and so on...
Or if it's in a modular variable frmFirstform.variablename.
That is if you haven't erased the first form from the memory with something like "Set frmFirstform = Nothing", when the second form loads.
-
Feb 1st, 2002, 09:03 AM
#3
Thread Starter
Hyperactive Member
The user selects an item from a list box, and the main form stays in memory.
I am trying to keep the code tidy. I started out doing what you are saying -
user selects item
user hits "cmdGo"
cmdGo
-do a select case on the list index (actually there are 8 items)
-load necessary form, with certain attributes (more text boxes etc) depending on which item was selected (referring back to the main form).
This is all fine to use the lsbSelection.ListIndex. But what about a month from now when I add another selection at the top? All of my ListIndices will change...that is what I am trying to avoid. If I use the name of selection, that would work, until I decide to modify the name, then I need to find all the places I referred to it.
So I have a way to do it, it just doesn't seem to be the *best* way. Ideally, all of the selecting would be done in the cmdGo procedure so if I modify my listbox selections or order, I only change the code one place.
-
Feb 1st, 2002, 09:23 AM
#4
The selection text is stored either in a table or in the listbox
properties as a delimited string with the delimiter being ";". Since
you presumably have not too many selections, I would think that
you are using absolute text strings.
You can parse the string to retrieve the text and then use a
select statement.
Select case TextSt
case = "GiveUp"
code
case = "GoHome"
code
case = "YourUgly"
code
case else
msgbox("Problem", "I didn't code for: " & TextSt & ", idiot")
End Select
if you ARE using a table lookup, you can store the ID of the
selection for future reference and do the same thing.
HTH
-
Feb 1st, 2002, 09:32 AM
#5
Maybee a better solution?
You don't want selection of the user to depend on the text or listindex of the combobox.
What if you let it depend on then itemdata property?
-
Feb 1st, 2002, 09:57 AM
#6
correction...
Listbox I mean, but they work the same when it comes to the itemdata property. If you insert a new item you just need to be sure to insert the new itemdata in the same place as in the list. No code need to be change just catch the new itemdata in the "select case".
-
Feb 1st, 2002, 10:13 AM
#7
Thread Starter
Hyperactive Member
My problem isn't determining what the user selected.
My problem is carrying a selection variable to a new form from the select case.
So
Code:
Select lsbOptions.List(lsbOptions.ListIndex)
case = "GiveUp" 'no problem this way
sType = "GiveUp"
MakeForgetItDoc sType
case = "GoHome"
sType = "GoHome"
MakeForgetItDoc sType
case = "You'reUgly" 'the problem starts here
sType = "You'reUgly"
frmHowUgly.Show *******sType*******
case = "You'reUgly&Smelly"
sType = "You'reUgly&Smelly"
frmHowUgly.Show *****sType*********
case else
msgbox("Problem", "I didn't code for: " & TextSt & ", idiot")
End Select
My question is - how do I get the value of sType to the frmHowUgly form, without making it a Global variable or referring back to the option form in the frmHowUgly_Load event?
Last edited by billwagnon; Feb 1st, 2002 at 10:24 AM.
-
Feb 1st, 2002, 10:32 AM
#8
"My question is - how do I get the value of sType to the frmHowUgly form, without making it a Global variable or referring back to the option form in the frmHowUgly_Load event"
Hmm... You don't want to refer back, and you dont wan't a global variable... But you want to store the value someway... a file seems like overkill... In the registry is quite easy even if's also seem like overkill when it comes to this problem. I would say, store it in a modular variable even if it means that you refer back...
-
Feb 1st, 2002, 10:35 AM
#9
Thread Starter
Hyperactive Member
Okay, I can store it in the registry. Is that the same as a modular variable?
It just *seems* like there should be a way to pass a parameter to a form just like you pass a parameter to a subprocedure.
-
Feb 1st, 2002, 10:57 AM
#10
But you can choose to pass it to a modular variable in the second form if you want to, then it almost work as a parameter.
I mean:
form1:
Select lsbOptions.List(lsbOptions.ListIndex)
case = "GiveUp" 'no problem this way
sType = "GiveUp"
MakeForgetItDoc sType
case = "GoHome"
sType = "GoHome"
MakeForgetItDoc sType
case = "You'reUgly" 'the problem starts here
sType = "You'reUgly"
frmHowUgly.MyModularVariable = sType !!!!!!!!!!
frmHowUgly.Show *******sType*******
case = "You'reUgly&Smelly"
sType = "You'reUgly&Smelly"
frmHowUgly.MyModularVariable = sType !!!!!!!!!!
frmHowUgly.Show *****sType*********
case else
msgbox("Problem", "I didn't code for: " & TextSt & ", idiot")
End Select
frmHowUgly:
Public MyModularVariable As String
The registry is something else that can be used for different things, like storing values when the program ends that you want to catch the next time the program starts.
-
Feb 1st, 2002, 11:00 AM
#11
Thread Starter
Hyperactive Member
Hey I think that's it. I'll try it out!
-
Feb 1st, 2002, 11:01 AM
#12
...
Sorry, the indentation dissepared, but i guess you know what i ment.
-
Feb 1st, 2002, 11:20 AM
#13
Thread Starter
Hyperactive Member
That works perfectly! Thank you for drawing the picture for me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|