Re: Script output by McKirahan
McKirahan
Thu Jan 26 09:36:36 CST 2006
"Amanda" <abstuckey@hotmail.com> wrote in message
news:1138287517.669062.196730@g43g2000cwa.googlegroups.com...
> I have a vbscript that I run from a command line. Instead of writing
> the code to output it to a file, I use the >file.txt after my script to
> output to a file. I am trying to get the columns to line up within
> that output. So I guess better worded my question would be, Can I
> specify what location the output starts at?
>
> For example:
>
> My current output:
> user ; yes ; date
> username ; no ; date
>
> I would like it to look like this:
> user ; yes ; date
> username ; no ; date
>
> So, when I output the semi colons, I would like to be able to say at
> what position in the line they should start.
>
> If this cannot be done, I will look inot creating an HTML table
> instead.
>
>
> Thanks,
> Amanda
>
This will work as-is; watch for word-wrap.
You should be able to adapt it for your need.
Option Explicit
Dim strTXT
strTXT = "user ; yes ; date" & vbCrLf
strTXT = strTXT & "username ; no ; date" & vbCrLf
WScript.Echo strTXT & vbCrLf & Proportional_Spacing(strTXT)
Function Proportional_Spacing(strTXT)
Proportional_Spacing = ""
'*
'* Declare Constants
'*
Const cSEP = "; "
'*
'* Declare Variables
'*
Dim arrCOL, intCOL, strCOL
Dim arrLEN, intLEN
Dim arrROW, strROW, intROW
Dim strSPC
Dim strVAL
strVAL = ""
'*
'* Identify the length of the longest value in each column
'*
arrROW = Split(strTXT,vbCrLf)
For intROW = 0 To UBound(arrROW)
strROW = arrROW(intROW)
arrCOL = Split(strROW,cSEP)
'*
If intROW = 0 Then
ReDim arrLEN(UBound(arrCOL))
For intLEN = 0 To UBound(arrLEN)
arrLEN(intLEN) = 0
Next
End If
'*
For intCOL = 0 To UBound(arrCOL)
strCOL = Trim(arrCOL(intCOL))
If Len(strCOL) > arrLEN(intCOL) Then
arrLEN(intCOL) = Len(strCOL)
End If
Next
Next
'*
'* Reconstruct string while adjusting spacing of each column
'*
For intROW = 0 To UBound(arrROW)
strROW = arrROW(intROW)
arrCOL = Split(strROW,";")
For intCOL = 0 To UBound(arrCOL)
strCOL = Trim(arrCOL(intCOL))
If intCOL > 0 Then strVAL = strVAL & cSEP
strSPC = Space(arrLEN(intCOL)-Len(strCOL)+1)
strVAL = strVAL & strCOL & strSPC
Next
strVAL = strVAL & vbCrLf
Next
'*
'* Return Result
'*
Proportional_Spacing = strVAL
End Function