Topic Options
#57965 - 04/20/21 01:16 PM Dynamic Width of Textbox
GHerman Offline
OL Toddler

Registered: 02/24/14
Posts: 37
Hello,

I have searched this forum extensively for this issue and couldn't find it which leads me to believe it's either too difficult and can't be done, or too simple and I'm overlooking something (most likely the latter).

I am making simple location labels for our warehouse. This consists of a barcode and text underneath it. I decided not to use the Human Readable option so I could have better control over the text.

Because the length of a location can be dynamic, I set the text and font size/barcode spacing using PP Talk to prevent them from going off the page. Something like this:


Code:
&location := uppercase(trim(XmlGet('/location_labels[1]/location_label[1]/location[1]')))
define(&BarWidth,integer,12)

if(length(&location) >= 12)
        &BarWidth := 12
elseif(and(length(&location) >= 9, length(&location) < 12))
        &BarWidth := 18
elseif(length(&location) < 9)
        &BarWidth := 22
endif()

showbarcodecode39(&location, &BarWidth, False, False, FALSE)



The purpose here is to increase or decrease the barcode width based off of the number of characters. I initially tried to do a repeat loop and decrease the font size until the object was less than the page width, but had issues, so this was the next best solution.

Here's the issue: I would like for the barcode and location text to be centered on the label. I tried the translate procedure calculating the width of the object against the width of the page, but because the text and barcode are generated via PP Talk, the proper object width is not registering. It thinks the object is blank. I have experimented with the placement of the code in PP Before and PP After with no avail. I've also tried a tip I learned form another forum post where I recreate the same barcode object off the canvas just to set the width. This also did not work.

How can I get the proper width of a dynamic object to translate it to the center of the page?

Thanks for your help.


Edited by GHerman (04/20/21 01:46 PM)

Top
#57969 - 04/22/21 09:48 AM Re: Dynamic Width of Textbox [Re: GHerman]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 650
Loc: Québec, Canada
You were on the right track:
Quote:
I've also tried a tip I learned form another forum post where I recreate the same barcode object off the canvas just to set the width.


The trick is use the PressTalk After of the off-canvas PressTalk object to store the width into a global variable. Then, you can use it in your on-canvas PressTalk object.

If it still doesn't work, please paste all your steps (PressTalk code use and where, order of steps, anything related to that part of your form) here, so I can review them.
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57972 - 04/26/21 11:43 AM Re: Dynamic Width of Textbox [Re: GHerman]
GHerman Offline
OL Toddler

Registered: 02/24/14
Posts: 37
Thanks for the reply.

I've tried your suggestion, and still no luck.

Here are my steps:

I have an off-canvas text object with only information in the PressTalk Before and After sections. In the PressTalk Before section, I create the barcode like so:

Code:
&location := uppercase(trim(XmlGet('/location_labels[1]/location_label[1]/location[1]')))

define(&BarWidth,integer,12)
define(&BarHeight,measure,1)
define(&BarType,integer,0)

if(length(&location) >= 12)
        &BarWidth := 12
elseif(and(length(&location) >= 9, length(&location) < 12))
        &BarWidth := 18
elseif(length(&location) < 9)
        &BarWidth := 22
endif()

setfillcolor([100,100,100,100])
showbarcodecode39(&location, &BarWidth, False, False, FALSE)


In the PressTalk After section, I set the Global Variable to the width.

Code:
&barcode_width := &width


It's worth noting I've also tried &current.x here instead of &width with no luck.

for my on-canvas barcode, I've duplicated the off-canvas textobject and have the following code in the PressTalk Before section:

Code:
&location := uppercase(trim(XmlGet('/location_labels[1]/location_label[1]/location[1]')))
define(&BarWidth,integer,12)
define(&BarHeight,measure,1)
define(&BarType,integer,0)

if(length(&location) >= 12)
        &BarWidth := 12
elseif(and(length(&location) >= 9, length(&location) < 12))
        &BarWidth := 18
elseif(length(&location) < 9)
        &BarWidth := 22
endif()

showbarcodecode39(&location, &BarWidth, False, False, FALSE)


In my PressTalk After, I have nothing.

To view the value of the variable, I've added it to a text object on the canvas (right click within text area and select Global Variable -> Measure -> &barcode_width. The value is only .7295074. I thought maybe the value only changed at execution, so I printed the file (File -> Print Using a Windows Driver) and the width did not change.

The only other object in my file is a text object that shows the location as a text, not a barcode. The following code is in the PressTalk Before section:

Code:
MoveTo(0,0)
MoveTo(&Width,&Height)
Margin(0.0000,0.0000)

define(&font_size, measure, 50.00)

if(length(&location) >= 12)
        &font_size := 25
elseif(and(length(&location) >= 9, length(&location) < 12))
        &font_size := 35
elseif(length(&location) < 9)
        &font_size := 45
endif()

        SetStyleExt(&Style4,&font_size,-1,-1)
                show(&location)

Top
#57973 - 04/26/21 04:56 PM Re: Dynamic Width of Textbox [Re: GHerman]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 650
Loc: Québec, Canada
Put your barcode PressTalk in the object itself, not the PressTalk Before of an object.
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top