Results 1 to 8 of 8
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how do i display all my array values as a msgbox (WordXP SP3)

    Hello

    I want to display like an online report.

    My code when it finds the correct value stores the information in an array. ie surname & firstname

    when the code is finished - I would like to display a messagebox showing all the values found eg
    Bloggs Joe
    Smith John

    note: in total i may display 8 records.

    How would I do that?

    I have the following code: but strMsg only the last array entry

    Dim i As Long
    i = 0
    For i = 1 To x
    strMsg = arrValue(i)
    Next

    MsgBox strMsg

    any ideas?
    many thanks
    diana

  2. #2
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do i display all my array values as a msgbox (WordXP SP3)

    Many thanks
    Ive answered my own question,

    I just realised I dont need to store in an array I can just keep adding to the string eg.
    strMsg = strMsg & ValueOne & " " & ValueTwo & Chr(13)

    and then display as...
    MsgBox x & " instances of " & strInputValue & " found. " & Chr(13) & Chr(13) & strMsg

    many thanks Diana <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: how do i display all my array values as a msgbox (WordXP SP3)

    Hi Diana, try this:

    strMsg = "Names found:"
    For i = 1 To x
    strMsg = strMsg & vbNewLine & arrValue(i)
    Next i
    MsgBox strMsg

    Within the loop, a line feed and the next array vallue are appended to the message string.

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do i display all my array values as a msgbox (WordXP SP3)

    nice one Hans <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

    Diana <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: how do i display all my array values as a msgbox (WordXP SP3)

    Glad you found a solution yourself!

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do i display all my array values as a msgbox (WordXP SP3)

    yes but your solution is alot neater...and from yours I learnt something as well.. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    diana

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: how do i display all my array values as a msgb

    <P ID="edit" class=small>(Edited by jscher2000 on 12-Oct-05 15:42. )</P>If you no longer need to support Office 97, here's another cool one. This assumes that you don't have any empty slots in your array (i.e., that it was dimensioned to the precisely correct size):

    MsgBox x & " instances of " & strInputValue & " found. " & String(2, vbCrLf) & Join(arrValue, vbCrLf)

    (The Join and Split methods were added in VBA 6/Office 2000)

    Added: If your array isn't full but you have a counter, perhaps:

    Redim Preserve arrValue(1 to x) 'I didn't actually test this to make sure I have the right syntax...
    MsgBox x & " instances of " & strInputValue & " found. " & String(2, vbCrLf) & Join(arrValue, vbCrLf)

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do i display all my array values as a msgb

    another good tip...thanks jefferson...

    diana

Posting Permissions

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