johnpayback
IS-IT--Management
I believe I've gotten most of the code but I cannot figure out a way to get my text file formatted the way I would like it. Below is what I want my text file to look like.
Here is my code so far. I'm at a loss right now as how to write the output to look like the text above. How can I do this?
BS/Computer Science
Code:
Server Name Free Space
server1 24%
server2 34%
server3 87%
server4 73%
server5 75%
Here is my code so far. I'm at a loss right now as how to write the output to look like the text above. How can I do this?
Code:
Dim objConn, objrs, resultSet, SQLStmt
Dim objFSO, objFile
'Database Connection String
Set objConn = CreateObject("ADODB.Connection")
Set objrs = CreateObject("ADODB.Recordset")
objConn.Open "Driver={SQL Server};" & _
"Server=SvrName\Instance;" & _
"Database=DBName;" & _
"user id=username;" & _
"password=password;"
'Create text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Documents and Settings\username\Desktop\output.txt", True)
'Create Array from SQL
Dim SQLArray 'SQLArray(Capacity, Available)
'Populate SQLArray
Set SQLStmt = CreateObject("ADODB.Command")
SQLStmt.CommandText = "select distinct system_id, capacity, available, cast(round(cast(available as decimal)/cast(capacity as decimal) * 100, 0) as integer) as FreeSpace from storage_info(nolock)"
SQLStmt.CommandType = 1
Set SQLStmt.ActiveConnection = objConn
objrs.Open SQLStmt
SQLArray = objrs.GetRows(,,"FreeSpace")
objrs.Close
'Create Array from list
Dim SVRArray(4)
SVRArray(0) = "server1"
SVRArray(1) = "server2"
SVRArray(2) = "server3"
SVRArray(3) = "server4"
SVRArray(4) = "server5"
'Begin writing text file
objFile.Writeline ("Server Name" & vbTab & vbTab & vbTab & "Free Space")
Dim i, j
For i=0 to ubound(SVRArray,1)
For j=0 to ubound(SQLArray,1)
objFile.Writeline SVRArray(i) & SQLArray(j)
Next
Next
'Clean up
objrs.Close
Set objrs = Nothing
Set objConn = Nothing
BS/Computer Science