Hello guys! I really need your help regarding this. I am asked to create somewhat a Gauss - Jordan Reduction Method calculator but I am having a hard time creating one. Is any one of you fammilliar with this method and can you help me??? This is the program that I have done so far...

Private Sub Form_Load()
Dim i() As Double

Private Sub Command1_Click()
Select Case Text1(0).Text
Case 1
Text1(0).Text = 1
Exit Sub

Case 2
If Text2(a).Text = 1 Then
For a = 0 To 4
i(a) = Text2(a).Text
Text2(a).Text = Text1(a).Text
Text1(a).Text = i

ElseIf Text3.Text = 1 Then
For a = 0 To 4
i(a) = Text3(a).Text
Text3(a).Text = Text1(a).Text
Text1(a).Text = i

ElseIf Text4.Text = 1 Then
For a = 0 To 4
i(a) = Text4(a).Text
Text4(a).Text = Text1(a).Text
Text1(a).Text = i

End If

Case 3
If Text1(a).Text = 0 Then
For a = 0 To 4
tex1(a).Text = Val((1 / i) * Text1(a).Text)
End If
End Sub

I really don't know what to do........thank you for your help...

this is the new codes that I have come up with.........

Private Sub Form_Load()
Dim i() As Double

End Sub

Private Sub Command1_Click()
Select Case Text1(0).Text
Case 1
Text1(0).Text = 1
Exit Sub

Case 2
If Text2(a).Text = 1 Then
For a = 0 To 4
i(a) = Text2(a).Text
Text2(a).Text = Text1(a).Text
Text1(a).Text = i

ElseIf Text3.Text = 1 Then
For a = 0 To 4
i(a) = Text3(a).Text
Text3(a).Text = Text1(a).Text
Text1(a).Text = i

ElseIf Text4.Text = 1 Then
For a = 0 To 4
i(a) = Text4(a).Text
Text4(a).Text = Text1(a).Text
Text1(a).Text = i

End If

Case 3
If Text1(a).Text = 0 Then
For a = 0 To 4
tex1(a).Text = Val((1 / i) * Text1(a).Text)
End If
Case 4
If Text2(a).Text <= 1 Then
For a = 0 To 4
Text2(a).Text = Val(Text2(a).Text - Text1(a).Text)

ElseIf Text3(a).Text <= 1 Then
For a = 0 To 4
Text3(a).Text = Val(Text3(a).Text - Text1(a).Text)

ElseIf Text4(a).Text <= 1 Then
For a = 0 To 4
Text4(a).Text = Val(Text4(a).Text - Text1(a).Text)
End If

I'm assuming this is a homework assignment. If so then you have two good reasons to add comments to your code

  1. you will probably lose marks if you don't
  2. it will be easier for us to offer help if we know what your code is supposoed to do
Private Sub Form_Load()
Dim i() As Double

Private Sub Command1_Click()
Select Case Text1(0).Text
/* here it says that textbox1 should be equal to 1 */
Case 1
Text1(0).Text = 1
Exit Sub
/* here if the ff. rows are equal to 1 then they must be replaced to the value of the row one aka textbox 1 */
Case 2
If Text2(a).Text = 1 Then
For a = 0 To 4
i(a) = Text2(a).Text
Text2(a).Text = Text1(a).Text
Text1(a).Text = i
ElseIf Text3.Text = 1 Then
For a = 0 To 4
i(a) = Text3(a).Text
Text3(a).Text = Text1(a).Text
Text1(a).Text = i
ElseIf Text4.Text = 1 Then
For a = 0 To 4
i(a) = Text4(a).Text
Text4(a).Text = Text1(a).Text
Text1(a).Text = i
End If
/* here it says that if the value of row1 or textbox1, then its value must turn to one by the performed formula */
Case 3
If Text1(a).Text = 0 Then
For a = 0 To 4
tex1(a).Text = Val((1 / i) * Text1(a).Text)
End If
End Sub

the first row should be always equal to one

I have created a new code for my program...

Private Sub Form_Load()
Dim i() As Double
Dim a As Double
End Sub

Private Sub Command1_Click()
Select Case Text1(0).Text
Case 1
/* this is for the 1st textbox to make the value =1 */
If Text1(0).Text <> 0 Then
For a = 0 To 4
Text1(a).Text = Text1(a).Text / Text1(0).Text
/*if the 2nd textbox is = 1 then its value will be replaced with the value of the 1st textbox*/
ElseIf Text1(0).Text = 0 Then
For a = 0 To 4
i(a) = Text2(a).Text
Text2(a).Text = Text1(a).Text
Text1(a).Text = i(a)
End If

/*this is to make the value of the 2nd,3rd and 4th textboxes = 0*/
Case 2
If Text2(a).Text = 1 Then
For a = 0 To 4
Text2(a).Text = Text2(a).Text - (Text1(a).Text * Text2(0).Text)
ElseIf Text3(a).Text = 1 Then
For a = 0 To 4
Text3(a).Text = Text3(a).Text - (Text1(a).Text * Text3(0).Text)
ElseIf Text4(a).Text = 1 Then
For a = 0 To 4
Text4(a).Text = Text4(a).Text - (Text1(a).Text * Text4(0).Text)
End If

