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

T Lee Davidson t.lee.davidson at gmail.com
Sat Nov 19 04:26:50 CET 2022


On 11/18/22 21:45, BB wrote:
> 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

Interesting. I think we must have been working on it separately together.

But, what I came up with is simpler :-P

[code]
' Gambas module file

Public Sub Main()

   Dim Customers As New Collection[]

   Customers.Add(["id": "312", "name": "Mary K Jones", "balance": 350, "phone": "423-614-12"])
   Customers.Add(["id": "472", "name": "Jim Bo", "balance": 75.5, "phone": "0416-763-274"])
   Customers.Add(["id": "666", "name": "The Devil Incarnate Himself", "balance": 99.999, "phone": "0413-100-200"])
   Customers.Add(["id": "2", "name": "Bozo Dog", "balance": 1.23, "phone": "0413-627-123"])

   For Each cust As Collection In Customers
     Print Pad(cust["id"], 8); Pad(cust["name"], 35); Pad(cust["balance"], 10); cust["phone"]
   Next

End

Public Sub Pad(sStr As String, iWidth As Integer) As String

   Return sStr & Space(iWidth - Len(sStr))

End
[/code]

Maybe not as versatile though.


-- 
Lee



More information about the User mailing list