SV650.org - SV650 & Gladius 650 Forum



Idle Banter For non SV and non bike related chat (and the odd bit of humour - but if any post isn't suitable it'll get deleted real quick).
There's also a "U" rating so please respect this. Newbies can also say "hello" here too.

Reply
 
Thread Tools
Old 03-02-06, 11:40 AM   #1
sharriso74
Guest
 
Posts: n/a
Default Script help

I'm trying to teach myself windows scripting but I'm a bit confused about one of the examples from the book I'm using
Option Explicit
'On Error Resume Next'

Const DriveType = 4
Dim colDrives
Dim drive

set colDrives = _
GetObject("Winmgmts:").ExecQuery _
("select DeviceID from Win32_LogicalDisk where DriveType =" & DriveType)

For Each drive in colDrives
WScript.Echo drive.DeviceID
Next

I understand that you use Dim to declare the variable and then you set what the variable is. But in this script I've declared a variable 'drive' but Idon't seem to set it.

The book doesn't explain this. Any help would be apreciated.
  Reply With Quote
Old 03-02-06, 11:47 AM   #2
Carsick
Guest
 
Posts: n/a
Default

I know nothing about windows scripting, btw.
The "drive" variable is set in the for each loop. It's set to the value of each entry in "colDrives".
  Reply With Quote
Old 03-02-06, 11:52 AM   #3
sharriso74
Guest
 
Posts: n/a
Default

Thanks thats been bugging me I just thought that For Each was just a way of looping the script.

Work is sending me on a course for this later I'm trying to get a bit of a head start so I can get the most out of the course.
  Reply With Quote
Old 03-02-06, 12:00 PM   #4
Carsick
Guest
 
Posts: n/a
Default

a standard for loop loops a known number of times.
a while loop loops until a specified condition occurs.
a for each loops over a collection of objects, assigning the current object to a variable at each iteration.

Those are the general loops and pretty much apply to any programming language.
  Reply With Quote
Old 03-02-06, 03:14 PM   #5
mysteryjimbo
Guest
 
Posts: n/a
Default

Looks reasonable enough to me. I can show you some working examples of my vbscript enough needed.

It may put some things in a working context rather than a following a book.

I have several from work and a couple at home. One at home renames all my photos based on the date they were taken (its embedded in the file, unlike date accessed etc) and stores them in a folder structure (Year->month->date).
  Reply With Quote
Old 03-02-06, 03:21 PM   #6
sharriso74
Guest
 
Posts: n/a
Default

That'd be great thanks. Trying to get away from doing support and move into the desktop architecture role.

Been looking after traders for 6 years now and I'm reaching the end of the line on that one
  Reply With Quote
Old 03-02-06, 03:28 PM   #7
mysteryjimbo
Guest
 
Posts: n/a
Default

I'll dig a few out for you.

One or two work using some third party dll's for email or ftp but you should get the idea. If you want to play with the dlls i can probably let you have them as well.
  Reply With Quote
Old 03-02-06, 03:33 PM   #8
BillyC
Moderator
Mega Poster
 
BillyC's Avatar
 
Join Date: Nov 2003
Location: The exiles of Kent
Posts: 2,184
Default

Hi there,

I've been programming VB in for about 8 years now, and programming for much longer, so I think I can help out a little bit here.

Books generally try and preach good-practise, which is very noble, but they don't often explain it well.

What you have declared here is:
Code:
dim colDrives
dim Drive
colDrives - this is a collection of Drives
Drive - an individual Drive.

By defining the collection, it could be assumed that you might want to reference an individual member of that collection - hence the two variables.

Later in your code we see:
Code:
For Each drive in colDrives 
WScript.Echo drive.DeviceID 
Next
This is a simple For-Next loop using VB objects. It is basically saying:

For Each item in itemcollection

So what we're saying is that every individual item in your collection, is referenced by your Drive variable.

Of course you didn't have to call it "Drive", you could've called it "Pineapples" or something suitably rediculous - but that wouldn't have been good practice

Does that help?
__________________
SV650 K3 - Gone. Now a member of the SV650.org Kawasaki brigade!
BillyC is offline   Reply With Quote
Old 03-02-06, 03:36 PM   #9
mysteryjimbo
Guest
 
Posts: n/a
Default

Could you dumb it down a little more please?
  Reply With Quote
Old 03-02-06, 03:40 PM   #10
sharriso74
Guest
 
Posts: n/a
Default

Dumb is good for me, I've given up on it today my habgover isn't shifting and Microsoft Press books aren't the most riviting
  Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP / MySQL coders out there, script help TSM Idle Banter 15 08-05-09 10:19 AM
Rainbow script that never was Defender Idle Banter 2 18-04-08 02:59 PM
windows script help needed timwilky Idle Banter 5 13-07-07 05:05 PM
Windows script help tricky Idle Banter 2 29-03-07 11:55 AM
Indian script monkeys timwilky Idle Banter 7 02-03-07 11:50 AM


All times are GMT. The time now is 12:11 PM.


Powered by vBulletin® - Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.