I'm starting to convert a number of "utilitarian apps" from Access/VBA to C#, and some of the equivalents escape me sofar.
By "utiltarian" I mean Access apps that run unattended, process data in various databases (mostly in one SQL Server DB), and possibly go through various phases of processing. So I have typically constructed them around one main form which when loaded calls a number of routines, some located in the form itself, and many located in modules, of which there are 2 categories: standard, generic modules which are used by many of the apps, and specific modules which do some specific processing only in one of the apps.
Many of my modules log what they are doing in a table in SQL Server, and they also add the same or similar kind of text log entries in one listbox on the main form, which always bear the same name, lbProgress, in all apps and which allows me when developing and testing to see what the code is doing and what problems it encounters. So basically I have this:
- main form calls subroutine A in module X by passing any needed arguments, but always Me as argument
- subroutine A (which has the argument "frm as Form" to map the Me argument in the sub call in the main form) starts working and, when it wants to "publish" the fact that it has reached some step in the processing, it calls a generic logging routine, passing it its own "frm" parameter and the text to log as arguments
- the generic logging routine uses these arguments to add the logging text to the main form's list box lbProgress by referring to it as frm.lbProgress
So in pseudo code, it is something like (simplified):
Private Sub Form_Load() (of frmMain form)
in specific module of app:
public Sub A(frm as Form)
' Want to log text "Step 1 completed"
call LogProgress(frm, "Step 1 completed")
In generic module modAppLogging:
Public Sub LogProgress(frm as Form, sLogText as String)
Dim Temp as Variant
Temp = SysCmd(acSysCmdSetStatus, sLogText )
I thought I would therefore start to rewrite such a generic module, which is basically a collection of public sub's doing some processing which may or may not access data in tables in a SQL Server DB, and to make a solution with one form as project and the generic module code in a sealed class. However, I'm stumbling on many small obstacles:
- the main form passes its reference "Me" in the sub call to A, because it might be used by A and by the LogProgress generic routine. What's the equivalent to "Me" in C# ? "this" ?
- is there an equivalent in C# for the SysCmd call, which just shows the log text in the status bar of the form ?
- the LogProgress routine uses in VBA the 2 arguments shown above: a reference to the main form, and a string. I can't fathom what type this "frm" variable should be in the sealed class A and in the sealed class where LogProgress is, i.e what's the type in:
public static void LogProgress( ??Type?? frm, string sLogText)
Thanks for helping me with these probably trivial problems.