Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the following code in VBA:
VB
For i = 1 To datalen
If (Sheets("data").Cells(2 + i, 2) >= fusionYmin) And (Sheets("data").Cells(2 + i, 2) <= fusionYmax) Then
            
            dataA = Sheets("data").Cells(2 + i, 3)
            AvgVolts = (Sheets("raster").Cells(raster + 1, 2) + Sheets("raster").Cells(raster + 1, 5)) / 2
            If (A - AvgA) <= threshold Then
                Corr_A(raster) = Corr_A(raster) + 1
            End If
raster = raster + 1


basically it takes a large number of cells, figures out if those meet a condition, if true then 1, and add all the 1's for a total. i've tried to mimic the code in c#

but what i'm getting is not right (the VBA gives me around 15 average and i'm getting 1200 average with the c#). I can verify that the data[] and avgVolts[] arrays are indeed returning correct values

If anyone can help me with this i'd really appreciate it, and i'd be happy to give as much information as needed to solve this problem.

What I have tried:

C#
for (j = 0; j < data.Length; j++)
           {
               if (data[j].Y >= Convert.ToSingle(textBox3.Text) && data[j].Y <= Convert.ToSingle(textBox4.Text))
               {
                   for (i = 0; i < numRasters + 2; i++)
                   {
                       if (data[j].A - avgVolts[0][i] <= thresh)
                           corrA[i]++;

                   }
               }
           }
Posted
Updated 25-Oct-16 18:05pm
v3
Comments
Member 12815488 26-Oct-16 0:06am    
i've added to my question, the VBA does loops but the loops are far removed from the code snippet so i forgot them

i am using the debugger, it isn't giving me any reason that there is something wrong.

1 solution

The C# code have 2 loops and VBA code have 0 loop. I suspect something wrong here.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900