SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Format Command question

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Format Command question
Author Message
Brent



Joined: 20 Feb 2002
Posts: 57

Post Format Command question Reply with quote

When using the Format command to pad string with spaces,
what is the format symbol? The symbol ? does not
appear to work. Whether I put the question mark in
quotes or not, I get a ? instead of the data I have
put into the field or a space like I need.

Wed Jul 16, 2003 2:18 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7968

Post Re: Format Command question Reply with quote

Format cannot be used to pad strings. It can be used with dates, times and numbers to convert them to a formated string.

To pad a string with spaces create your user-defined statement such as RightPad
with 2 parameters: old_string, new_length
In the statement code copy the following

Dim new_string, string
Dim pad_string, string
Dim pad_length, number
Dim str_length, number

Length old_string, str_length
Subtract new_length, str_length, pad_length
Fill " ", pad_length, pad_string
Concat old_string, pad_string, new_string
Return new_string

Use your new statement just as you use built-in statements

PS. To create a new statement use Tools menu then Script Library and then click the New button.

: When using the Format command to pad string with spaces,
: what is the format symbol? The symbol ? does not
: appear to work. Whether I put the question mark in
: quotes or not, I get a ? instead of the data I have
: put into the field or a space like I need.

Wed Jul 16, 2003 3:28 pm View user's profile Send private message
Brent



Joined: 20 Feb 2002
Posts: 57

Post Re: Format Command question Reply with quote

I tried this, but it didn't work the way I need it to.
I need to pad the left side of the variable with
spaces. Is there a way to positionally move data
into a string variable?

: Format cannot be used to pad strings. It can be used with dates, times and
: numbers to convert them to a formated string.

: To pad a string with spaces create your user-defined statement such as
: RightPad
: with 2 parameters: old_string, new_length
: In the statement code copy the following

: Dim new_string, string
: Dim pad_string, string
: Dim pad_length, number
: Dim str_length, number

: Length old_string, str_length
: Subtract new_length, str_length, pad_length
: Fill " ", pad_length, pad_string
: Concat old_string, pad_string, new_string
: Return new_string

: Use your new statement just as you use built-in statements

: PS. To create a new statement use Tools menu then Script Library and then
: click the New button.

Wed Jul 16, 2003 4:30 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7968

Post Re: Format Command question Reply with quote

The only difference is that you do
Concat pad_string, old_string, new_string
instead of
Concat old_string, pad_string, new_string

: I tried this, but it didn't work the way I need it to.
: I need to pad the left side of the variable with
: spaces. Is there a way to positionally move data
: into a string variable?

Wed Jul 16, 2003 5:15 pm View user's profile Send private message
Brent



Joined: 20 Feb 2002
Posts: 57

Post Re: Format Command question Reply with quote

I wrote a test program to simulate the problem that I
am having. This is the code:

---------------------------------------------------------------
// test_number will simulate the number from the database
dim test_number number
dim test_string string
dim test_length number

MessageBox "Welcome to the Research Program!"
InputBox "Please enter a 2 decimal number:" "edit" test_number

// The number is pulled into a string by the database get command
Set test_string test_number

// Since the database field is a number size 9 with 2 decimals,
// I need to format the number before I save it into a file
Format test_string,0000000.00,test_string
MessageBox test_string

// This would be fine, but the numbers could be negative.
// If the length of the field is 10 (no negative sign), I need to
// pad one space onto the begining of the field.
LeftPad(test_string,11,test_string)
MessageBox test_string
---------------------------------------------------------------

the LeftPad logic looks like this:

---------------------------------------------------------------
Dim new_string, string
Dim pad_string, string
Dim pad_length, number
Dim str_length, number

Length old_string, str_length
Subtract new_length, str_length, pad_length
Fill " ", pad_length, pad_string
Concat pad_string, old_string, new_string
Return new_string
---------------------------------------------------------------

Instead of padding an extra space onto the beginning,
all the leading zeros disappear from the string, with
and without the negative sign. Where am I going wrong?

: The only difference is that you do
: Concat pad_string, old_string, new_string
: instead of
: Concat old_string, pad_string, new_string

Thu Jul 17, 2003 10:42 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7968

Post Re: Format Command question Reply with quote

There are several problems in your script. Here is the corrected version

// test_number will simulate the number from the database
dim test_number, number
dim test_string, string

MessageBox "Welcome to the Research Program!"
InputBox "Please enter a 2 decimal number:", "EDIT", test_number

