Solved

help convert pascal to vba

Posted on 2011-02-13
9
803 Views
Last Modified: 2012-05-11
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.
var
   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;
begin
   try
      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
      else
      begin
         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')
         else
            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); // 
      end;
   except on E : Exception do
      showMessage(E.Message);
   end;
end;

Open in new window

0
Comment
Question by:miketonny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 21
ID: 34884894
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.


0
 
LVL 2

Author Comment

by:miketonny
ID: 34884957
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.
0
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 250 total points
ID: 34885001
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

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 2

Author Comment

by:miketonny
ID: 34885205
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
0
 
LVL 21
ID: 34885493
So is mmControl the class used to work with the DLL?

Where is GetControlInformation()?
0
 
LVL 2

Author Comment

by:miketonny
ID: 34885534
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
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 34887354
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.
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 250 total points
ID: 34908510
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.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question