|
-
Sep 14th, 2000, 01:08 AM
#1
Thread Starter
Lively Member
Hello for each next statement)
what is this statement does and
how to use and plz example of if
Bye
-
Sep 14th, 2000, 03:09 AM
#2
Junior Member
Hi,
U usually use 'for' loops this way:
for iCounter=... to ...
'code to be repeated
Next i
This is especially useful when U know how many times U want to repeat some code and/or when the code is dependent on iCounter.
But in some cases U need to do some operation on every object in a collection, doesn 't matter how many objects are there
Then 'for each ...' statement is very helpful.
The syntax is:
For each (var1 - usually object type) in (collection of objects of var1 type)
'repeated code
next (var1)
Want an example? Here is one:
Dim rst As Recordset
Dim fld As Field
Set rst = New ADODB.Recordset
rst.OpenRecordset "Customers", dbOpenDynaset 'Customers is a name of a table in a database
'(A)
For Each fld In rst.Fields
MsgBox fld.Name
Next fld
rst.Fields.Delete rst.Fields(3).Name
'(B)
For Each fld In rst.Fields
MsgBox fld.Name
Next fld
in the example above, in part A, U get names of all fields in rst (columns' names);
then U remove one column, third one
and again U use for each statement to obtain names of all fields after deleting.
To do the same with 'for i = ... to ...' U should know how many fields there are in the recordset before and after deleting
The 'for each' statement is very nice, I think U'll like it
Best wishes,
Syl
-
Sep 14th, 2000, 03:30 AM
#3
transcendental analytic
For each can also be used with arrays stored in variants.
Code:
For each item in VariantArray
...
Next item
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 15th, 2000, 06:38 AM
#4
Conquistador
Originally posted by kedaman
For each can also be used with arrays stored in variants.
Code:
For each item in VariantArray
...
Next item
i didn't know you could do that!
that helps me out with some other code too!
-
Sep 15th, 2000, 06:48 AM
#5
transcendental analytic
Have fun
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 18th, 2000, 01:59 AM
#6
Conquistador
how would i go about setting values of an array?
-
Sep 18th, 2000, 03:03 AM
#7
Hyperactive Member
Well guys, I really need your help..
I am looking for a way to do
for each ...
but for all the animations in a microsoft agent character.
any idea ?
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 18th, 2000, 03:49 AM
#8
transcendental analytic
set YourArray(index)=yourobject
da_silvy, that's what you meant?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 18th, 2000, 03:50 AM
#9
Conquistador
try this:
Code:
For Each AnimationName In Character.AnimationNames
List1.AddItem AnimationName
Next
tell me if it works!
-
Sep 18th, 2000, 03:51 AM
#10
Conquistador
Originally posted by kedaman
set YourArray(index)=yourobject
da_silvy, that's what you meant?
yes, but it does not work for me
Code:
for i = 1 to 20
myArray(i) = i
next i
why not?
-
Sep 18th, 2000, 03:56 AM
#11
Hyperactive Member
thank you da_silvy !!
I don't get it, this property does not appear in the drop down ..
anyway, thank you it is working.
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 18th, 2000, 04:01 AM
#12
Conquistador
that's a pleasure, but i don't know why it doesn't appear in the drop down box, must be a little secret of microsoft's
-
Sep 18th, 2000, 04:04 AM
#13
Hyperactive Member
Well, probably, anyway good to have people like you around :-)
Thanks
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 18th, 2000, 04:16 AM
#14
Conquistador
what are you using the agent for?
-
Sep 18th, 2000, 04:24 AM
#15
Hyperactive Member
just make a "virtual firend" on the desktop ..
It reads me stuff that I put in the clipboard, and from time to time do/say stuff randomly.
I have another question that I just posted, maybe you can help me, I need to know how to use the microsoft voice recognition .., I can't make it "listen" to me (I know that you can use the commands with the characters, but I want to use the voice recognition, it seems more flexible).
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 18th, 2000, 04:32 AM
#16
transcendental analytic
dasilvy, it should. What type of array are you using?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 18th, 2000, 04:34 AM
#17
Conquistador
i don't know anything about it???
-
Sep 18th, 2000, 04:37 AM
#18
Conquistador
my last message was for kedaman!
and now for asabi
Originally posted by asabi
just make a "virtual firend" on the desktop ..
It reads me stuff that I put in the clipboard, and from time to time do/say stuff randomly.
I have another question that I just posted, maybe you can help me, I need to know how to use the microsoft voice recognition .., I can't make it "listen" to me (I know that you can use the commands with the characters, but I want to use the voice recognition, it seems more flexible).
you could read up about recognition on the microsoft developers website, and i will try to put some code together for you. From memory, you have to add a function to the menu, then have code for it, and assign a voice command to it.
-
Sep 18th, 2000, 04:39 AM
#19
Conquistador
i would also suggest downloading the complete documentation, as that is very technical (too hard in some places) and will help you will an answer.
-
Sep 18th, 2000, 04:49 AM
#20
transcendental analytic
Let's make a test da_silvy:
Code:
Dim A as variant, B() as byte, C as variant
A=Array(1,3,7)
Redim B(2)
B(2)=A(2)
C=B
Msgbox A(2) & "," & B(2) & "," & C(0)
does this work for you?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 18th, 2000, 04:56 AM
#21
Hyperactive Member
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 19th, 2000, 02:50 AM
#22
Conquistador
that example works, but how do i fix this?
Code:
Dim A As Variant
Private Sub Command1_Click()
For Each Item In A
List1.AddItem A
Next
End Sub
Private Sub Form_Load()
For i = 0 To 20
A(i) = i
Next
End Sub
i want a(20) to = 20
but how?
-
Sep 19th, 2000, 03:03 AM
#23
Junior Member
try something like that:
Code:
Dim a(20) As Variant
For i = 0 To 20
a(i) = i
Next i
or
Code:
Dim a() As Variant
ReDim Preserve a(1) As Variant
For i = 0 To 20
ReDim Preserve a(UBound(a) + 1) As Variant
a(i) = i
Next i
-
Sep 20th, 2000, 04:07 AM
#24
Conquistador
yes, thanks, that was what i was looking for
-
Sep 20th, 2000, 04:37 AM
#25
transcendental analytic
That's an array of variants, not an array stored in a variant! not really what you wanted or?
Anyway here's the array variant, in your code:
Code:
Dim A As Variant
Private Sub Command1_Click()
For Each Item In A
List1.AddItem Item'not A
Next
End Sub
Private Sub Form_Load()
Dim B(20) as integer
For i = 0 To 20
B(i) = i
Next
A=B
End Sub
note, arrays of variants are really slow, don't use them, i made it a integer array for your purpose.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 20th, 2000, 09:09 PM
#26
Conquistador
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
|