Santron Posted July 3, 2009 Share Posted July 3, 2009 I need help solving this problem. I need to add a count to a file. I have 30 spaces and it must be left justified and right space filled. for instance: if $a = 2 then $answer10 = "1____________________________" if $a = 3 then $answer10 = "2____________________________" if $a = 4 then $answer10 = "3____________________________" if $a = 5 then $answer10 = "4____________________________" if $a = 6 then $answer10 = "5____________________________" if $a = 7 then $answer10 = "6____________________________" if $a = 8 then $answer10 = "7____________________________" if $a = 9 then $answer10 = "8____________________________" if $a = 10 then $answer10 = "9____________________________" _ represents a space If $a is a 8 then $answer10 = 7 and 29 spaces If $a is a 20 then $answer10 = 19 and 28 spaces I am looking for a routine that will do this for all possible numbers 1 - 999999999999999999999999999999 Thanks, Link to comment Share on other sites More sharing options...
Santron Posted July 3, 2009 Author Share Posted July 3, 2009 StringFormat() will do what you want. $answer10 = StringFormat("%-30s\n", $a-1) Here's an example. For $i = 2 To 11 ConsoleWrite(StringFormat("%-30s\n", $i-1)) Next Thank you so much for the fast reply. When I add $answer10 = StringFormat("%-30s\n", $a-1) and I put it in a file $filewritecheck = $answer1 & $answer2 & $answer3 & $answer10 & $answer4 FileWriteLine($file, $filewritecheck) The 30th spot for $answer10 becomes hex 0a (Line feed) any ideas? Link to comment Share on other sites More sharing options...
Santron Posted July 4, 2009 Author Share Posted July 4, 2009 Thank you so much for the fast reply. When I add$answer10 = StringFormat("%-30s\n", $a-1)and I put it in a file$filewritecheck = $answer1 & $answer2 & $answer3 & $answer10 & $answer4FileWriteLine($file, $filewritecheck)The 30th spot for $answer10 becomes hex 0a (Line feed)any ideas?I was incorrect it adds hex 0a on the 31st spot then puts $answer4 in the line Link to comment Share on other sites More sharing options...
Santron Posted July 4, 2009 Author Share Posted July 4, 2009 Yeah, I had the format wrong. It was adding a Line Feed after the spaces. I think this is right. StringFormat("%-30s", $i-1) Absolutely perfect. Thanks Link to comment Share on other sites More sharing options...
Santron Posted July 4, 2009 Author Share Posted July 4, 2009 Absolutely perfect.ThanksOk I am attempting to figure out the StringFormat commandI need to right justify and left zero fill for 10 digitsso I thought this would work$answer1 = InputBox("Question", "What is the number", " ", "",-1, -1, 0, 0)$lenanswer1 = StringFormat("%010d", $answer1)This only gives me the word error Link to comment Share on other sites More sharing options...
Spiff59 Posted July 4, 2009 Share Posted July 4, 2009 There's also the old-fashioned way: Local $spaces = " " $z = StringLeft("7" & $spaces, 30) Local $zeros = "0000000000" $z = StringRight($zeros & "123", 10) For some reason it's a lot faster, if that matters. Link to comment Share on other sites More sharing options...
Santron Posted July 6, 2009 Author Share Posted July 6, 2009 That Stringformat is correct. There must be something else wrong. If I enter 1, I get 0000000001. If I enter 12, I get 0000000012. If I enter 123, I get 0000000123. $answer1 = InputBox("Question", "What is the number", " ", "",-1, -1, 0, 0) $lenanswer1 = StringFormat("%010d", $answer1) ConsoleWrite($lenanswer1 & @CRLF) Thanks again, I was writing $answer1 when I should have been writing $lenanswer1 Link to comment Share on other sites More sharing options...
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