Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP need to line up things

Status
Not open for further replies.

xeo123

Programmer
Apr 13, 2006
4
US
Hey guyz,
i need to line up this things coming from a file like this

5.34 -14.278 -121.94 8.601 29.914 -304.47 0.55 0.0 5.45 5.55 -5.45 -5.55 342.56

and be written to a file lined up like this
5.34
-14.278
-121.94
8.601
29.914
-304.47
0.55
0.0
etc...
notice how the decimal points are all lined up
hope you can help me thanks
 
Is there a separator, or just some space(s) between the values?
Code:
Set fso = CreateObject("Scripting.FilesystemObject")
objFile = fso.OpenTextFile("numbers.log", 1, False)
strFileCont = objFile.ReadAll
objFile.Close
arrFileCont = Split(strFileCont, vbCrLf)

For each strRow in arrFileCont
    arrRow = Split(strRow, chr(32), -1, 1)
    For i = 0 to Ubound(arrRow)
        If Not arrRow(i) = "" Then
            y = y & Trim(arrRow(i)) & vbCrLf
        End if
    Next
    Wscript.Echo y 'or: z = z & y 
Next
Wscript.Echo z
Wscript.Quit
 
This was fun to figure out. Thanks for the challenge.

Code:
'==========================================================================
'
' NAME: DecimalAlignment.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.TheSpidersParlor.com[/URL]
' COPYWRITE (c) 2006 All Rights Reserved
' DATE  : 4/22/2006
'
' COMMENT: 
'
'==========================================================================

sample="5.34    -14.278 -121.94 8.601   29.914  -304.47 0.55    0.0     5.45    5.55    -5.45   -5.55   342.56"

sampleArray = Split(sample)

'First determine the padding we need.
LeftOfDecimal= 0
For Each Line in sampleArray
 If Len(Line) > 0 Then   
	Spacer = Split(Line,".")
	If Len(Spacer(0))>LeftOfDecimal Then
	    LeftOfDecimal = Len(Spacer(0))
    End If
 End If
Next

'next pad those lines that need it
For Each Line in sampleArray
 If Len(Line) > 0 Then   
	Spacer = Split(Line,".")
	If Len(Spacer(0))< LeftOfDecimal Then
		Padding =LeftOfDecimal - Len(Spacer(0))
		For Pad = 1 to Padding
		    Line = " " & Line
		Next
		Report = Report & Line & vbCrLf
    End If
 End If
Next
Wscript.Echo Report

I hope you find this post helpful.

Regards,

Mark
 
THANKS FOR THE HELP
CAN YOU DO IT WITHOUT USING UBOUND or SPLIT?
would appreciate it if you do have the answer
 
WHY?

Please be more specific regarding your need.

I hope you find this post helpful.

Regards,

Mark
 
I NEED TO LINE UP THE 1st Column so that all the decimals are straight

Option Explicit
Dim ts,num(14),fso,filename,i,large,small,b,c,total,average,x

Set fso= createobject("scripting.filesystemobject")
Filename = "D:\Numbers.txt"
Set ts = fso.opentextfile(filename,1,False)


large=num(i)
small=num(i)

For i=1 To 14
num(i)=ts.read(8)
Next
ts.close

Call Openfile(ts)
ts.writeblanklines 2
ts.write " x int(x) int(x*10+.5)/10"
ts.writeblanklines 1
ts.write " --- ------ ---------------"
ts.writeblanklines 1

For i=1 To 13

If csng(num(i))<csng(small) Then small=csng(num(i))
If csng(num(i))>csng(large) Then large=csng(num(i))
b = int(num(i))
c = int(csng(num(i))*10+.5)/10
x = Space(15-len(cstr(num(i))))
ts.write x&Space(15-len(cstr(num(i))))&num(i) &space(15-len(cstr(b)))&b&space(15-len(cstr(c)))&c
ts.writeblanklines 1

Next


ts.close

Sub OpenFile(ts)
Dim fso,FileName
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = "d:\Array.txt"
Set ts = fso.CreateTextFile(FileName)
End Sub
 
Did you test the code I posted? It does what you asked for. It reads the line of numbers, makes them each on a seperate line and lines up the decimals. So what is the problem?

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top