March 19th, 2014, 12:29 PM
I am trying to make a programm that classifies data , but i don't get the right result.
Here is my code :
For example i have d1 txt file :
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
Print #4, R(1), R(2), R(3), R(4)
and the result must be :
Any suggestion? Thanks anyway
March 19th, 2014, 05:31 PM
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
Select Case R(k)
Always use [code][/code] tags when posting code.
March 19th, 2014, 06:13 PM
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!
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.