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

Jussi Lahtinen jussi.lahtinen at gmail.com
Sat Nov 19 04:11:12 CET 2022


Looks good!
You just need an additional argument for the alignment (perhaps by changing
integer[] to string[] or variant[]), if you want to add it, or you will
narrow the function's use cases.

Jussi

On Sat, Nov 19, 2022 at 4:46 AM BB <adamnt42 at gmail.com> wrote:

> Well, it turned out to be simple!
> On 19/11/22 11:47 am, Jussi Lahtinen wrote:
>
> I see... you can use tabs this way:
> Print Cust.ID & gb.Tab & Cust.Name & gb.Tab & Cust.Balance & gb.Tab &
> Cust.Phone
>
> Many tabs by String(n, gb.Tab). Not very handy though. I think it is best
> to write your own function to show things neatly.
> See here to learn how to take variable amount of parameters:
> http://gambaswiki.org/wiki/comp/gb/param
>
> This would be a nice feature... but I can do it only with C.
> Print [0,6,50,70], Cust.ID, Cust.Name, Cust.Balance, Cust.Phone
>
>
> Jussi
>
>
>
> Public Sub Main()
>
>   PrintF([0, 6, 30, 45, 60, 132], "ACCT", "NAME", "BALANCE", "PHONE", "DUE")
>   PrintF([0, 6, 30, 45, 60, 132], String(5, "_"), String(23, "_"), String(45 - 31, "_"), String(60 - 45 - 1, "_"), String(22, "_"))
>   PrintF([0, 6, 30, 45, 60, 132], 12345, "Doris Day", Format(45.67, "$#.00"), "N/A", Now())
>   PrintF([0, 6, 30, 45, 60, 132], 145, "Michaelango Vesputti", Format(125.67, "$#.00"), "", Date(Now() - 1))
>   PrintF([0, 6, 30, 45, 60, 132], 45, "Bozo Dog", Format(5.60, "$#.00"), "Woof", Null)
>   PrintF([0, 6, 30, 45, 60, 132], 666, "The Devil Incarnate Himself", Format(-66666, "($,#.00"), "0666-666-666", Date(666))
>   PrintF([0, 6, 30, 45, 60, 132], 427, "Jim Bo", Format(75.5, "$#.00"), "0416-763-274", Date(2023, 5, 1, 12, 30))
>
> End
>
> Private Sub PrintF(fmt As Integer[], ...)
>
>   Dim idx As Integer
>   Dim iPad As Integer ' the number of spaces to add
>
>   If Param.Count > (fmt.Count - 1) Then Error.Raise("Mismatched format")
>
>   For idx = 0 To Param.Max
>     If Len(Str(Param[idx])) >= fmt[idx + 1] - fmt[idx] Then
>       Print Left(Str(Param[idx]), fmt[idx + 1] - fmt[idx] - 1); "…";
>     Else
>       iPad = (fmt[idx + 1] - fmt[idx]) - Len(Str(Param[idx]))
>       If ipad < 0 Then Print "¿";
>       Print Param[idx];
>       If idx < Param.Max Then Print String(iPad, " ");
>     Endif
>   Next
>   Print
>
> End
>
>
> Yields
>
> ACCT  NAME                    BALANCE        PHONE          DUE
> _____ _______________________ ______________ ______________ ______________________
> 12345 Doris Day               $45.67         N/A            19/11/2022 13:04:09
> 145   Michaelango Vesputti    $125.67                       18/11/2022 00:00:00
> 45    Bozo Dog                $5.60          Woof
> 666   The Devil Incarnate Him…($66,666.00)   0666-666-666   28/10/-4800 00:00:00
> 427   Jim Bo                  $75.50         0416-763-274   01/05/2023 12:30:00
>
> A bit rudimentary and would be "nicer" if numbers were right or decimal
> point aligned and may need a  bit more error control.
>
> Amazing what a good sleep and two days free of malformed XML ahead can do.
>
> regards
>
> bruce
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20221119/8d87858d/attachment-0001.htm>


More information about the User mailing list