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).![]() |
![]() |
|
Thread Tools |
![]() |
#1 |
Guest
Posts: n/a
|
![]()
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. |
![]() |
![]() |
#2 |
Guest
Posts: n/a
|
![]()
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". |
![]() |
![]() |
#3 |
Guest
Posts: n/a
|
![]()
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. |
![]() |
![]() |
#4 |
Guest
Posts: n/a
|
![]()
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. |
![]() |
![]() |
#5 |
Guest
Posts: n/a
|
![]()
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). |
![]() |
![]() |
#6 |
Guest
Posts: n/a
|
![]()
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 ![]() ![]() |
![]() |
![]() |
#7 |
Guest
Posts: n/a
|
![]()
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. |
![]() |
![]() |
#8 |
Moderator
Mega Poster
Join Date: Nov 2003
Location: The exiles of Kent
Posts: 2,184
|
![]()
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 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 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! |
![]() |
![]() |
![]() |
#9 |
Guest
Posts: n/a
|
![]()
Could you dumb it down a little more please?
![]() |
![]() |
![]() |
#10 |
Guest
Posts: n/a
|
![]()
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
|
![]() |
![]() |
|
|
![]() |
||||
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 |