Hi there,

I am very very new to C++. A bit of background. I have been writing in excel vba for large number crunching, and the code is now taking quite a while to run. A friend of mine suggested i start writing in C++, so i read up on it. And downloaded Code:Blocks.

My VBA Code is:

Code:
Sub arrayss()

Dim NameArray As Variant
Dim datarray As Byte
Dim DirectionArray As Variant
Dim WinArr As Variant
Dim Results As Variant
Dim iColumns As Long
Dim jRows As Long
Dim a As Long
Dim b As Long
Dim c As Long
Dim q As Long
Dim tradevalue As Long
Dim noofrowsWin As Long
Dim noofcolumnsWin As Long
Dim cell1position As Long
Dim cell2position As Long
Dim cell3position As Long
Dim cell4position As Long
Dim cell1value As Long
Dim cell2value As Long
Dim cell3value As Long
Dim cell4value As Long
Dim y As Long
Dim z As Long



'Range("AN:BBB").Delete

Application.Calculation = xlCalculationManual

dataarray = ThisWorkbook.Names("Data1").RefersToRange.Value
NameArray = ThisWorkbook.Names("NameArray").RefersToRange.Value
DirectionArray = ThisWorkbook.Names("DirectionArray").RefersToRange.Value

cell1position = Sheets("Test").Cells(2, 3)
cell2position = Sheets("Test").Cells(3, 3)
cell3position = Sheets("Test").Cells(4, 3)
cell4position = Sheets("Test").Cells(5, 3)
cell1value = Sheets("Test").Cells(7, 3)
cell2value = Sheets("Test").Cells(8, 3)
cell3value = Sheets("Test").Cells(9, 3)
cell4value = Sheets("Test").Cells(10, 3)
tradevalue = Sheets("Test").Cells(12, 3)
jRows = 1
iColumns = 1
a = 3
b = 1
y = 0
z = 0
i = 1
j = 1
Sheets("Final").Cells(3, 1) = "=Counta(2:2)-1"
Sheets("Final").Cells(1, 2) = "=COUNTA(A:A)"
noofcolumnsWin = ((Sheets("Final").Cells(3, 1)) - 1) ^ 2 - (Sheets("Final").Cells(3, 1) - 1)
noofrowsWin = Sheets("Final").Cells(1, 2) + 1

ReDim Results(1 To 500, 1 To 16)
For q = 1 To UBound(dataarray, 2) - 1
    
    For c = 1 To UBound(dataarray, 2) - 1
        If c = q Then
        GoTo labelend3
        End If
        For jRows = 1 To UBound(dataarray, 1) - cell4position
            If IsEmpty(dataarray(jRows, q)) Or DirectionArray(jRows, 1) = 15 Or DirectionArray(jRows, 1) = 45 Then
            ElseIf dataarray(jRows + cell1position, c) = cell1value And dataarray(jRows + cell2position, c) = cell2value And dataarray(jRows + cell3position, c) = cell3value And dataarray(jRows + cell4position, c) = cell4value Then                 ' cell check
                If tradevalue = dataarray(jRows, q) Then            ' win or lose
                    y = y + 1
                Else
                    z = z + 1
                End If
            End If
        a = a + 1
labelend:
        Next
        
        If z = 0 Then
            z = 1
        End If
        
        If y = 0 Then
            y = 1
        End If
        
        If y > 20 And y / z > 5 Then
            Results(i, j) = NameArray(1, q)
            Results(i, j + 1) = NameArray(1, c)
            Results(i, j + 2) = y
            Results(i, j + 3) = z
            Results(i, j + 4) = y / z
            Results(i, j + 5) = cell1position
            Results(i, j + 6) = cell2position
            Results(i, j + 7) = cell3position
            Results(i, j + 8) = cell4position
            Results(i, j + 9) = ""
            Results(i, j + 10) = cell1value
            Results(i, j + 11) = cell2value
            Results(i, j + 12) = cell3value
            Results(i, j + 13) = cell4value
            Results(i, j + 14) = ""
            Results(i, j + 15) = tradevalue
            i = i + 1
        End If
        
        y = 0
        z = 0
        a = 3
        b = b + 1
        '''  PUT IN HERE THE TEST FOR COUNTING 1's and zeros or below lol
        ''''
labelend3:
    Next
a = 3
labelend1:
Next


Sheets("Test").Select
Range("an:an").End(xlDown).Offset(1, 0).Select
a = ActiveCell.Row
Range(Range("an" & a & ""), Range("an" & a & "").Offset(500, 16)).Value = Results
 
'Range(Range("m1"), Range("m1").Offset(10000, 16)).Value = Results
'Range(Range("g1"), Range("g1").Offset(noofrowsWin - 1, noofcolumnsWin - 1)).Value = WinArr
'Range(Range("g1"), Range("g1").Offset(noofrowsWin - 1, noofrowsWin - 1)).Value = Application.Transpose(WinArr)
    
Application.Calculation = xlCalculationAutomatic


End Sub
Ultimately i would like to recode this to C++, but my first and probably silly question is how do i get the data from Excel to use in C++. I was thinking either to put the data in 3 csv files and convert into three Arrays in C++. Or maybe create a library of the data in C++. Ultimately it is speed i am looking for, so before i start recoding i wanted to start with the best way.

Does that make sense?

The data is like this in excel: (don't know how to create a table)

ABC DCA GFE THE
15 0 1 0 1
30 1 0 1 0
45 1 1 0
00 0 0 1
15 1 1 0
15 1 0 0 1
15 0 1 1 1
30 1 0 0
45 1 1 1

So the headers would be in one array, the 15's, 30's etc would be in another array and the 1's and 0's and Empty ( i need it to record an empty cell) would be in another array

Rgds

Surreall

PS and thankyou for your time