× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Here is our procedure

Here are the special attributes of this procedure:
- it accept string of up to 1000 caracters
- if you do not pass the length of the string, it find it out by itself
- you can decide to center the string in another string of a different length

This procedure is part of a service progam that handle string manipulation

p Center          b                   export                                
d                 pi          1000a   opdesc                                
d  String                     1000a   options(*varsize) const               
d  StringLen                     4s 0 options(*nopass)  const               
                                                                            
d @CalStrLen      s                   like(StringLen)                       
d @SpaceBefore    s                   like(StringLen)                       
d @WrkStr         s           1000a                                         
d @Return         s           1000a                                         
                                                                            
 * compute size of input parameter                          
c                   callp     CEEDOD(1        : DescType : DataType:        
c                                    DescInfo1: DescInfo2: Inlen   : *OMIT) 
                                                                            
 * extract input string in work field  
c                   eval      @WrkStr = %subst(String:1:Inlen)              
                                                                            
 * decide the length to use for centering calculation 
c                   if        %parms < 2                                    
c                   eval      @CalStrLen = InLen                        
c                   else                                                
c                   eval      @CalStrLen = StringLen                    
c                   endif                                               
                                                                        
 * center the string                                                     
c                   clear                   @Return                     
c                   eval      @spaceBefore =                            
c                             (@CalStrLen - %len(%trim(@WrkStr)))/2 + 1 
                                                                        
c                   if        @spaceBefore <= 0                         
c                   eval      @return = %trim(@WrkStr)                  
c                   else                                                
c                   eval      %subst(@return:@spaceBefore) =            
c                             %trim(@WrkStr)                            
c                   endif                                               
                                                                        
c                   return    @return                                   
                                                                        
p Center          e                                                             
                                                                    

Denis Robitaille
Directeur services technique TI
819 363 5187

SUPPORT
Jour (EST) Daytime : 819-363-5087
En-dehors des heures (EST) After hour : 819-363-5095
Network Status : 819-363-5096

>>> Booth@xxxxxxxxxxxx 08/14/03 09:39am >>>
 
 
What is the current best practice to center text of unknown length in a
field of unknown length?

It occurs to me I am making it much too difficult.

(free form is nice I suppose but an example in ordinary RPGIV would be
easier for me to understand)

---------------------------------------------------------
Booth Martin http://www.MartinVT.com 
Booth@xxxxxxxxxxxx 
---------------------------------------------------------
 

_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx 
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l 
or email: RPG400-L-request@xxxxxxxxxxxx 
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.