Snippets

SeanB Splitting text up for a cWinPrint2

Created by SeanB
Object oLineCalc is a ModalPanel  
    Set Size to 177 246
    Property Integer phLabelObj 
    Property String psTypeFace "Arial"
    Property Integer piFontSize 12
    
    Function CreateLineObj Returns Integer 
        Integer hObj 
        Get phLabelObj  to hObj 
        If (hObj <>0) Function_Return hObj 
        
        Get Create (RefClass(TextBox)) to hObj 
        Set phLabelObj  to hObj 
        Function_Return hObj 
    End_Function
    
    Function TextLineLength String sInp Returns Integer 
        Integer hObj 
        Integer iLength
        
        Get CreateLineObj to hObj 

        Set FontPointHeight of hObj  to (piFontSize(Self)) 
        Set Typeface of hObj  to (psTypeFace(Self)) 
        
        Set Value of hObj to "xx"
        Set Value of hObj to sInp
        
        Get GuiSize of hObj to iLength 
        Move (low(iLength)) to iLength 
        
        Function_Return iLength         
    End_Function
    
    Function MonitorResolution Returns Number 
        Number nPos 
        Integer hObj 
        Integer iHeight 
        
        Get CreateLineObj to hObj 
        Set Size of hObj to 100 100
        Get GuiSize of hObj to nPos 
        Move (Hi(nPos)) to nPos
        
        If (nPos < 200) Function_Return 1 
        If (nPos < 300) Function_Return 1.25 
        If (nPos < 350) Function_Return 1.5 
        If (nPos < 400) Function_Return 1.75 

        Move (nPos/200) to nPos 
        
        Function_Return nPos 
    End_Function
    
    Function FormatLineToFixedWidth String sInp Integer iLength Returns String[]
        String[] aWords
        String[] aRet 
        Integer iMax 
        Integer iPos 
        String sRet 
        Integer iTestLen
        
        Move (StrSplitToArray(sInp," ")) to aWords
        Move (SizeOfArray(aWords)) to iMax
        If (sInp="") Move "" to aWords[0]

        Move aWords[0] to sRet 
        For iPos from 1 to (iMax-1) 
            Move (TextLineLength(Self,sRet+" "+aWords[iPos]+" ")) to iTestLen
            If (iTestLen>=iLength) Begin 
                Move sRet to aRet[SizeOfArray(aRet)]
                Move aWords[iPos] to sRet 
            End
            Else Begin 
                Move (sRet+" "+aWords[iPos]) to sRet 
            End
        Loop
        If (sret<>"") Move sRet to aRet[SizeOfArray(aRet)]
        
        Function_Return aRet         
    End_Function
    
    Function FormatTextToFixedWidth String sInp Integer iLength Returns String[]
        String[] aRet 
        String[] aLines
        String[] aTemp
        Integer iMax 
        Integer iPos 
        String  sChar10  
        
        Move (Character(10)) to sChar10 
        
        Move (StrSplitToArray(sInp,sChar10)) to aLines
        Move (SizeOfArray(aLines)) to iMax 
        For iPos from 0 to (iMax-1)
            Move (FormatLineToFixedWidth(Self,aLines[iPos],iLength)) to aTemp 
            Move (AppendArray(aRet,aTemp)) to aRet 
        Loop
        
        Function_Return aRet 
    End_Function
    
    Function LengthForInches Integer iInches Returns Integer 
        Number nPointSize 
        
        Get MonitorResolution to nPointSize
        Move (nPointSize*93) to nPointSize
        
        Function_Return (iInches*nPointSize) 
    End_Function
    
    
End_Object

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.