# if then variable

## Recommended Posts

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,

##### Share on other sites

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```

and I put it in a file

FileWriteLine(\$file, \$filewritecheck)

The 30th spot for \$answer10 becomes hex 0a (Line feed)

any ideas?

##### Share on other sites

and I put it in a file

FileWriteLine(\$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

##### Share on other sites

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

##### Share on other sites

Absolutely perfect.

Thanks

Ok I am attempting to figure out the StringFormat command

I need to right justify and left zero fill for 10 digits

so I thought this would work

\$answer1 = InputBox("Question", "What is the number", " ", "",-1, -1, 0, 0)

This only gives me the word error

##### Share on other sites

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.

##### Share on other sites

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)

Thanks again,

## Create an account

Register a new account

×

• Wiki

• Back

• Git