Post by tsh73 on Jun 22, 2022 15:34:44 GMT -5
Your code is incomplete so it doesn't run.
If you want "first three lines are not printed",
comment out first call to [showArr] (just before SORT)
"And it give a error for the file."
- you should actually OPEN file before printing to it.
Fixed code
resulting file "data1.csv"
If you want "first three lines are not printed",
comment out first call to [showArr] (just before SORT)
"And it give a error for the file."
Runtime error: Invalid file handle: #csv
- you should actually OPEN file before printing to it.
Fixed code
band$="19,08,13,16,20,14,11,07,10,23,21,22,12,09,15"
gift$="0.0,0.0,6.5,9.0,5.0,9.5,0.0,0.0,0.0,4.0,4.0,4.0,5.5,0.0,8.5"
opname$="0,0,5,7.5,4.5,7.5,0,0,0,3,3,3,5,0,7.5"
'print numWords(band$)
'print numWords(gift$)
'print numWords(opname$)
'if all you have is numbers then there is 15 of them
N=numWords(band$)
dim a(N,3)
for i = 1 to N 'if title not in string, start from 1
a(i,1)=val(word$(band$,i,","))
a(i,2)=val(word$(gift$,i,","))
a(i,3)=val(word$(opname$,i,","))
next
'print "source"
open "data1.csv" for output as #csv
'if you do not need see data before sorting just comment next line
'gosub [showArr]
'if title not in string, start from 1
sort a(), 1,N,1
'print "sorted"
gosub [showArr]
close #csv
print "done"
run "explorer.exe data1.csv"
end
[showArr]
print #csv,"Title,"; 'put a comma after title!
'if title not in string, start from 1
for i=1 to N
print #csv, a(i,1);word$(",", i<N);
next
print #csv,""
print #csv,"Gift,";
for i=1 to N
print #csv, a(i,2);word$(",", i<N);
next
print #csv,""
print #csv,"Opname,";
for i=1 to N
print #csv, a(i,3);word$(",", i<N);
next
print #csv,""
return
function numWords(a$)
'delimited by (,)
i=1
while 1
w$=word$(a$,i,",")
if w$="" then exit while
i=i+1
wend
numWords=i-1
end function
resulting file "data1.csv"
Title,7,8,9,10,11,12,13,14,15,16,19,20,21,22,23
Gift,0,0,0,0,0,5.5,6.5,9.5,8.5,9,0,5,4,4,4
Opname,0,0,0,0,0,5,5,7.5,7.5,7.5,0,4.5,3,3,3