// Since the database field is a number size 9 with 2 decimals,
// I need to format the number before I save it into a file
Format test_number, "0000000.00", test_string
MessageBox test_string

// This would be fine, but the numbers could be negative.
// If the length of the field is 10 (no negative sign), I need to
// pad one space onto the begining of the field.
LeftPad test_string, 11, test_string
MessageBox test_string

: I wrote a test program to simulate the problem that I
: am having. This is the code:
: ---------------------------------------------------------------
: // test_number will simulate the number from the database
: dim test_number number
: dim test_string string
: dim test_length number

: MessageBox "Welcome to the Research Program!"
: InputBox "Please enter a 2 decimal number:" "edit"
: test_number

: // The number is pulled into a string by the database get command
: Set test_string test_number

: // Since the database field is a number size 9 with 2 decimals,
: // I need to format the number before I save it into a file
: Format test_string,0000000.00,test_string
: MessageBox test_string

: // This would be fine, but the numbers could be negative.
: // If the length of the field is 10 (no negative sign), I need to
: // pad one space onto the begining of the field.
: LeftPad(test_string,11,test_string)
: MessageBox test_string
: ---------------------------------------------------------------

: the LeftPad logic looks like this:
: ---------------------------------------------------------------
: Dim new_string, string
: Dim pad_string, string
: Dim pad_length, number
: Dim str_length, number

: Length old_string, str_length
: Subtract new_length, str_length, pad_length
: Fill " ", pad_length, pad_string
: Concat pad_string, old_string, new_string
: Return new_string
: ---------------------------------------------------------------

: Instead of padding an extra space onto the beginning,
: all the leading zeros disappear from the string, with
: and without the negative sign. Where am I going wrong?

Thu Jul 17, 2003 11:25 am View user's profile Send private message
Brent



Joined: 20 Feb 2002
Posts: 57

Post Re: Format Command question Reply with quote

I regret to say that this code still works the same
way, the leading zeros are dropped when the last
MessageBox is displayed. The message box just
before the last one shows the number correctly, missing
one blank space if the number is not negative.

: There are several problems in your script. Here is the corrected version

: // test_number will simulate the number from the database
: dim test_number, number
: dim test_string, string

: MessageBox "Welcome to the Research Program!"
: InputBox "Please enter a 2 decimal number:", "EDIT",
: test_number

: // Since the database field is a number size 9 with 2 decimals,
: // I need to format the number before I save it into a file
: Format test_number, "0000000.00", test_string
: MessageBox test_string

: // This would be fine, but the numbers could be negative.
: // If the length of the field is 10 (no negative sign), I need to
: // pad one space onto the begining of the field.
: LeftPad test_string, 11, test_string
: MessageBox test_string

Thu Jul 17, 2003 11:53 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7968

Post Re: Format Command question Reply with quote

This is because the argument is automatically converted to a number

To make it really simply, remove last 2 lines of the script and you will get what you want

: I regret to say that this code still works the same
: way, the leading zeros are dropped when the last
: MessageBox is displayed. The message box just
: before the last one shows the number correctly, missing
: one blank space if the number is not negative.


Thu Jul 17, 2003 12:09 pm View user's profile Send private message
Brent



Joined: 20 Feb 2002
Posts: 57

Post Re: Format Command question Reply with quote

Thank you for the help. I have found a work around.
Here is what I decided to do instead of the LeftPad
function:

Length test_string,test_length
IsEqual test_length,10,length_test
If (length_test,AppendOneSpace,DoNotAppendOneSpace)
AppendOneSpace:

Concat " ", test_string, test_string

goto EndAppendSpaceIf
DoNotAppendOneSpace:

EndAppendSpaceIf:

This will give me 0000033.55 and

-0000033.55
instead of

0000033.55 and

-0000033.55
.

: This is because the argument is automatically converted to a number

: To make it really simply, remove last 2 lines of the script and you will get
: what you want

Thu Jul 17, 2003 1:10 pm View user's profile Send private message
Brent



Joined: 20 Feb 2002
Posts: 57

Post Re: Format Command question Reply with quote

It looks like the spacing in my response is not being
displayed correctly.

I just wanted to point out that using my alternative
code, that I got the leading space in the variable.

: This is because the argument is automatically converted to a number

: To make it really simply, remove last 2 lines of the script and you will get
: what you want

Thu Jul 17, 2003 1:18 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.