this program have 3 arrays.. x,y and z.. its multiply array x and array y and will display the answer in array z.. my problem is, how to make the answer displays at z? -
Private Sub Command1_Click()
-
-
Dim X(1 To 3, 1 To 3) As Integer
-
Dim Y(1 To 3, 1 To 3) As Integer
-
Dim Z(1 To 3, 1 To 3) As Integer
-
Dim row As Integer
-
Dim col As Integer
-
-
-
For row = 1 To 3
-
For col = 1 To 3
-
Z(row, col) = (X(row, 1) * Y(1, col)) + (X(row, 2) * Y(2, col)) + (X(row, 3) * Y(3, col))
-
-
Next
-
Next
-
-
txtZ(0 to 8)=Z(row, col)
-
-
End Sub
8 6567
Hi,
To Display the Result also, you need to loop through:
Check This : -
Private Sub Command1_Click()
-
-
Dim X(1 To 3, 1 To 3) As Integer
-
Dim Y(1 To 3, 1 To 3) As Integer
-
Dim Z(1 To 3, 1 To 3) As Integer
-
Dim row As Integer
-
Dim col As Integer
-
dim k As Integer
-
k=0
-
For row = 1 To 3
-
For col = 1 To 3
-
Z(row, col) = (X(row, 1) * Y(1, col)) + (X(row, 2) * Y(2, col)) + (X(row, 3) * Y(3, col))
-
txtZ(k)=Z(row, col)
-
k = k + 1
-
Next
-
Next
-
-
End Sub
Regards
Veena
-
A(1, 1) = txtA(0).Text
-
A(1, 2) = txtA(1).Text
-
A(1, 3) = txtA(2).Text
-
A(2, 1) = txtA(3).Text
-
A(2, 2) = txtA(4).Text
-
A(2, 3) = txtA(5).Text
-
A(3, 1) = txtA(6).Text
-
A(3, 2) = txtA(7).Text
-
A(3, 3) = txtA(8).Text
-
-
B(1, 1) = txtB(0).Text
-
B(1, 2) = txtB(1).Text
-
B(1, 3) = txtB(2).Text
-
B(2, 1) = txtB(3).Text
-
B(2, 2) = txtB(4).Text
-
B(2, 3) = txtB(5).Text
-
B(3, 1) = txtB(6).Text
-
B(3, 2) = txtB(7).Text
-
B(3, 3) = txtB(8).Text
-
-
-
is there any other way to load the value from the matrix? i use visual basic 6.0
I'm sure we can come up with much more compact (and possibly efficient) ways of doing this, using loops. But I'm short on time right now so I'll just say this...
If you are trying to place the results into the textboxes, then the statements coded in post #3 are backwards.
Also, I think line 12 in the original code posted in message #1 is probably wrong, but we can discuss that.
Hi,
Try This : -
Dim i As Integer
-
Dim j As Integer
-
Dim k As Integer
-
k= -1
-
For i= 1 To 3
-
For j = 1 To 3
-
k = k + 1
-
A(i , j) = txtA(k).Text
-
B(i , j) = txtB(k).Text
-
Next j
-
Next i
-
Regards
Veena
this is what i programmed.. -
Private Sub cmdExit_Click()
-
Unload Me
-
End Sub
-
-
Private Sub cmdXy_Click()
-
-
Dim A(1 To 6, 1 To 6) As Integer
-
Dim x(1 To 6, 1 To 4) As Integer
-
Dim y(1 To 4, 1 To 6) As Integer
-
Dim z(1 To 4, 1 To 6) As Integer
-
Dim row As Integer
-
Dim col As Integer
-
-
-
x(1, 1) = txtX(0).Text
-
x(1, 2) = txtX(1).Text
-
x(1, 3) = txtX(2).Text
-
x(1, 4) = txtX(3).Text
-
x(2, 1) = txtX(4).Text
-
x(2, 2) = txtX(5).Text
-
x(2, 3) = txtX(6).Text
-
x(2, 4) = txtX(7).Text
-
x(3, 1) = txtX(8).Text
-
x(3, 2) = txtX(9).Text
-
x(3, 3) = txtX(10).Text
-
x(3, 4) = txtX(11).Text
-
x(4, 1) = txtX(12).Text
-
x(4, 2) = txtX(13).Text
-
x(4, 3) = txtX(14).Text
-
x(4, 4) = txtX(15).Text
-
x(5, 1) = txtX(16).Text
-
x(5, 2) = txtX(17).Text
-
x(5, 3) = txtX(18).Text
-
x(5, 4) = txtX(19).Text
-
x(6, 1) = txtX(20).Text
-
x(6, 2) = txtX(21).Text
-
x(6, 3) = txtX(22).Text
-
x(6, 4) = txtX(23).Text
-
-
y(1, 1) = txtY(0).Text
-
y(1, 2) = txtY(1).Text
-
y(1, 3) = txtY(2).Text
-
y(1, 4) = txtY(3).Text
-
y(1, 5) = txtY(4).Text
-
y(1, 6) = txtY(5).Text
-
y(2, 1) = txtY(6).Text
-
y(2, 2) = txtY(7).Text
-
y(2, 3) = txtY(8).Text
-
y(2, 4) = txtY(9).Text
-
y(2, 5) = txtY(10).Text
-
y(2, 6) = txtY(11).Text
-
y(3, 1) = txtY(12).Text
-
y(3, 2) = txtY(13).Text
-
y(3, 3) = txtY(14).Text
-
y(3, 4) = txtY(15).Text
-
y(3, 5) = txtY(16).Text
-
y(3, 6) = txtY(17).Text
-
y(4, 1) = txtY(18).Text
-
y(4, 2) = txtY(19).Text
-
y(4, 3) = txtY(20).Text
-
y(4, 4) = txtY(21).Text
-
y(4, 5) = txtY(22).Text
-
y(4, 6) = txtY(23).Text
-
-
z(1, 1) = txtZ(0).Text
-
z(1, 2) = txtZ(1).Text
-
z(1, 3) = txtZ(2).Text
-
z(1, 4) = txtZ(3).Text
-
z(1, 5) = txtZ(4).Text
-
z(1, 6) = txtZ(5).Text
-
z(2, 1) = txtZ(6).Text
-
z(2, 2) = txtZ(7).Text
-
z(2, 3) = txtZ(8).Text
-
z(2, 4) = txtZ(9).Text
-
z(2, 5) = txtZ(10).Text
-
z(2, 6) = txtZ(11).Text
-
z(3, 1) = txtZ(12).Text
-
z(3, 2) = txtZ(13).Text
-
z(3, 3) = txtZ(14).Text
-
z(3, 4) = txtZ(15).Text
-
z(3, 5) = txtZ(16).Text
-
z(3, 6) = txtZ(17).Text
-
z(4, 1) = txtZ(18).Text
-
z(4, 2) = txtZ(19).Text
-
z(4, 3) = txtZ(20).Text
-
z(4, 4) = txtZ(21).Text
-
z(4, 5) = txtZ(22).Text
-
z(4, 6) = txtZ(23).Text
-
-
-
-
If optXy.Value = True Then
-
For row = 1 To 6
-
For col = 1 To 6
-
A(row, col) = (x(row, 1) * y(1, col)) + (x(row, 2) * y(2, col)) + (x(row, 3) * y(3, col)) + (x(row, 4) * y(4, col))
-
Next
-
Next
-
Else
-
For row = 1 To 6
-
For col = 1 To 6
-
A(row, col) = (x(row, 1) * z(1, col)) + (x(row, 2) * z(2, col)) + (x(row, 3) * z(3, col)) + (x(row, 4) * z(4, col))
-
Next
-
Next
-
End If
-
-
-
-
-
lbl11.Caption = A(1, 1)
-
lbl12.Caption = A(1, 2)
-
lbl13.Caption = A(1, 3)
-
lbl14.Caption = A(1, 4)
-
lbl15.Caption = A(1, 5)
-
lbl16.Caption = A(1, 6)
-
lbl21.Caption = A(2, 1)
-
lbl22.Caption = A(2, 2)
-
lbl23.Caption = A(2, 3)
-
lbl24.Caption = A(2, 4)
-
lbl25.Caption = A(2, 5)
-
lbl26.Caption = A(2, 6)
-
lbl31.Caption = A(3, 1)
-
lbl32.Caption = A(3, 2)
-
lbl33.Caption = A(3, 3)
-
lbl34.Caption = A(3, 4)
-
lbl35.Caption = A(3, 5)
-
lbl36.Caption = A(3, 6)
-
lbl41.Caption = A(4, 1)
-
lbl42.Caption = A(4, 2)
-
lbl43.Caption = A(4, 3)
-
lbl44.Caption = A(4, 4)
-
lbl45.Caption = A(4, 5)
-
lbl46.Caption = A(4, 6)
-
lbl51.Caption = A(5, 1)
-
lbl52.Caption = A(5, 2)
-
lbl53.Caption = A(5, 3)
-
lbl54.Caption = A(5, 4)
-
lbl55.Caption = A(5, 5)
-
lbl56.Caption = A(5, 6)
-
lbl61.Caption = A(6, 1)
-
lbl62.Caption = A(6, 2)
-
lbl63.Caption = A(6, 3)
-
lbl64.Caption = A(6, 4)
-
lbl65.Caption = A(6, 5)
-
lbl66.Caption = A(6, 6)
-
-
-
-
End Sub
-
-
Populating the arrays can be coded in a much more compact way using loops. For instance... -
Private Sub cmdXy_Click()
-
-
Dim A(1 To 6, 1 To 6) As Long
-
Dim x(1 To 6, 1 To 4) As Long
-
Dim y(1 To 4, 1 To 6) As Long
-
Dim z(1 To 4, 1 To 6) As Long
-
Dim row As Long
-
Dim col As Long
-
Dim Pointer As Long
-
-
For row = 1 To 6
-
For col = 1 To 4
-
x(row, col) = txtX(Pointer).Text
-
Pointer = Pointer + 1
-
Next
-
Next
-
-
Pointer = 0
-
For row = 1 To 4
-
For col = 1 To 6
-
y(row, col) = txtY(Pointer).Text
-
z(row, col) = txtZ(Pointer).Text
-
Pointer = Pointer + 1
-
Next
-
Next
I'm sure you could also combine these two sets of loops into a single one, but didn't have the time to play with it any more. In any case, one of the nice things about using loops like this is that if for example you decided to double the size of your array, the code hardly needs to be touched at all.
As for the actual calculation, I'm going to assume that your current code works. It could probably be rewritten to be a bit simpler by using another loop nested within row and col, which loops from 1 to 4. But it would run slower, and probably wouldn't be worth the effort.
Placing the results in the labels would also be much more compact if you make the labels into a control array. You can also "simulate" an array by building the control name dynamically. For example... -
For row = 1 To 6
-
For col = 1 To 6
-
Me.Control("lbl" & row & col).Caption = A(row, col)
-
Next
-
Next
-
Of course, it's a matter of personal preference as to which way you want to code this stuff. You have to weigh up what's important to you. Various techniques will affect the length of the code, the complexity, performance, memory usage and so on.
Hi,
Use Killer's Code for Calculations and
Displaying of Results in Label can be done this way : -
Dim i As Integer
-
Dim j As Integer
-
Dim ctl As TextBox
-
Dim TStr As String
-
For i = 1 To 6
-
For j = 1 To 6
-
TStr = "lbl" & i & j
-
Set ctl = Me.Controls(TStr)
-
ctl.Caption = A(i , j)
-
Next j
-
Next i
-
Regards
Veena
thank you.. i got it.. terima kasih..
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ben Ingram |
last post by:
Hi all,
I am writing a template matrix class in which the template parameters are
the number of rows and number of columns. There are a number of reasons
why this is an appropriate tradeoff for...
|
by: christopher diggins |
last post by:
Here is some code I wrote for Matrix multiplication for arbitrary
dimensionality known at compile-time. I am curious how practical it is. For
instance, is it common to know the dimensionality of...
|
by: robix |
last post by:
Hi again. I'm now asking your help because of a smal problem i'm getting
with my multiplication matrix code.
I'll try to give you as many details as possible.
My matrix structure:
typedef...
|
by: amitnanda |
last post by:
Hi Guys,
I have a matrix multiplication program in C that multiplies two
matrices.
When their size is 3*3 or 800*800, the program runs fine. But above
that size, I get a "segmentation fault"....
|
by: Frank-O |
last post by:
Hi ,
Recently I have been commited to the task of "translating" some complex
statistical algorithms from Matlab to C++. The goal is to be three
times as fast as matlab ( the latest) .
I've...
|
by: lituncse |
last post by:
dear friends,
i have come across a problem which is difficult to solve for me.it's about starssen's matrix multiplication.in general matrix multiplication we need 8 multiplications and 4 additions...
|
by: amitsoni.1984 |
last post by:
Hi,
Is there any direct function for matrix multiplication in Python or
any of its packages? or do we have to multiply element by element?
Thank you,
Amit
|
by: crazygrey |
last post by:
Hello, I'm a newbie to C++ so excuse me if my question was trivial but
it is important to me.
I'm implementing a simple code to find the forward kinematics of a
robot:
#include "stdafx.h"...
|
by: Sozos |
last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help.
#define index(i,j,power) (((i)<<(power))+(j))
void...
|
by: joegao1 |
last post by:
can some one give me a hint?
I want to program the code for matrix multiplication with as less arithmetical / multiplication operations as possible.
my task is to calculate the matrix...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |