help convert pascal to vba

Hi experts,
    could i get following pascal code convert to vba version please? i know most of them but some of them like arrays i'm not sure how to do the correct conversion. any help would be great.
procedure TForm1.Button3Click(Sender: TObject);
    // declare the variables. Note the use of 0-based Array of Chars for the PChars at the required length.
   pControlPath   : Array[0..MAX_PATH] of Char;
   pIsAccessDB    : Boolean;
   pControlServer : Array[0..256] of Char;
   pSQLName       : Array[0..31] of Char;
   pSQLPassword   : Array[0..31] of Char;
   pError         : Array[0..2049] of Char;
      mmControl.Clear; // clear the display control
      if not GetControlInformation(pControlPath, pIsAccessDB,
                                   pControlServer, pSQLName, pSQLPassword, pError) then // get the results from the dll
         mmControl.Lines.Add(pError) // if it fails display the error
         mmControl.Lines.Add('ControlPath: '+pControlPath); //show the control path

         if pIsAccessDB then // show whether it's Access or SQL
            mmControl.Lines.Add('Using an Access Control DB')
            mmControl.Lines.Add('Using an SQL Control DB');

         mmControl.Lines.Add('ControlServer: '+pControlServer); // show the Control server (SQL only)
         mmControl.Lines.Add('UserName: '+pSQLName); // 
         mmControl.Lines.Add('Password: '+pSQLPassword); // 
   except on E : Exception do

Open in new window

Who is Participating?
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPConnect With a Mentor Commented:
Are you trying to open a recordset?  If yes then I I would use ADO.

To convert the arrays try:

   Dim pControlPath  as String
   Dim pIsAccessDB    as Boolean
   Dim pControlServer  as String
   Dim pSQLName  as String
   Dim pSQLPassword  as String
   Dim pError  as String

Open in new window

Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
It would really help to know what the code is try9ign to do.

There might be other and possible better ways to accomplish the desired results in VBA.

miketonnyAuthor Commented:
it's trying to connect to database , i'm just copying these codes directly from an sdk provided by an accounting software. it's purpose is to allow 3rd party programs to work with the software.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

miketonnyAuthor Commented:
not really, i'm just trying to estalibsh a connection to db and call a function from a reference. function name is "GetControlInformation", its in a .DLL, the purpose of this function is to return me whether connection is successful or not, that's all it does
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
So is mmControl the class used to work with the DLL?

Where is GetControlInformation()?
miketonnyAuthor Commented:
function GetControlInformation(pControlPath : PChar;
                               var pIsAccessDB : Boolean;
                            pControlServer : PChar;
                            pSQLName : PChar;
                            pSQLPassword : PChar;
                            pError : PChar): Boolean;

Open in new window

this is the function , its called from .DLL
yes mmControl is the control working with the DLL

"PCHAR" is a buffer here
If you are going to use static arrays then you can just go ahead and set the array bounds.

Dim pControlPath  (0 To MAX_PATH) as String
Dim    pIsAccessDB  as Boolean
Dim   pControlServer (0 TO 256) as String
Dim   pSQLName (0 To 31) as String
Dim   pSQLPassword (0 To 31) as String
Dim   pError (0 To 2049) as String

If you want Dynamic Arrays, then just leave out what is between the parenthesis and use ReDim Preserve as needed.
Dim pControlPath  () as String
Dim    pIsAccessDB  as Boolean
Dim   pControlServer () as String
Dim   pSQLName () as String
Dim   pSQLPassword () as String
Dim   pError () as String

Also, you stated VBA in your question, but have VB.Net as a selected zone.  I have requested that Visual Basic be added as well since you might get better support there.
aikimarkConnect With a Mentor Commented:
The challenge will be to pass the values to the function.

If using String variables, you will need to pass them by value (By Val), since a VB string variable is a complex 'safe array' structure.

You might need to use StrConv() to transfer string variable data into byte array variables.  The StrConv() function will automatically resize the byte array, so you don't need to use the ReDim statement.  

Note: PChar data is terminated by a zero ASCII byte.  You can use the vbNullChar constant or use a byte array that is one byte larger.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.