From: Gautier write-only address <gautier_niouzes@hotmail.com>
Subject: Re: Ada interface to Excel file
Date: Thu, 20 Apr 2023 12:08:40 -0700 (PDT) [thread overview]
Message-ID: <1205879c-cbef-4a87-b3a5-94f9db91f2f0n@googlegroups.com> (raw)
In-Reply-To: <fb877c1f-9dc3-45ed-af3a-fab90f77d548n@googlegroups.com>
The simplest way by far is to generate the Ada sources
from within Excel by using VBA (a BASIC with a strong Ada flavour,
but still a BASIC) which is part of Excel.
From Excel, you activate VBA with the Alt-F11 shortcut.
You have "modules" which are just editor files and visible from
everywhere else (you have like implicit "with"'s and "use"'s); you
have functions called "Function" and procedures called "Sub".
You can associate a button in the Excel sheet to a Sub.
You declare each variable with "Dim x As Type".
You can also forget to declare variables, with funny outcomes.
The behavious of the type system around parameter passing is also funny.
You find below a few examples.
Now, if you already have your CSV-to-Ada generator, you can export a CSV; that's also easy with VBA.
G.
[somewhere (some module)]
Sub Generate_for_Production()
Dim anchor As String ' VBA String is Ada's Unbounded_String
' File handles
Dim fh_ada_spec As Integer
Dim fh_ada_body As Integer
...
Open ThisWorkbook.Path & "\src\" & pkg_name & _
".ads" For Output As #fh_ada_spec
...
For Each ws In Worksheets ' Scan all worksheets
For Each r In ws.UsedRange.Rows ' Scan all used rows
anchor = r.Cells(1, 1).Value
If anchor <> "" Then
...
End If
Next r
Next ws
...
Close #fh_ada_spec
End Sub
[somewhere else (perhaps another module)]
Print #fh, "with Ada.Calendar;"
Print #fh, "with Ada.Unchecked_Conversion;"
Print #fh, "with Interfaces;"
Print #fh,
Print #fh, "package " & name & " is"
[somewhere else]
If simple_record Then
Print #fh_ada_spec, " -- Simple record."
Print #fh_ada_spec,
Print #fh_ada_spec, " type Xyz is record -- " & paragraph
Else
Print #fh_ada_spec, " type Xyz is new " & parent_name & _
"Abc with record -- " & paragraph
End If
[somewhere else]
For i = min_row_offset To max_row_offset
' Convert name in cell to Ada name
field = Ada_Name(r.Cells(i, 3).Value)
If field = "" Then
Exit For
End If
amount = r.Cells(i, 6).Value
...
Print #fh_ada_body, " for index in 1 .. " & amount & " loop"
Print #fh_ada_body, " declare"
next prev parent reply other threads:[~2023-04-20 19:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 17:36 Ada interface to Excel file AdaMagica
2023-04-19 18:22 ` Jeffrey R.Carter
2023-04-20 19:24 ` Gautier write-only address
2023-04-20 20:48 ` Jeffrey R.Carter
2023-04-24 10:15 ` AdaMagica
2023-04-20 9:18 ` Dmitry A. Kazakov
2023-04-20 19:08 ` Gautier write-only address [this message]
2023-04-20 20:07 ` Björn Lundin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox