?
Solved

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

Posted on 2014-09-09
2
Medium Priority
?
264 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 800 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 1200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 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