Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


How to separate string values

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,3101
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to separate string values
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 How to separate string values - 5/24/2005 3:41:43 AM   
  Wylan

 

Posts: 2
Score: 0
Joined: 5/24/2005
From:
Status: offline
I would like to be able to separate vales contained in a string. I am trying to query servers for disk size and free space. If I run the following script on a machine with multiple drives, each string returns multiple values.

************************************

Const HARD_DISK = 3

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

For Each objDisk in colDisks

strsize = FormatNumber(objDisk.size /1024 /1024 /1024, 2)
strfree = FormatNumber(objDisk.freespace /1024 /1024 /1024, 2)


Wscript.Echo objDisk.deviceid
Wscript.Echo strsize
Wscript.Echo strfree


Next

*************************

If I run this on a machine with 2 drives, I will get this result in this order:

objDisk.deviceid "C:"
strsize "12.72"
strfree "2.74"

then

objDisk.deviceid "D:"
strsize "104.24"
strfree "92.86"

I need to be able to put the values into an SQL database, so the "C:" drive needs to have a separate name/value from the "D:" drive for the objDisk.deviceid, stsize, and srfree.

How or can I do this?

I hope I explained myself correctly.
 
 
Post #: 1
 
 Re: How to separate string values - 5/24/2005 6:25:38 AM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
you could insert an if statement after the for loop that checks to see if the system has more than 1 drive, and if so build a small array that assigns each drive a unique variable name, i.e. objDisk01, 02, etc.

(in reply to Wylan)
 
 
Post #: 2
 
 Re: How to separate string values - 5/25/2005 12:47:25 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
While this is not the best way, you could try this:

      

All depending on how you make your call to the SQL server, you can add that inside the if statement.

(in reply to Wylan)
 
 
Post #: 3
 
 Re: How to separate string values - 5/25/2005 6:37:29 AM   
  Wylan

 

Posts: 2
Score: 0
Joined: 5/24/2005
From:
Status: offline
Thanks, mbouchard

That is the way I am going to do it.

(in reply to Wylan)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to separate string values Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts