Apostolic Friends Forum
Tab Menu 1
Go Back   Apostolic Friends Forum > The Foyer > The Information Station > Tech Talk: with Bit & Byte
Facebook

Notices

Tech Talk: with Bit & Byte For all those that speak Geek & Greek among us! Or for those technically challenged who don't!


 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-19-2007, 08:35 AM
BUPC-HCB
Guest


 
Posts: n/a
Visual Studio 2005

Does anybody here have experience with Visual Studio 2005? Would you mind helping out a beginner? I'm not necessarily looking for THE answer, but I just think there's bound to be a better way than I've done it here. Any pointers or advice would be appreciated.

I am studying arrays and loops and I have to create a matrix calculator. I have two 3x3 matrices to be added together to create a third results matrix. Nine 2 character input text boxes are provided for input per matrix.

I already have created a program, but I'm looking for alternatives. Specifically, I'm trying figure out if I could have handled the input matrix populations and the calculations by using an array loop. The following is my code:
============
Option Explicit On
Option Strict On

Public Class frmMatrixCalculator
Dim arMatrix1(0 To 2, 0 To 2) As Integer
Dim arMatrix2(0 To 2, 0 To 2) As Integer
-----
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
'Declaring Matrix1 and it's corresponding text input boxes.
arMatrix1(0, 0) = CInt(txtM1_00.Text)
arMatrix1(0, 1) = CInt(txtM1_01.Text)
arMatrix1(0, 2) = CInt(txtM1_02.Text)
arMatrix1(1, 0) = CInt(txtM1_10.Text)
arMatrix1(1, 1) = CInt(txtM1_11.Text)
arMatrix1(1, 2) = CInt(txtM1_12.Text)
arMatrix1(2, 0) = CInt(txtM1_20.Text)
arMatrix1(2, 1) = CInt(txtM1_21.Text)
arMatrix1(2, 2) = CInt(txtM1_22.Text)

'Declaring Matrix2 and it's corresponding text input boxes.
arMatrix2(0, 0) = CInt(txtM2_00.Text)
arMatrix2(0, 1) = CInt(txtM2_01.Text)
arMatrix2(0, 2) = CInt(txtM2_02.Text)
arMatrix2(1, 0) = CInt(txtM2_10.Text)
arMatrix2(1, 1) = CInt(txtM2_11.Text)
arMatrix2(1, 2) = CInt(txtM2_12.Text)
arMatrix2(2, 0) = CInt(txtM2_20.Text)
arMatrix2(2, 1) = CInt(txtM2_21.Text)
arMatrix2(2, 2) = CInt(txtM2_22.Text)

'Setting the Matrix1 variables and values
Dim intM1_00 As Integer = arMatrix1(0, 0)
Dim intM1_01 As Integer = arMatrix1(0, 1)
Dim intM1_02 As Integer = arMatrix1(0, 2)
Dim intM1_10 As Integer = arMatrix1(1, 0)
Dim intM1_11 As Integer = arMatrix1(1, 1)
Dim intM1_12 As Integer = arMatrix1(1, 2)
Dim intM1_20 As Integer = arMatrix1(2, 0)
Dim intM1_21 As Integer = arMatrix1(2, 1)
Dim intM1_22 As Integer = arMatrix1(2, 2)

'Setting the Matrix2 variables and values
Dim intM2_00 As Integer = arMatrix2(0, 0)
Dim intM2_01 As Integer = arMatrix2(0, 1)
Dim intM2_02 As Integer = arMatrix2(0, 2)
Dim intM2_10 As Integer = arMatrix2(1, 0)
Dim intM2_11 As Integer = arMatrix2(1, 1)
Dim intM2_12 As Integer = arMatrix2(1, 2)
Dim intM2_20 As Integer = arMatrix2(2, 0)
Dim intM2_21 As Integer = arMatrix2(2, 1)
Dim intM2_22 As Integer = arMatrix2(2, 2)

'Set the variables for the results matrix and do the math.
Dim intMR_00 As Integer = intM1_00 + intM2_00
Dim intMR_01 As Integer = intM1_01 + intM2_01
Dim intMR_02 As Integer = intM1_02 + intM2_02
Dim intMR_10 As Integer = intM1_10 + intM2_10
Dim intMR_11 As Integer = intM1_11 + intM2_11
Dim intMR_12 As Integer = intM1_12 + intM2_12
Dim intMR_20 As Integer = intM1_20 + intM2_20
Dim intMR_21 As Integer = intM1_21 + intM2_21
Dim intMR_22 As Integer = intM1_22 + intM2_22

'Populate the results matrix
txtMR_00.Text = CStr(intMR_00)
txtMR_01.Text = CStr(intMR_01)
txtMR_02.Text = CStr(intMR_02)
txtMR_10.Text = CStr(intMR_10)
txtMR_11.Text = CStr(intMR_11)
txtMR_12.Text = CStr(intMR_12)
txtMR_20.Text = CStr(intMR_20)
txtMR_21.Text = CStr(intMR_21)
txtMR_22.Text = CStr(intMR_22)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'End the program operation, clear all variables, close the form.
Close()
End Sub
--------
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Setting variables for the types of objects to clear.
Dim ctrl As Control
Dim txt As TextBox
'Running a For loop to clear all the textboxes and prepare for new entry.
For Each ctrl In Me.Controls
If (ctrl.GetType() Is GetType(TextBox)) Then
txt = CType(ctrl, TextBox)
txt.Text = ""
'I added this line to return focus to the first box of Matrix1.
txtM1_00.Focus()
End If
Next
End Sub
End Class
Reply With Quote
 

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Are You Visual? Digging4Truth Fellowship Hall 14 03-22-2007 08:09 AM

 
User Infomation
Your Avatar

Latest Threads
- by coksiw

Help Support AFF!

Advertisement




All times are GMT -6. The time now is 03:18 PM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.