×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

use for...to.. next in stead of for each..next

use for...to.. next in stead of for each..next

use for...to.. next in stead of for each..next

(OP)
hello everybody,
I would like to know how to use for...to.. next in stead of for each..next
for example :

CODE -->

Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objDrive In objFSO.Drives
  WScript.Echo objDrive.DriveLetter
Next 

I want the same result but with using For..To..Next

CODE -->

Set objFSO = CreateObject("Scripting.FileSystemObject")
nn = objFSO.Drives.Count
For i=1 to nn
  WScript.Echo .............  ' I want to get same result obove
Next 

thank you all

RE: use for...to.. next in stead of for each..next

You can't natively, but you could always use the "For Each ... In ..." loop to create an array if you really needed it in an array. What are you trying to achieve?

RE: use for...to.. next in stead of for each..next

(OP)
thank you for your quick response.. that's exactly the point that I want to use it as an array to use it for other purposes in other parts of my application.

RE: use for...to.. next in stead of for each..next

(OP)
this is what I used to fill the array, but is there any faster or better way to do this?

CODE --> vbscript

Set objFSO = CreateObject("Scripting.FileSystemObject")

nn = objFSO.Drives.Count
Dim arr()
ReDim arr(nn)
x=0
For Each objDrive In objFSO.Drives
	x=x+1
        arr(x)= objDrive.DriveLetter
 Next 

RE: use for...to.. next in stead of for each..next

Both of which reiterate that you need to load an array ...

The problem here is that the item Index used for the FileSystemObject's Files collection is the filename, not a number, so we cannot use for ... next with it ...

But here's a question: do you have a good reason why you want to use For Next, or is it just a personal preference?

RE: use for...to.. next in stead of for each..next

(OP)
Actually I am collecting data from different locations with different types of data and at the end I do some calculations and statistics then I flush the data according to user choice either to text file,excel file or SQL database, in fact I can output them to a temp text file and reuse it after choice but I am trying to avoid writing the data anywhere before selection for security reasons and for more speed in execution as writing to memory is faster than writing to storage.

thank you

RE: use for...to.. next in stead of for each..next

(OP)
thank you guitarzan for the links


regards

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close