Source language: Translate to:

change display of integer variable?

General questions about NeoBook

Moderator: Neosoft Support

change display of integer variable?

Postby yanzco » Fri Aug 01, 2014 7:00 pm

hello guys. i'm not exactly sure how to say it.

but i want a variable as an integer to be displayed something like below.

ID : [Hexdb.Students.ID] = ID : 0001
ID : [Hexdb.Students.ID] = ID : 0024
ID : [Hexdb.Students.ID] = ID : 0107

instead of

ID : [Hexdb.Students.ID] = ID : 1
ID : [Hexdb.Students.ID] = ID : 24
ID : [Hexdb.Students.ID] = ID : 107

maybe a workaround would be
ID : [ZZZ][Hexdb.Students.ID] = ID : 1
if [Hexdb.Students.ID] <10 make [ZZZ]=000
if [Hexdb.Students.ID] <100 make [ZZZ]=00
if [Hexdb.Students.ID] <1000 make [ZZZ]=0

ok, did i just answer my question? :shock:

or is there an easier way to do what i wanted it to do...
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: change display of integer variable?

Postby Tony Kroos » Fri Aug 01, 2014 10:50 pm

make a subroutine:
Code: Select all
IfEx "[Hexdb.Students.ID] > 99 AND [Hexdb.Students.ID] < 1000"
SetVar "[Hexdb.Students.ID]" "!0[Hexdb.Students.ID]"
Return
EndIf
IfEx "[Hexdb.Students.ID] > 9 AND [Hexdb.Students.ID] < 100"
SetVar "[Hexdb.Students.ID]" "!00[Hexdb.Students.ID]"
Return
EndIf
If "[Hexdb.Students.ID]" "<" "10"
SetVar "[Hexdb.Students.ID]" "!000[Hexdb.Students.ID]"
EndIf
Return


and call it before displaying [Hexdb.Students.ID] variable:
goSub "SubroutineName"
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Re: change display of integer variable?

Postby yanzco » Sat Aug 02, 2014 12:00 am

yep, that worked great!.. thanks! :D
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: change display of integer variable?

Postby Gaev » Sat Aug 02, 2014 7:11 am

Here is a Generic Subroutine to pad left of [InString] with [OutStringPad] (or 0 if not specified) ... returns [OutString] with length specified in [OutStringSize].

Code: Select all
:PadString
... generic subroutine to pad left of [InString] with [OutStringPad] or 0 (if not specified)
... returns [OutString] with length specified in [OutStringSize]
 
... set default value of [OutStringPad] if not specified
If "[OutStringPad]" "=" ""
   SetVar "[OutStringPad]" "0"
EndIf
... size of [InString]
StrLen "[InString]" "[InStringSize]"
... required pad characters
Math "[OutStringSize]-[InStringSize]" "0" "[RequiredPads]"
... initial value
SetVar "[OutString]" "![InString]"
If "[RequiredPads]" "<=" "0"
    Return
EndIf
Loop "1" "[RequiredPads]" "[thisIteration]"
   ... pad to the left
   SetVar "[OutString]" "![OutStringPad][OutString]"
EndLoop
Return


Can be called like so ...
Code: Select all
SetVar "[OutStringSize]" "4"
... optional; must only be one character; default is 0
SetVar "[OutStringPad]" "0"
SetVar "[InString]" "12"
GoSub "PadString"
... [OutString] will contain pad'ed string of desired size


Subroutine can also be converted to a NeoBook Function that can be called like so ...
Code: Select all
Call PadStringFunction "4" "0" "[Instring]" "[OutString]"
User avatar
Gaev
 
Posts: 3733
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: change display of integer variable?

Postby yanzco » Sun Aug 03, 2014 1:33 am

@gaev

im trying to implement your suggestion, but how do i implement it?.. when should i call the subroutine, where do i place the integer variable(3) that is needed to be changed (0003)
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: change display of integer variable?

Postby Gaev » Sun Aug 03, 2014 9:30 am

yanzco:

when should i call the subroutine, where do i place the integer variable(3) that is needed to be changed (0003)


1) copy the first code block in my previous response to your pub's SubRoutine section ... read the Help file if you are not familiar with SubRoutines.

2) If your Integer variable is [Hexdb.Students.ID] ...
Code: Select all
SetVar "[OutStringSize]" "4"
SetVar "[InString]" "[Hexdb.Students.ID]"
GoSub "PadString"

... [OutString] will contain pad'ed string of desired size ... now you can copy (SetVar) it to whatever variable you want to display.
User avatar
Gaev
 
Posts: 3733
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 2 guests

cron