25 pts.
 Defining a diagonal matrix in VB 6
Hi. I am having trouble defining a diagonal matrix. I am using code that is something like public diagmatrix(numofm, numofm) as long (numofm has been pre-set as some number) but i'm getting an error message, "constant expression required". Thing is, to begin with, the number of columns and rows (square matrix) should be equal to "numofm"; this is because "numofm" will change on different occassions as selected by users and the code " public diagmatrix(numofm, numofm) as long" was meant to allow the matrix dimensions to change accordingly. Secondly, the diagonal elements are dependent on other variables, say, 3 variables, temperature, pressure and thrust. This would thus require a 3by3 diagonal matrix. How would I define these diagonal elements ? Say, Row1, column 1 should be reciprocal of temp. Row2, column 2 should be reciprocal of pressure Row3, column 3 should be reciprocal of thrust Every other element would ofcoure be zero, being a diagonal matrix. Temp, pressure and thrust are variables and users can add to these, thus requiring a larger matrix---or reduce these variables, thus requiring a smaller matrix. Thanks.

Software/Hardware used:
ASKED: January 15, 2009  10:18 PM
UPDATED: January 24, 2009  8:38 PM

Answer Wiki:
To be able to redimension an array, you need to use a dynamic array. To define a dynamic array use a Dim, Public, Private, or Static statement with empty parentheses. For example: <pre> Private diagmatrix() as long</pre> This way, you can redimension it as needed with a ReDim statement, for example: <pre>ReDim diagmatrix(numofm, numofm) as long</pre> As for your second point, I'm not sure to understand what you are asking for. I just wanted to say thankyou very much for your help; much appreciated. Frank.
Last Wiki Answer Submitted:  January 24, 2009  8:38 pm  by  ITKE   16,755 pts.
All Answer Wiki Contributors:  ITKE   16,755 pts. , Frankly747   25 pts. , carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _