visual basics string manipulation.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Weezy F Dixx
    New Member
    • Aug 2014
    • 1

    visual basics string manipulation.

    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)]
  • IronRazer
    New Member
    • Jan 2013
    • 83

    #2
    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

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim animals() As String = {"Cat", "Dog", "Fish", "Horse", "Donkey", "Giraffe", "Lion", "Snake", "Elephant", "Tiger", "Bear"}
    
            For Each animal As String In animals
                MessageBox.Show(animal)
            Next
        End Sub
    End Class
    Here is an example using a For Next loop.

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim animals() As String = {"Cat", "Dog", "Fish", "Horse", "Donkey", "Giraffe", "Lion", "Snake", "Elephant", "Tiger", "Bear"}
    
            For i As Integer = 0 To animals.Length - 1
                MessageBox.Show(animals(i))
            Next
        End Sub
    End Class

    Comment

    Working...