By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

visual basics string manipulation.

P: 1
Dim animals() As String = {"Cat", "Dog", "Fish", "Horse", "Donkey", "Giraffe", "Lion", "Snake", "Elephant", "Tiger", "Bear"}


Using a For Loop, which code can i use to display these animals in a MsgBox [(one by one)]
Aug 21 '14 #1
Share this Question
Share on Google+
1 Reply


IronRazer
P: 82
Hi,
You can use a For Each loop or a For Next loop to iterate through all the elements of the string array.

Here is an example using a For Each loop

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim animals() As String = {"Cat", "Dog", "Fish", "Horse", "Donkey", "Giraffe", "Lion", "Snake", "Elephant", "Tiger", "Bear"}
  5.  
  6.         For Each animal As String In animals
  7.             MessageBox.Show(animal)
  8.         Next
  9.     End Sub
  10. End Class
  11.  
Here is an example using a For Next loop.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim animals() As String = {"Cat", "Dog", "Fish", "Horse", "Donkey", "Giraffe", "Lion", "Snake", "Elephant", "Tiger", "Bear"}
  5.  
  6.         For i As Integer = 0 To animals.Length - 1
  7.             MessageBox.Show(animals(i))
  8.         Next
  9.     End Sub
  10. End Class
  11.  
Aug 21 '14 #2

Post your reply

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