AW: Replace conditional statement with Polymorphism

Martin Obongita martin.obongita at
Sat Jul 2 20:47:36 UTC 2022

 Hi Rudolf,
For max string length I am using:

For lLineNum from 1 to lCustomDataList.$linecount step 1

# Switch

#try switch case to get the len(1,2,3,4,5,6)

# End Switch

Calculate lString as lCustomDataList.1.2


Calculate lColLength as len(lCustomDataList.[lLineNum].[lCol01])

If lColLength<lColLengthMax

Calculate lColLength as lColLengthMax

End If

Calculate lColLengthMax as lColLength

End For

Quit method lColLengthMax

Thank you ALL for your helps.
    On Saturday, July 2, 2022 at 11:15:11 PM GMT+3, Rudolf Bargholz <rudolf at> wrote:  
 Hi Martin,

Why not just use the FontOps function $reptextwidth() to calculate the width of the longest value in the column, and then use that value to determine the width of your column. You will have to work out a max-width for the column, and if $reptextwidth() returns a value greater than this value, then use your max value, but this will reduce your code below to a very manageable and understandable block.


Rudolf Bargholz

-----Ursprüngliche Nachricht-----
Von: omnisdev-en <omnisdev-en-bounces at> Im Auftrag von Martin Obongita via omnisdev-en
Gesendet: Samstag, 2. Juli 2022 19:50
An: OmnisDev List - English <omnisdev-en at>; Rob Mostyn <mostyn at>
Cc: Martin Obongita <martin.obongita at>
Betreff: Re: Replace conditional statement with Polymorphism

 Hi Rob,
I have a report class in which I want to display columns.
The length of the columns should depend on the longest data in that column.I get the data and approximate its length in pixels.

Calculate lColLength as pColLength

If lColLength<=5

Calculate lPixels as 1

Else If lColLength<=10

Calculate lPixels as 2

Else If lColLength<=15

Calculate lPixels as 3

Else If lColLength<=20

Calculate lPixels as 4

Else If lColLength<=25

Calculate lPixels as 5

Else If lColLength<=30

Calculate lPixels as 6

Else If lColLength<=35

Calculate lPixels as 7

Else If lColLength<=40

Calculate lPixels as 8

Else If lColLength<=45

Calculate lPixels as 9

Else If lColLength<=50

Calculate lPixels as 10

Else If lColLength<=55

Calculate lPixels as 11

Else If lColLength<=60

Calculate lPixels as 12

Else If lColLength<=65

Calculate lPixels as 13

Else If lColLength<=70

Calculate lPixels as 14

Else If lColLength<=75

Calculate lPixels as 15

Else If lColLength<=80

Calculate lPixels as 16

Else If lColLength<=85

Calculate lPixels as 17

Else If lColLength<=90

Calculate lPixels as 18

Else If lColLength<=95

Calculate lPixels as 19

Else If lColLength<=100

Calculate lPixels as 20

End If

Quit method lPixels

You are right that this is old Omnis classic mindset.If there is a way to replace the IF statement in my code, it will do me a great deal of good.

    On Saturday, July 2, 2022 at 08:32:47 PM GMT+3, Rob Mostyn <mostyn at> wrote:  
 H Martin,
object oriented programming requires a complete mind shift from procedural (Omnis Classic) programming.   More than that, it is a multidimensional or rather multi layered mind shift.  This transition took me about 18 months to get some 20 years ago.  I am sure you are somewhere along the curve yourself but I/we cannot tell how far. My suggestion is that you focus on a class / subclass hierarchy to address, or at least partially address your challenge.  The solution will most likely be a combination of the two methods.
Are your conditional statements implementing change in behaviour, change in business logic, change in presentation or change on … whatever? To answer your question properly requires a good understanding of your code base which you have and we don’t, so Its difficult to answer your questions succinctly.
Other may chip in with a more academic response.

On 1 Jul 2022, at 20:45, Martin Obongita via omnisdev-en <omnisdev-en at> wrote:
Hi Listers,
I have an academic question about object-oriented programming.How is "polymorphism" implemented in Omnis Studio?
I have many conditional statements in my code: if...else if, that keeps breaking whenever I make a change in a related method elsewhere.Is there a sample library in the HUB which best described how to work with code that can take many forms?
Kind regards,Martin O.

Manage your list subscriptions at Start a new message -> mailto:omnisdev-en at 

Manage your list subscriptions at Start a new message -> mailto:omnisdev-en at 

More information about the omnisdev-en mailing list