Results 1 to 13 of 13

Thread: carrying data between forms

  1. #1

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290

    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()?

  2. #2
    stickan
    Guest

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

  3. #3

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    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.

  4. #4
    DerFarm
    Guest
    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

  5. #5
    stickan
    Guest

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

  6. #6
    stickan
    Guest

    Cool 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".

  7. #7

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    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.

  8. #8
    stickan
    Guest

    Unhappy

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

  9. #9

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    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.

  10. #10
    stickan
    Guest
    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.

  11. #11

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    Hey I think that's it. I'll try it out!

  12. #12
    stickan
    Guest

    Talking ...

    Sorry, the indentation dissepared, but i guess you know what i ment.

  13. #13

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    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
  •  



Click Here to Expand Forum to Full Width