Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 02-09-2005, 08:15 AM   #1 (permalink)
Psycho
 
Location: the hills of aquafina.
[VBscript] Function cannot return a collection

I've made a small function which gets the system drives filters them based on ready state and also if they are not a mapped network drive and then returns the collection to the calling code, like so:

Code:
Function getLocalFixedDrives()
	Set filesys = CreateObject("Scripting.FileSystemObject")
	Set driveColl = filesys.Drives
	Set LocalFixedDrivesColl = CreateObject("Scripting.Dictionary")
	counter = 0
	For each drv in driveColl
		If drv.IsReady = true Then
			If drv.DriveType <> 3 Then '<- 0=unknown, 1=removable, 2=Fixed, 3=network, 4=CD-ROM, 5=RAMDisk		
				LocalFixedDrivesColl.add counter, drv.RootFolder
				counter = counter + 1
			End if
		End if
	Next
	'below is the problem
	getLocalFixedDrives = LocalFixedDrivesColl
End Function
My problem is when I need to return my 'filtered collection' to the calling code, which is this line:
Code:
getLocalFixedDrives = LocalFixedDrivesColl
I'm getting an error which states it's an invalid property assignment or wrong number of arguements. But since VBScript forces you to 'return' your function values in the above manner, it's getting confused on what I need to do. I've been searching the intarweb for the last couple of days trying to find an alternate solution, but none were found. Help!!

Wouldn't it just be easier it VBscript utilized the 'return' statement for returning objects from methods?!?!? argh!
__________________
"The problem with quick and dirty, as some people have said, is that the dirty remains long after the quick has been forgotten" - Steve McConnell

Last edited by cartmen34; 02-09-2005 at 09:00 AM.. Reason: spelling, it is a biatch
cartmen34 is offline  
Old 02-09-2005, 12:34 PM   #2 (permalink)
zen_tom
Guest
 
Try
Code:
set getLocalFixedDrives = LocalFixedDrivesColl
Because it's an object (rather than a regular variable) you need to use set when assigning it to something.

You might also want to tell the function what kind of value it's going to return

as in

Code:
Function myfunction() as MyClass
 
Old 02-12-2005, 12:44 PM   #3 (permalink)
Psycho
 
Location: the hills of aquafina.
awesome. thanks zen_tom!
__________________
"The problem with quick and dirty, as some people have said, is that the dirty remains long after the quick has been forgotten" - Steve McConnell
cartmen34 is offline  
 

Tags
collection, funtion, return, vbscript


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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 03:29 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62