Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any idea on how to display array elements in a msgbox as...

Status
Not open for further replies.

jlitondo

MIS
Jun 27, 2000
175
US
one message box with all the elements listed???  
 
With 20 elements, it will be long and ugly, but you can do this,<br><br>If your Array was called varTest():<br><br>MsgBox varTest(1) & vbNewLine & varTest(2) & vbNewLine & varTest(3) & vbNewLine & varTest(4) & vbNewLine & varTest(5) ..... etc.<br><br>This will work, I tried it. I will let you know if I come up with a different solution.<br><br>HTH<br> <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Given varTest(X) is the array, and the first array number was 0.<br>You could do this if you wanted to have the items separated by a comma<br><br>&nbsp;Dim strMsg As String, i As Long<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Do Until X = -1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strMsg = varTest(X) & &quot;, &quot; & strMsg<br>&nbsp;&nbsp;&nbsp;&nbsp;X = X - 1<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br>&nbsp;&nbsp;&nbsp;&nbsp;i = Len(strMsg)<br>&nbsp;&nbsp;&nbsp;&nbsp;strMsg = Left(strMsg, i - 2) ' trim trailing comma<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox strMsg<br><br>or you could change & &quot;, &quot; to&nbsp;&nbsp;& vbCrLf if you wanted a new line, and then remove the <br>i = Len(strMsg) and the line to trim the comma
 
Thanks alot guys for the tip. Since the array was filling up with values that have been selected in a list box,I used the following looping structure:<br><br>For each counter in myListBox.ItemsSelected<br>&nbsp;&nbsp;&nbsp;myArray(counter) = myListBox.Column(1,[counter]) <br>&nbsp;&nbsp;&nbsp;strMsg = myArray(counter) & &quot;,&quot; & strMsg<br>&nbsp;&nbsp;&nbsp;counter = counter + 1<br>Next counter<br><br>&nbsp;Response = MsgBox(strMsg,vbYesNo,Title)<br><br>'use IF statement to execute code based on vbYesNo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top