String Reading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gav82
    New Member
    • Feb 2008
    • 2

    String Reading

    Hi,

    I'm new to Access and was wondering if someone could help me with a little problem.


    If I am trying to get strings from an unbound listbox on a form and assign them to an array. How do I go about constructing the character reader in VBA to assign each string to an array element. I'm assuming that I need to read the row source and read each string up to a semicolon then repeat?

    Any Help would be great as I am bamboozled thanks!
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Originally posted by gav82
    Hi,
    I'm new to Access and was wondering if someone could help me with a little problem.

    If I am trying to get strings from an unbound listbox on a form and assign them to an array. How do I go about constructing the character reader in VBA to assign each string to an array element. I'm assuming that I need to read the row source and read each string up to a semicolon then repeat?

    Any Help would be great as I am bamboozled thanks!
    Hi Gav82. There is not enough detail in your post to give you an answer to your question at the moment. What is the source data for the listbox? What is the significance of the semicolon you mention? Are you including multiple elements in each string (not a good idea if you are...)? What is the purpose of the array? How many elements does it contain? What is going to be done after you fill the string array?

    Please give us something more to help us answer you...

    Regards

    Stewart
    Last edited by Stewart Ross; Mar 1 '08, 11:26 AM. Reason: Post mentions that list box is unbound, so question removed!

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by gav82
      Hi,

      I'm new to Access and was wondering if someone could help me with a little problem.


      If I am trying to get strings from an unbound listbox on a form and assign them to an array. How do I go about constructing the character reader in VBA to assign each string to an array element. I'm assuming that I need to read the row source and read each string up to a semicolon then repeat?

      Any Help would be great as I am bamboozled thanks!
      It's a lot simpler than you think, only 6 lines of code including a Comment. Assuming your List Box Name is List1, and that the Row Source Type is Value List, since you did mention the semi-colon, then:
      [CODE=vb]
      Dim varListContents As Variant, intCounter As Integer

      varListContents = Split(Me![List1].RowSource, ";")

      'Read the contents of the Array back
      For intCounter = LBound(varListC ontents) To UBound(varListC ontents)
      Debug.Print varListContents (intCounter)
      Next[/CODE]

      Comment

      • gav82
        New Member
        • Feb 2008
        • 2

        #4
        Originally posted by ADezii
        It's a lot simpler than you think, only 6 lines of code including a Comment. Assuming your List Box Name is List1, and that the Row Source Type is Value List, since you did mention the semi-colon, then:
        [CODE=vb]
        Dim varListContents As Variant, intCounter As Integer

        varListContents = Split(Me![List1].RowSource, ";")

        'Read the contents of the Array back
        For intCounter = LBound(varListC ontents) To UBound(varListC ontents)
        Debug.Print varListContents (intCounter)
        Next[/CODE]

        Split works a treat thanks a lot guys, just for the record I wanted the (;) as a delimiter so thats great.

        Thanks

        Comment

        Working...