# Gauss-Jordan Elimination Calculator

Page 1 of 1

## 10 Replies - 4269 Views - Last Post: 18 August 2013 - 12:39 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=327237&amp;s=e373184875fd46a07701744e6f6642e4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 julietcapulet

Reputation: 0
• Posts: 7
• Joined: 17-August 13

# Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 02:45 PM

I am doing a Gauss-Jordan reduction Method calculator but I am new to vb6 and does not know how to execute the codes. I managed to create a code here...
```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
If Text1(0).Text <> 0 Then
For a = 0 To 4
Text1(a).Text = Text1(a).Text / Text1(0).Text
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

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

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 - (textbox1(a).Text * Text2(1).Text)
ElseIf Text3(a).Text = 1 Then
For a = 0 To 4
Text3(a).Text = Text3(a).Text - (textbox1(a).Text * Text3(1).Text)
ElseIf Text4(a).Text = 1 Then
For a = 0 To 4
Text4(a).Text = Text4(a).Text - (textbox1(a).Text * Text4(1).Text)
End If

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 - (textbox1(a).Text * Text2(2).Text)
ElseIf Text3(a).Text = 1 Then
For a = 0 To 4
Text3(a).Text = Text3(a).Text - (textbox1(a).Text * Text3(2).Text)
ElseIf Text4(a).Text = 1 Then
For a = 0 To 4
Text4(a).Text = Text4(a).Text - (textbox1(a).Text * Text4(2).Text)
End If

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 - (textbox1(a).Text * Text2(3).Text)
ElseIf Text3(a).Text = 1 Then
For a = 0 To 4
Text3(a).Text = Text3(a).Text - (textbox1(a).Text * Text3(3).Text)
ElseIf Text4(a).Text = 1 Then
For a = 0 To 4
Text4(a).Text = Text4(a).Text - (textbox1(a).Text * Text4(3).Text)
End If

Exit Sub

```

my question is, is my execution of code correct and what is "Else without if error"? I keep getting this error whenever I run the program.What can you suggest that I should do to make my program functional.Thank you for the help..I have attached a picture of how it should look

#### Attached image(s)

Is This A Good Question/Topic? 0

## Replies To: Gauss-Jordan Elimination Calculator

### #2 maj3091

• D.I.C Lover

Reputation: 324
• Posts: 1,924
• Joined: 26-March 09

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 03:02 PM

OK, a couple of pointers for you....

1. If you're new to VB6, then it might be worth investing your time and effort into the newer VB.Net, as VB6 is an old language now.

2. You need to get a grasp on Loops and Conditionals, as you're missing some bits of code in there. For example, a For loop would normally be in the format of

```For variable = StartVal to EndVal
'Do what you want in here
Next variable
```

The If conditional would be something like:

```If ConditionalStatement Then
'one or more statements to be executed if condition is true
Else
'one or more statements to be executed if condition is false
End If
```

or the extended version would be something like this:

```If ConditionalStatement_1 Then
'one or more statements to be executed if condition 1 is true
ElseIf ConditionalStatement_2 Then
'one or more statements to be executed if condition 2 is true
. . .
ElseIf ConditionalStatement_n Then
'one or more statements to be executed if condition n is true
Else
'one or more statements to be executed if none of the above conditions is true
End If
```

Now it would be worth revisiting your code using the information above and then see how you get on.

This post has been edited by maj3091: 17 August 2013 - 03:07 PM

### #3 julietcapulet

Reputation: 0
• Posts: 7
• Joined: 17-August 13

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 03:15 PM

i know that vb6 is already an old language now, but we are assigned to use vb6....

This post has been edited by andrewsw: 17 August 2013 - 03:17 PM
Reason for edit:: Removed unnecessary quote

### #4 julietcapulet

Reputation: 0
• Posts: 7
• Joined: 17-August 13

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 03:44 PM

here is my code with explanations

``` 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

```

### #5 andrewsw

• But the opposite, you said.

Reputation: 5520
• Posts: 21,779
• Joined: 12-December 12

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 04:16 PM

Why are you using c-style comments /* */ rather than the VB comment delimiter, the apostrophe ? Without these no-one can just copy and paste your code making it more difficult for someone to help you. The VB Editor would not have allowed you to use these comments without producing lots of error messages.

If you receive this error "Else without if error" then what line does it take you to in your posted code? However, you should indent your code properly and it will be much easier for you to spot the missing If or other syntax errors.

This post has been edited by andrewsw: 17 August 2013 - 04:21 PM

### #6 julietcapulet

Reputation: 0
• Posts: 7
• Joined: 17-August 13

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 04:24 PM

Sorry, I am still new to vb6...
```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'
'(here is where the "else without if" error points..)'
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

```

### #7 andrewsw

• But the opposite, you said.

Reputation: 5520
• Posts: 21,779
• Joined: 12-December 12

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 04:29 PM

It is not the If that is causing the error but the fact that your For statements have no matching Next.

There are a number of logic and other coding errors. You need to study, as maj3091 has already suggested, the fundamentals of the language, including variable scope, conditional statements (if) and looping structures.

### #8 julietcapulet

Reputation: 0
• Posts: 7
• Joined: 17-August 13

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 04:45 PM

I am getting a "sub or function not defined" on line 17, the i(a) part
``` i(a) = Text2(a).Text

```

This post has been edited by andrewsw: 17 August 2013 - 04:46 PM

### #9 andrewsw

• But the opposite, you said.

Reputation: 5520
• Posts: 21,779
• Joined: 12-December 12

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 04:49 PM

Yes, so what do you know about variable scope?

### #10 julietcapulet

Reputation: 0
• Posts: 7
• Joined: 17-August 13

## Re: Gauss-Jordan Elimination Calculator

Posted 17 August 2013 - 05:09 PM

I already declared the i()....what should I do to remove the error??

### #11 maj3091

• D.I.C Lover

Reputation: 324
• Posts: 1,924
• Joined: 26-March 09

## Re: Gauss-Jordan Elimination Calculator

Posted 18 August 2013 - 12:39 AM

juliet, andrew has already mentioned variable scope in two of his posts.

Have a look at where you declared your variable....have a look at where you're trying to use it.....now have a look at this link to see if you can understand variable scope and resolve your error.