Solved

How to convert vba macro function into c#.net code

Posted on 2014-09-09
2
263 Views
Last Modified: 2014-09-11
Hi,

Could you please help me out regarding how to convert the code from vba macro to c#.net 3.5

Private Type Struct_XYZ
  CellID As Long
  P_Pos(1 To 3) As Double
  W_IDs(1 To Max_Num_XYZ) As Long
  W_Vectors(1 To 3, 1 To Max_Num_XYZ) As Double
  W_Distance(1 To Max_Num_XYZ)
  Shortest As Double
  W_Vector_Shortest(1 To 3) As Double
  W_ID_Shortest As Long
  Number_of_XYZ As Integer
End Type

Thanks you in advance.
0
Comment
Question by:mannevenu26
[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
2 Comments
 
LVL 101

Assisted Solution

by:mlmcc
mlmcc earned 200 total points
ID: 40315549
Something like this

Private class Struct_XYZ
{
   Long CellID;
   Double[ ]  P_Pos;
   Long[ ] W_IDs; 
   Double[ ] W_Vectors;
   Double [ ] W_Distance; 
   Double Shortest; 
   Double[ ] W_Vector_Shortest;
   Long W_ID_Shortest;
   int Number_of_XYZ ;
}

Open in new window


mlmcc
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 300 total points
ID: 40315604
You would also need to initialize the arrays.  So if Max_XYZ is a variable (as apposed to a constant), then it would be:
struct Struct_XYZ
{
    public Struct_XYZ(int Max_Num_XYZ)
    {
        CellID = 0;
        P_Pos = new double[3]; //indexed 0-2
        W_IDs = new long[Max_Num_XYZ]; //indexed 0 to Max_Num_XYZ-1
        W_Vectors = new double[3, Max_Num_XYZ];  //indexed 0-2 & 0 to Max_Num_XYZ-1
        W_Distance = new double[Max_Num_XYZ]; //indexed 0 to Max_Num_XYZ-1
        Shortest = 0;
        W_Vector_Shortest = new double[3];  //index 0-2
        W_ID_Shortest = 0;
        Number_of_XYZ = 0;
    }
    long CellID;
    double[] P_Pos;
    long[] W_IDs;
    double[,] W_Vectors;
    double[] W_Distance;
    double Shortest;
    double[] W_Vector_Shortest;
    long W_ID_Shortest;
    int Number_of_XYZ;
}

Open in new window


All of the arrays are 0 based (as apposed to 1 based in VBA),   So to access the 3rd item in the W_Distance array, you would do this:
   StructInst.W_Distance[2]=5;

In C# you have both classes and structs.  A class is allocated on the heap (the variable is a pointer to the allocated memory), while a struct is allocated on the stack (the variable is the direct memory pointer to the stack).  The main difference, is a struct is passed by value when it is used as a function parameter (a copy is sent to the function).  For a class, the variable is passed by reference.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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