Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Variable in Textbox Event

  1. #1
    New Member
    Join Date
    Oct 2018
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Variable in Textbox Event

    I make a selection in a Userform.Listbox with data coming form the Textbox in a Userform
    Can I pass a variable to the Textbox Sub ..._Change event
    ie. Sub TextBx_Change(ByRef ....)
    I don't want to use a Public variable
    Thanks

  2. #2
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,346
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Variable in Textbox Event

    Quote Originally Posted by helivw View Post
    I make a selection in a Userform.Listbox with data coming form the Textbox in a Userform
    Can I pass a variable to the Textbox Sub ..._Change event
    ie. Sub TextBx_Change(ByRef ....)
    I don't want to use a Public variable
    Thanks
    Can you use the TextBox Tag Property to store the data ?
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

  3. #3
    New Member
    Join Date
    Oct 2018
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable in Textbox Event

    Quote Originally Posted by Jaafar Tribak View Post
    Can you use the TextBox Tag Property to store the data ?
    My problem is, I need to pass an "array"

  4. #4
    MrExcel MVP mikerickson's Avatar
    Join Date
    Jan 2007
    Location
    Davis CA
    Posts
    22,575
    Post Thanks / Like
    Mentioned
    20 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Variable in Textbox Event

    What is the data type of the array?
    A delimited string and an array are pretty much the same information.

  5. #5
    New Member
    Join Date
    Oct 2018
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable in Textbox Event

    Quote Originally Posted by mikerickson View Post
    What is the data type of the array?
    A delimited string and an array are pretty much the same information.
    My array consist of +200 rows & 3 columns

  6. #6
    MrExcel MVP mikerickson's Avatar
    Join Date
    Jan 2007
    Location
    Davis CA
    Posts
    22,575
    Post Thanks / Like
    Mentioned
    20 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Variable in Textbox Event

    That would be a long delimited string. A module wide variable would be the easiest way to pass it. What is your concern about using a public variable?

  7. #7
    New Member
    Join Date
    Oct 2018
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable in Textbox Event

    Quote Originally Posted by mikerickson View Post
    That would be a long delimited string. A module wide variable would be the easiest way to pass it. What is your concern about using a public variable?
    Because I read everywhere, you have to avoid using public variables and I use a lot of userforms (very handy) and each time I'm fighting of finding a easy way to transfer variables between my subroutine and parts (listbox, textbox, ...) of the userform and vv

  8. #8
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,346
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Variable in Textbox Event

    Can't you use module level variables instead of Public global variables - Each variable declared at the top of each userform module so you can use them throughout the entire userform lifetime and scope.
    Last edited by Jaafar Tribak; Aug 4th, 2019 at 09:34 AM.
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

  9. #9
    New Member
    Join Date
    Oct 2018
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable in Textbox Event

    Quote Originally Posted by Jaafar Tribak View Post
    Can't you use module level variables instead of Public global variables - Each variable declared at the top of each userform module so you can use them throughout the entire userform lifetime and scope.
    Thanks a lot Jaafar.
    I really never thought that way, shame on me.

    And what would be te best way to transfer my array to a userform Sub i.e. the userform initialize or whathever before my command
    Userform.Show

  10. #10
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,346
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Variable in Textbox Event

    The userform Initialize event fires before showing the userform so that's a good place to populate the array.
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •