|
-
Sep 14th, 2009, 11:18 AM
#1
Thread Starter
New Member
looking in a array and loop it
Dear readers.
I have a script which works fine except that I would like to add a loop into a current loop.
I have some info that I will use.
X 123,920
Y -221,322
Z -90,2
X 143,920
Y -251,322
Z -20,2
and some more.
I want to add these in a array, but I have no clue on how to do that.
Secondly, I need to build a loop which I do not know how to do. But it should be something like this:
Code:
If MyPositionX() <= 123,920 AND MyPositionX() >= 123,915 THEN
'press the left button'
SendCommand(75,1);
SendCommand(75,0);
End If
and so on, it should check the array for EVERY x_as and if it matches (within a +5 difference) it should send the command.
Could someone please show me how to do this?
Best regards
Last edited by Warbringer; Sep 14th, 2009 at 11:21 AM.
-
Sep 14th, 2009, 11:25 AM
#2
Re: looking in a array and loop it
Have you looked in the codebank?
Here's a link to a post in that forum.
Last edited by abhijit; Sep 14th, 2009 at 11:27 AM.
Reason: Fixed link
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
-
Sep 14th, 2009, 11:35 AM
#3
Thread Starter
New Member
Re: looking in a array and loop it
cheer ill check it out, but main problem is I have no VBCODE knowledge at all, its just I am in desperate need of this modification (little script) lol but ill read and give it a try!
Thanks a lot abhijit!
-
Sep 14th, 2009, 11:38 AM
#4
Thread Starter
New Member
Re: looking in a array and loop it
 Originally Posted by abhijit
Have you looked in the codebank?
Here's a link to a post in that forum.
Yeah, way to difficult for me. I have none to little knowledge about VB lol.
Was actually looking for someone who can write me the script so I can play around with it and learn it. I am in desperate need for it lol.
Anyways ill check it out and hope I will understand it lol.
Basicly what i need is a array on which I can add or substract things like "192.20", "211.3", "532.33392"
and so on. THen the loop has to check if i am at that position i.e.
If myPosition() == in_array(myarray) Then
' code in here '
EndIf
-
Sep 14th, 2009, 11:53 AM
#5
Re: looking in a array and loop it
 Originally Posted by Warbringer
Yeah, way to difficult for me. I have none to little knowledge about VB lol.
Was actually looking for someone who can write me the script so I can play around with it and learn it. I am in desperate need for it lol.
Anyways ill check it out and hope I will understand it lol.
Basicly what i need is a array on which I can add or substract things like "192.20", "211.3", "532.33392"
and so on. THen the loop has to check if i am at that position i.e.
If myPosition() == in_array(myarray) Then
' code in here '
EndIf
Here's a simple script to populate an array.
Code:
Dim x() As String
Dim iCounter As Integer
Private Sub Command1_Click()
'Array Population
For iCounter = 1 To 10
ReDim Preserve x(iCounter)
x(iCounter) = Format(Now, "hh:mm:ss")
Next iCounter
'Array Looping
For iCounter = 1 To UBound(x)
Debug.Print x(iCounter)
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
-
Sep 14th, 2009, 12:26 PM
#6
Thread Starter
New Member
Re: looking in a array and loop it
I think we have a miscommunication lmao...
I dont need a script to put things INTO a array... I need one thatgets it out!
For example I have this:
array("5", "10", "15", "20");
now what i need is a loop like this:
If myNumber() <= 10 Then
print "hello"
End If
but what i dont understand is two things:
1. How to make a array with already known values like the above sample (array("5", "10", "15", "20")
2. How to make the loop look if one of the values IN the array, equals the myNumber value
Last edited by Warbringer; Sep 14th, 2009 at 12:31 PM.
-
Sep 14th, 2009, 12:43 PM
#7
Re: looking in a array and loop it
 Originally Posted by Warbringer
I think we have a miscommunication lmao...
I dont need a script to put things INTO a array... I need one thatgets it out!
For example I have this:
array("5", "10", "15", "20");
now what i need is a loop like this:
If myNumber() <= 10 Then
print "hello"
End If
but what i dont understand is two things:
1. How to make a array with already known values like the above sample (array("5", "10", "15", "20")
2. How to make the loop look if one of the values IN the array, equals the myNumber value
Are your known values in a table? Are you planning to hardcode your values in the code? Is the array single dimensional?
For checking against the loop, you can still use my code.
Code:
For iCounter = 1 To UBound(x)
if x(iCounter) <= 10 Then
debug.print "hello"
end if
Next
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
-
Sep 14th, 2009, 12:57 PM
#8
Thread Starter
New Member
Re: looking in a array and loop it
I know the values already yeah, and they need to be hardcoded (values never change).
-
Sep 14th, 2009, 01:02 PM
#9
Re: looking in a array and loop it
 Originally Posted by Warbringer
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
-
Sep 14th, 2009, 01:48 PM
#10
Thread Starter
New Member
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 ?
-
Sep 14th, 2009, 02:18 PM
#11
Re: looking in a array and loop it
 Originally Posted by Warbringer
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
-
Sep 14th, 2009, 02:42 PM
#12
Thread Starter
New Member
Re: looking in a array and loop it
Yeah i knew but can i do:
If x(iCounter) < x(0) - 5 AND x(iCounter) > 5 Then
Debug.print "Number between 10 and 5"
End If
so i am adding minus 5 to the value... ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|