I would like to share my doubt with you. I hope someone has the solution.
The result I want to get is this:
When opening the desktop app, a query on a Mysql database generates a multidimensional array (at least 12 columns with N rows).
And I would like to save it in a global property to use it later with other methods but basing my calculations always and only on the initial array created when opening.
This is because the initial query is a bit slow so I save it once and then calculate all the data.
How can I create this?
I state that I have already tried something but with little success.
Public Function SetMyArray() as String(,)
Dim sql as String, sqlcount as String, orderby as String, where as String
Dim arrayIMG(-1,-1) as String
Dim row As Integer
Dim rsc as RecordSet, numrec as integer, colrsc as Integer, dc as String, textpricedrop as String, textstockdrop as String
if DbConn then
try
sql = "SELECT DISTINCT id, code, brand, price, stock FROM products WHERE code is not null "
rsc = db.SQLSelect(sql)
row = 1
Redim arrayPRO(rsc.recordCount,rsc.fieldCount)
if rsc <> nil then
rsc.MoveFirst
colrsc = (rsc.FieldCount)
Do Until rsc.EOF
For i as Integer =1 to colrsc
arrayPRO(row,i) = rsc.IdxField(i).StringValue.DefineEncoding(Encodings.UTF8)
Next
row=row+1
rsc.MoveNext
Loop
rsc.Close
end
rsc=nil
db.Commit
db.Close
Exception
msgbox dbLinky.ErrorMessage
end
else
MsgBox “Connessione al db fallita”
end if
End Function
is inserted in the method.
Should I return and then declare it in the property?
What am I doing wrong?
Above all, does this process allow me to use an array throughout my desktop app and call it as many times as I need?
I’m not sure what this means. In your screenshot of the MyArray property, you show some code in the comments portion of the window. That is a comment only, not code.
You should have a global property named arrayPRO of type String(,). Put it in a Module and set it’s scope to Global. That will make it accessible throughout your app.
but I don’t understand where I’m wrong.
As you said, I created a property called “arrayPRO ()”, with type String (,) default value empty and scope Public.
I created a method that returns a recordset from an sql query, with a loop for each row of this recordset except for the whole array “arrayPRO”.
When I run it has 2 errors
Syntax error on the property “arrayPRO ()”
And
Window1.SetMyArray, line 58
This array has fewer dimensions than you have provided
If you put it in Window1, it’s only available in Window1. If you have other windows, then it should go into a module. If you only have the one window, then that’s fine.