423,688 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,688 IT Pros & Developers. It's quick & easy.

How to display 3 arrays in a single label?

P: 1
How to display a 3 arrays in a single label?
as in:
Expand|Select|Wrap|Line Numbers
  1. dim roll(3)as string
  2. roll(0) = "Yellow"
  3. roll(1)= "red"
  4. roll(2)= "green"
So I want to display yellow,red and green in a label
how do you do it?

please help its really important
Mar 1 '17 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
Loop through your array and add the value at that array position to a string.

Then set your label's text to the string that you have populated with the data from your array.

If you have multiple arrays, then loop through each array and add the string at each position in each array to the string.

Expand|Select|Wrap|Line Numbers
  1. Dim labelContent as String 'Will contain the data from the arrays
  2.  
  3. Dim roll(3) As String 'The first array
  4. roll(0) = "Yellow"
  5. roll(1)= "red"
  6. roll(2)= "green"
  7.  
  8. 'Populating the labelContent String variable with the
  9. 'data in the roll array
  10. For rollIndex As Integer = 0 To roll.Length - 1 
  11.   labelContent = labelContent + " " + roll(rollIndex)
  12. Next
  13.  
  14. Dim moreRolls(2) As String 'The second array
  15. moreRolls(0) = "Purple"
  16. moreRolls(1)= "Magenta"
  17.  
  18. 'Populating the labelContent String variable with the
  19. 'data in the moreRolls array
  20. For moreRollsIndex As Integer = 0 To moreRolls.Length - 1 
  21.   labelContent = labelContent + " " + moreRolls(moreRollsIndex)
  22. Next
  23.  
  24. 'Setting the label's text to the variable
  25. 'that contains the content we retrieved from the arrays
  26. myLabel.Text = labelContent
  27.  
Mar 1 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.