Post by perfinit on Feb 17, 2020 15:02:05 GMT -5
I'm a true beginner with this code (something that I derived from my job where I do a good amount of work with EXCEL files - and, couldn't figure out a way to do this in EXCEL) - I've gone through the code several times - tried different things but still get the same output. I guess that I should be happy that I made it this far - LOL!.
Any help is greatly appreciated.
Thank you.
My input is as follows:
123456 7 14 pt 8 1
123456 7 14 ot 8 2
456789 34 52 sp 19 1
123456 7 14 ot 8 2
456789 34 52 sp 19 1
The output I'm receiving is as follows:
123456 7 14 pt 8 1 0 3 4 1 0 0 0 0 0 0 0 0
123456 7 14 0 8 0 0 0 0 0 0 0 0 0 0 0 0
2 0 456789 34 52 0 0 0 0 0 0 0 0 0 0 0 0 0
19 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
123456 7 14 0 8 0 0 0 0 0 0 0 0 0 0 0 0
2 0 456789 34 52 0 0 0 0 0 0 0 0 0 0 0 0 0
19 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The output is correct for the first record, but each subsequent record is offset to the right.
In addition, I get error warnings or messages that state:
1. that my file closings aren't what they should be.
2. that my program read past the end of file.
My code:
Print "Starting Program!"
comma$ = ","
open "c:\Liberty.Files\first1.csv" for input as #test
open "c:\Liberty.Files\opfirst1.csv" for output as #optest
while eof(#test) = 0
inputcsv #test, ID$, FWK, LWK, SRV$, WKS, FRQ
x = 0
z = 0
aa = 0
mo01 = 0
mo02 = 0
mo03 = 0
mo04 = 0
mo05 = 0
mo06 = 0
mo07 = 0
mo08 = 0
mo09 = 0
mo10 = 0
mo11 = 0
mo12 = 0
gosub [figureit]
print ID$
print #optest, ID$;comma$;FWK;comma$;LWK;comma$;SRV$;comma$;WKS;comma$;FRQ;comma$;mo01;comma$;mo02;comma$;mo03;comma$;mo04;comma$;mo05;comma$;mo06;comma$;mo07;comma$;mo08;comma$;mo09;comma$;mo10;comma$;mo11;comma$;mo12
wend
close #test
close #optest
END
[figureit]
for x = FWK to LWK step 1
gosub [getmonth]
next x
RETURN
[getmonth]
aa = FWK + z
z = z + 1
gosub [findmonth]
RETURN
[findmonth]
IF aa >= 01 and aa <= 05 THEN
mo01 = mo01 + FRQ
end if
IF aa >= 06 and aa <= 09 THEN
mo02 = mo02 + FRQ
end if
IF aa >= 10 and aa <= 13 THEN
mo03 = mo03 + FRQ
end if
IF aa >= 14 and aa <= 18 THEN
mo04 = mo04 + FRQ
end if
IF aa >= 19 and aa <= 22 THEN
mo05 = mo05 + FRQ
end if
IF aa >= 23 and aa <= 26 THEN
mo06 = mo06 + FRQ
end if
IF aa >= 27 and aa <= 31 THEN
mo07 = mo07 + FRQ
end if
IF aa >= 32 and aa <= 35 THEN
mo08 = mo08 + FRQ
end if
IF aa >= 36 and aa <= 40 THEN
mo09 = mo09 + FRQ
end if
IF aa >= 41 and aa <= 44 THEN
mo10 = mo10 + FRQ
end if
IF aa >= 45 and aa <= 48 THEN
mo11 = mo11 + FRQ
end if
IF aa >= 49 and aa <= 52 THEN
mo12 = mo12 + FRQ
end if
RETURN
comma$ = ","
open "c:\Liberty.Files\first1.csv" for input as #test
open "c:\Liberty.Files\opfirst1.csv" for output as #optest
while eof(#test) = 0
inputcsv #test, ID$, FWK, LWK, SRV$, WKS, FRQ
x = 0
z = 0
aa = 0
mo01 = 0
mo02 = 0
mo03 = 0
mo04 = 0
mo05 = 0
mo06 = 0
mo07 = 0
mo08 = 0
mo09 = 0
mo10 = 0
mo11 = 0
mo12 = 0
gosub [figureit]
print ID$
print #optest, ID$;comma$;FWK;comma$;LWK;comma$;SRV$;comma$;WKS;comma$;FRQ;comma$;mo01;comma$;mo02;comma$;mo03;comma$;mo04;comma$;mo05;comma$;mo06;comma$;mo07;comma$;mo08;comma$;mo09;comma$;mo10;comma$;mo11;comma$;mo12
wend
close #test
close #optest
END
[figureit]
for x = FWK to LWK step 1
gosub [getmonth]
next x
RETURN
[getmonth]
aa = FWK + z
z = z + 1
gosub [findmonth]
RETURN
[findmonth]
IF aa >= 01 and aa <= 05 THEN
mo01 = mo01 + FRQ
end if
IF aa >= 06 and aa <= 09 THEN
mo02 = mo02 + FRQ
end if
IF aa >= 10 and aa <= 13 THEN
mo03 = mo03 + FRQ
end if
IF aa >= 14 and aa <= 18 THEN
mo04 = mo04 + FRQ
end if
IF aa >= 19 and aa <= 22 THEN
mo05 = mo05 + FRQ
end if
IF aa >= 23 and aa <= 26 THEN
mo06 = mo06 + FRQ
end if
IF aa >= 27 and aa <= 31 THEN
mo07 = mo07 + FRQ
end if
IF aa >= 32 and aa <= 35 THEN
mo08 = mo08 + FRQ
end if
IF aa >= 36 and aa <= 40 THEN
mo09 = mo09 + FRQ
end if
IF aa >= 41 and aa <= 44 THEN
mo10 = mo10 + FRQ
end if
IF aa >= 45 and aa <= 48 THEN
mo11 = mo11 + FRQ
end if
IF aa >= 49 and aa <= 52 THEN
mo12 = mo12 + FRQ
end if
RETURN