[Gambas-user] COBOL and how great it was!

gian bagoneo at libero.it
Mon Nov 21 09:31:12 CET 2022


Il 21/11/22 00:47, BB ha scritto:
> Tried it out with a few changes.
> 
> Dim aState As Integer[] = [spRight, spRight, spLeft, spRight, spRightPlus, spCenter]
>    Dim aSpace As Integer[] = [6, 44, 15, 12, 20, 17]
>    PrintVarPad(aState, aSpace, True, "ACCT", "NAME", "BALANCE", "PHONE", "DUE", "OTHER STUFF")
>    PrintVarPad(aState, aSpace, False, 12345, "Doris Day", Format(45.67, "$,#.00"), "N/A", Now(), Round(Pi, -7))
>    PrintVarPad(aState, aSpace, False, 145, "Michaelango Vesputti", Format(125.67, "$,#.00"), Null, Date(Now() - 1))
>    PrintVarPad(aState, aSpace, False, 45, "Bozo the Dog", Format(0.05, "$,#.00"), "Woof")
>    PrintVarPad(aState, aSpace, False, 666, "The Devil Incarnate Himself", Format(-6666, "$,#.00"), "0666-666-666", Date(666))
>    PrintVarPad(aState, aSpace, False, 427, "«Jim Bo»", Format(75.5, "$,#.00"), "0416-763-274 ext 42", Date(2023, 5, 1, 12, 30), 1)
> 
> Giving
> 
> ACCT  NAME                                             BALANCEPHONE         DUE                    OTHER STUFF
> ----- ------------------------------------------- ----------- ----------- --------------------- ----------------
> 12345 Doris Day                                         $45.67N/A           21/11/2022 09:50:00     3.1415927
> 145   Michaelango Vesputti                             $125.67              20/11/2022 00:00:00
> 45    Bozo the Dog                                       $0.05Woof
> 666   The Devil Incarnate Hi…                       -$6,666.000666-666-666  28/10/-4800 00:00:00
> 427   «Jim Bo»                                          $75.50*failed (Bad argument at line 62) here because the input string is too wide*
> 
> 1) the account column is not right aligned.
> 
> 2) even though the name column is now wide enough to cope with the 
> longest name it is still eliding?
> 
> 3) the three dots are the elision character from the "special 
> characters" dropdown. It only takes one character so as much of the 
> string as possible is visible.
> 
> 4) the balance column does not resize no matter what I set the column 
> width to. Also it is overflowing the actual column width by one character.
> 
> 5) negative dates overflow the allowed column width
> 
> 6) text that is too wide to fit in the phone column caused it to fail as 
> it it trying to pad with a negative number of spaces.
> 
> I do like the ability to center a column but I doubt that I would ever 
> need it.
> 
> It's a good proof of using column widths though. As I said previously I 
> went for the column number approach though. One reason for that is I can 
> copy the original "ragged" edge output from the console panel and paste 
> it into Geany. It is fairly quick therein to pad out a representative 
> line with tabs and that gives me the column numbers I need i.e. no need 
> to calculate column widths. Mneh! Others may prefer your way.
> 
> b

Mine was just a suggestion.
I am convinced that it is easily improved, such as in the case you 
posted (aSpace As Integer[] = [6, 44, 15, 12, 20, 17]):

'---------------------------------------
Private Sub PrintVarPad(aState As Integer[], aSpace As Integer[], bTitle 
As Boolean, ...)

   Dim aField As Variant = Param.All
   Dim iSpaceTwo As Integer = aSpace[2]
   Dim iSpaceOne As Integer = aSpace[1]

   For i As Integer = 0 To Param.Max
     If TypeOf(aField[i]) <> 9 Then Try aField[i] = Str(aField[i])
     If Error Then aField[i] = "No Data"
     Select Case i
       Case 1
         If Len(aField[i]) > iSpaceOne Then aField[i] = 
String.Left(aField[i], iSpaceOne) & "..."
       Case 2
         If String.Left(aField[i]) = "-" Then
           aField[2] = "\e[31m" & aField[2] & "\e[0m"
           aSpace[i] += 9
         Endif
       Case 4
         If Len(aField[i]) > 20 Then aField[i] = String.Left(aField[i], 
17) & "..."
       Case 5
         If Len(aField[i]) > 16 Then aField[i] = String.Left(aField[i], 
11) & "..."
     End Select
     Print PadString(aField[i], aSpace[i], " ", aState[i]);
     aSpace[2] = iSpaceTwo
   Next
   Print
   If bTitle Then
     For i = 0 To aField.Max
       Print String(aSpace[i] + $aOffset[i] - 1, "-"); "+";
     Next
     Print
     $aOffset.Clear
   Endif

End
'-------------------------------------

If you messed up the numbers in your code what would happen?

Regards

Gianluigi



More information about the User mailing list