Results 1 to 12 of 12

Thread: looking in a array and loop it

Hybrid View

  1. #1
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: looking in a array and loop it

    Quote Originally Posted by Warbringer View Post
    I know the values already yeah, and they need to be hardcoded (values never change).
    In that case, one way I can think of is

    Code:
    'Declared Array
    Dim x(5) As String
    Dim iCounter As Integer
    
    Private Sub Command1_Click()
        'Assigned Values
        x(0) = "India": x(1) = "China": x(2) = "Brazil": x(3) = "Russia": x(4) = "Yemen"
        
        'Looped Through Array
        For iCounter = 0 To UBound(x) - 1
                If x(iCounter) = "China" Then
                    Debug.Print "Hello China"
                End If
        Next
        
    End Sub
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    7

    Re: looking in a array and loop it

    Okey, my code so far:

    Code:
    'Declared Array
    Dim x(6) As String
    Dim y(6) As String
    Dim iCounter As Integer
    
    Private Sub Command1_Click()
        'Assigned Values
        x(0) = "414,622": x(1) = "431,82": x(2) = "413,685": x(3) = "421,604": x(4) = "429,794": x(5) = "413,557"
    	y(0) = "-400,55": y(1) = "-392,107": y(2) = "-380,754": y(3) = "-377,159": y(4) = "-363,381": y(5) = "-360,796"
        
        'Looped Through Array
        For iCounter = 0 To UBound(x) - 1
    			'check if something equials the x array
                If x(iCounter) = "China" Then
                    Debug.Print "x found"
                End If
    			'check if something equials the y array
                If x(iCounter) = "China" Then
                    Debug.Print "y found"
                End If
        Next
        
    End Sub
    Is there something like 'BETWEEN' ? i.e.

    'check if something equials the x array
    If x(iCounter) BETWEEN x(iCounter) -5 And x(iCounter) +5 Then

    so i have a marge of 10 ?

  3. #3
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: looking in a array and loop it

    Quote Originally Posted by Warbringer View Post
    Okey, my code so far:

    Code:
    'Declared Array
    Dim x(6) As String
    Dim y(6) As String
    Dim iCounter As Integer
    
    Private Sub Command1_Click()
        'Assigned Values
        x(0) = "414,622": x(1) = "431,82": x(2) = "413,685": x(3) = "421,604": x(4) = "429,794": x(5) = "413,557"
    	y(0) = "-400,55": y(1) = "-392,107": y(2) = "-380,754": y(3) = "-377,159": y(4) = "-363,381": y(5) = "-360,796"
        
        'Looped Through Array
        For iCounter = 0 To UBound(x) - 1
    			'check if something equials the x array
                If x(iCounter) = "China" Then
                    Debug.Print "x found"
                End If
    			'check if something equials the y array
                If x(iCounter) = "China" Then
                    Debug.Print "y found"
                End If
        Next
        
    End Sub
    Is there something like 'BETWEEN' ? i.e.

    'check if something equials the x array
    If x(iCounter) BETWEEN x(iCounter) -5 And x(iCounter) +5 Then

    so i have a marge of 10 ?

    For numeric variables, you could always do a comparison using the standard comparison operators.

    Code:
    If x(iCounter) < 10 AND x(iCounter) > 5 Then
       Debug.print "Number between 10 and 5"
    End If
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

Posting Permissions

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



Click Here to Expand Forum to Full Width