# [RESOLVED] Classification

• March 19th, 2014, 12:29 PM
Eagle4
[RESOLVED] Classification
Hello there!
I am trying to make a programm that classifies data , but i don't get the right result.

Here is my code :
Code:

```Open "C:\Temp\data1.txt" For Input As #3 Open "C:\Temp\data2.txt" For Output As #4 Dim R(4) As Double Do While Not EOF(3) Input #3, R(1), R(2), R(3), R(4) For k = 1 To 4 If R(k) >= 0 And R(i) <= 10 Then R(k) = 1 ElseIf R(k) >= 11 And R(k) <= 20 Then R(k) = 2 ElseIf R(k) >= 21 And R(k) <= 30 Then R(k) = 3 ElseIf R(k) >= 31 And R(k) <= 40 Then R(k) = 4 ElseIf R(k) >= 41 And R(k) <= 50 Then R(k) = 5 End If Next k Print #4, R(1), R(2), R(3), R(4) Loop Close #4 Close #3```
For example i have d1 txt file :
 27 32 44 49 4 12 38 22

and the result must be :
 3 4 5 5 1 2 4 3

Any suggestion? Thanks anyway
• March 19th, 2014, 05:31 PM
DataMiser
Re: Classification
So what results are you getting?

At a glance the code looks like it should work assuming the file is comma delimited or each value is on a different line.
If the file looks like your sample then that would not work.

You also do not need so much code for example the second line of your If statement test if >=11 and <=20 but the code will not get there if it is not either <0 or >10
This could easier to read and likely faster using a select case
Code:

```Select Case R(k)   Case <0   Case <11       R(K)=1   Case <21   Case <31   Case <41   Case <51 End Select```
• March 19th, 2014, 06:13 PM
Eagle4
Re: Classification
Thank you very much!! Now it works great with case statement!
My previous code works fine only for the first line , not for the second,third etc...
Thanks once again!