Defining a diagonal matrix in VB 6

25 pts.
Tags:
Diagonal matrix
VB 6
Visual Basic
Visual Basic 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.
ASKED: January 15, 2009  10:18 PM
UPDATED: January 24, 2009  8:38 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following