notta Posted February 26, 2007 Posted February 26, 2007 (edited) If I output data to a text file, how do you line up the second column so their all even? My first column are all variable length, so adding a couple of tabs after the first column will make the second column look like a staircase. lksad________________________sadasd sadklasdka________________________sadasdasd asdkasldk________________________asdasda asd________________________asdasd asdas________________________assdasd asdasdasdasdasd_________________________asdas asddddd______________________________asdasdasd Had to use the __ to keep my spacing. Thanks. Edited February 26, 2007 by notta
Moderators SmOke_N Posted February 26, 2007 Moderators Posted February 26, 2007 If I output data to a text file, how do you line up the second column so their all even? My first column are all variable length, so adding a couple of tabs after the first column will make the second column look like a staircase.lksad________________________sadasdsadklasdka________________________sadasdasdasdkasldk________________________asdasdaasd________________________asdasdasdas________________________assdasdasdasdasdasdasd_________________________asdasasddddd______________________________asdasdasdHad to use the __ to keep my spacing. Thanks.Well... you'd have to know the length of the longest string in the first column... then "space" that much over and add a space for every character less in each of the other strings. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
notta Posted February 26, 2007 Author Posted February 26, 2007 (edited) Thanks Smoke for the logic. I think I have all the calculations figured out, but how do I do custom spacing? I was assuming you were talking about using the send command with spaces, but that only does it in the active window and not in the file itself. FileWriteLine("c:\results.txt", $aRecords[$j] & @tab & Send("{SPACE " & $tempval &"}") & " columm2") I have searched the forums many times and I'm surprised that the custom spacing issue hasn't been asked more often. What do you do if @TAB, @LF, @CRLF isn't outputting your text exactly where you need it? Just point me in the right direction and I'll work on it. Thanks. Edited February 26, 2007 by notta
Moderators SmOke_N Posted February 26, 2007 Moderators Posted February 26, 2007 (edited) $LongestStringChars = 20 + 5 Dim $avArray[4] = ['', '1234567890123456789:', '1234567:', '123:'] Dim $aAddTo[4] = ['', 'This1','This2','This3'] Dim $LongestStringChars = (_ArrayStringGetLongest($avArray, 1) + 5), $ExampleString = '' For $iCC = 1 To UBound($avArray) - 1 If StringLen($avArray[$iCC]) < $LongestStringChars Then Do $avArray[$iCC] &= ' ' Until StringLen($avArray[$iCC]) = $LongestStringChars EndIf $ExampleString &= $avArray[$iCC] & $aAddTo[$iCC] & @CRLF Next ConsoleWrite(@LF & $ExampleString & @LF) Func _ArrayStringGetLongest($aArray, $iBase = 1) If IsArray($aArray) = 0 Then Return SetError(1, 0, 0) Local $nNum = 0 For $iCC = $iBase To UBound($aArray) - 1 If StringLen($aArray[$iCC]) > $nNum Then $nNum = StringLen($aArray[$iCC]) Next Return Int($nNum) EndFunc Edited February 26, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Moderators SmOke_N Posted March 8, 2007 Moderators Posted March 8, 2007 As requested, a break down of what I wrote and what it is doingDim $avArray[4] = ['', '1234567890123456789:', '1234567:', '123:'];I don't have your array so I had to make my own Dim $aAddTo[4] = ['', 'This1','This2','This3'];This is the 2nd part, what's added after the first part Dim $LongestStringChars = (_ArrayStringGetLongest($avArray, 1) + 5), $ExampleString = '' ;$LongestStringChars, finds the longest string and adds 5 to the number so that we have an even spread out For $iCC = 1 To UBound($avArray) - 1;Base is starting at 1 and going to the max element index of the array If StringLen($avArray[$iCC]) < $LongestStringChars Then;If the length of the current string is less than the max lenght we found earlier, then we need to add spaces Do $avArray[$iCC] &= ' ';Adding a space after the string, &= is String = String & Space Until StringLen($avArray[$iCC]) = $LongestStringChars;Keep adding spaces until the new string len of the array element is the same as the longest number + 5 EndIf $ExampleString &= $avArray[$iCC] & $aAddTo[$iCC] & @CRLF;Adding all my array elements into 1 string that can be saved or written to a file or clipboard or sent Next;Keep looping until Max Element Index is reached ConsoleWrite(@LF & $ExampleString & @LF);Writing the output to the console so you can see the seperation Func _ArrayStringGetLongest($aArray, $iBase = 1) If IsArray($aArray) = 0 Then Return SetError(1, 0, 0);If you don't pass an array here, it will error and return 0 Local $nNum = 0;declaring my variable For $iCC = $iBase To UBound($aArray) - 1;Base to Max Element Index If StringLen($aArray[$iCC]) > $nNum Then $nNum = StringLen($aArray[$iCC]);Keep going through the loop, and if 1 elment string lenght is longer, that's the new max string length Next;Keep looping until Max Element Index is reached Return Int($nNum);Return the new max string length as an integer EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now