Replace conditional statement with Polymorphism

Martin Obongita martin.obongita at
Sat Jul 2 17:49:43 UTC 2022

 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 


More information about the omnisdev-en mailing list