/*this for the 2nd column*/
Case 3
If Text1(1).Text <> 0 Then
For a = 0 To 4
Text1(a).Text = Text1(a).Text / Text1(1).Text
ElseIf Text1(1).Text = 0 Then
For a = 0 To 4
i(a) = Text2(a).Text
Text2(a).Text = Text1(a).Text
Text1(a).Text = i(a)

Case 4
If Text2(a).Text = 1 Then
For a = 0 To 4
Text2(a).Text = Text2(a).Text - (Text1(a).Text * Text2(1).Text)
ElseIf Text3(a).Text = 1 Then
For a = 0 To 4
Text3(a).Text = Text3(a).Text - (Text1(a).Text * Text3(1).Text)
ElseIf Text4(a).Text = 1 Then
For a = 0 To 4
Text4(a).Text = Text4(a).Text - (Text1(a).Text * Text4(1).Text)
End If

/*this for the 3rd column*/
Case 5
If Text1(2).Text <> 0 Then
For a = 0 To 4
Text1(a).Text = Text1(a).Text / Text1(2).Text
ElseIf Text1(2).Text = 0 Then
For a = 0 To 4
i(a) = Text2(a).Text
Text2(a).Text = Text1(a).Text
Text1(a).Text = i(a)

Case 6
If Text2(a).Text = 1 Then
For a = 0 To 4
Text2(a).Text = Text2(a).Text - (Text1(a).Text * Text2(2).Text)
ElseIf Text3(a).Text = 1 Then
For a = 0 To 4
Text3(a).Text = Text3(a).Text - (Text1(a).Text * Text3(2).Text)
ElseIf Text4(a).Text = 1 Then
For a = 0 To 4
Text4(a).Text = Text4(a).Text - (Text1(a).Text * Text4(2).Text)
End If

/*this for the 4th column*/
Case 7
If Text1(3).Text <> 0 Then
For a = 0 To 4
Text1(a).Text = Text1(a).Text / Text1(3).Text
ElseIf Text1(3).Text = 0 Then
For a = 0 To 4
i(a) = Text2(a).Text
Text2(a).Text = Text1(a).Text
Text1(a).Text = i(a)

Case 8
If Text2(a).Text = 1 Then
For a = 0 To 4
Text2(a).Text = Text2(a).Text - (Text1(a).Text * Text2(3).Text)
ElseIf Text3(a).Text = 1 Then
For a = 0 To 4
Text3(a).Text = Text3(a).Text - (Text1(a).Text * Text3(3).Text)
ElseIf Text4(a).Text = 1 Then
For a = 0 To 4
Text4(a).Text = Text4(a).Text - (Text1(a).Text * Text4(3).Text)
End If


Exit Sub

whenever I run my program an error "else without if" is being shown by the compiler. also the the error "sub or function " is appearing for i(a)... I will post a picture of what it should look....

Edited 3 Years Ago by akasekaihime: so many mistakes

If you are using case statements then you are doing it incorrectly. Reread the document you linked to at the top. All the algorithm requires is a couple of nested loops. Write out your program using pseudocode first.

Edited 3 Years Ago by Reverend Jim

an error "sub or function not defined" in line 16..in the 1(a) part...

i(a) = Text2(a).Text

what does that mean??

I tried this code:

Private Sub Command1_Click()
Dim i() As Double

For a = 0 To 4
`If Text1(0).Text <> 0 Then`
Text1(a).Text = Text1(a).Text /      Text1(0).Text
ElseIf Text1(0).Text = 0 Then
i(a) = Text2(a).Text
Text2(a).Text = Text1(a).Text
Text1(a).Text = i(a)
End If
Next
If Text2(a).Text = 1 Then
Text2(a).Text = Text2(a).Text - (Text1(a).Text * Text2(0).Text)
ElseIf Text3(a).Text = 1 Then
Text3(a).Text = Text3(a).Text - (Text1(a).Text * Text3(0).Text)
ElseIf Text4(a).Text = 1 Then
Text4(a).Text = Text4(a).Text - (Text1(a).Text * Text4(0).Text)
End If

but an error "type mismatch" is appearing and pointing to "If Text1(0).Text <> 0 Then"

Comments
Ever considered indenting?

VB will attempt to coerce a value into the type required for use. If the text has a value that can be coerced into a number then you can use math operators on it. However if the text box has text in it then the text cannot be coerced into a number and you get a type mismatch.
Set text 1 to a number, even to 0 before using operators on the value.

If you wish to be better at developing software, then I offer the following suggestions.
1. Use meaningful names. I have no idea what Text1, Text2, Text3 or Text4 mean. I have no idea why they have indexes. I don't know what i(a) is.
2. Make your code readable. Use indentation, blank lines, comments. Whatever it takes to guide your reader/client/customer/instructor.
2. Within the VB environment, use Option Explicit in the first lines of your code. It checks to make sure that variables are declared before they are used.
3. Do NOT rely on implicit type coercion.

Then, I would STRONGLY suggest doing your matrix work in internal arrays. Matrix(rowInx, ColInx) is more readable (and algorithmically easier to work with) then Text<1..4>(a).

Comments
Well said!
This article has been dead for over six months. Start a new discussion instead.