konijn
Junior Member
Posts: 96
|
Post by konijn on Jun 8, 2022 14:13:33 GMT -5
Hello,
I have a directory with logfiles, the have the same name except the last part thats the date and time. Now I want to open the latest file in that directory.
I managed to find the specific file but now how to open?
Thanks Jack
[begin] dim info$(10,10) DefaultDir$ ="C:\Users\info\Documents\KMW_Transfer" if fileExists(DefaultDir$, "CalfConsumption*.ads") then goto [inlees] else end end if [inlees] n= val(info$(0,0)) print info$(n, 2)
'not good!!
'open "C:\Users\info\Documents\KMW_Transfer\CalfConsumption*.ads" info$(n, 2)for input as #1 function fileExists(path$, filename$) 'dimension the array info$( at the beginning of your program files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by Chris Iverson on Jun 8, 2022 14:53:42 GMT -5
If you have the index of the file you want to use in the FILES array in variable n, then you should be able to use:
open "C:\Users\info\Documents\KMW_Transfer\" + info$(n, 0) for input as #1
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Jun 19, 2022 11:38:28 GMT -5
Thanks Chris. I have it working!
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Jun 19, 2022 11:41:45 GMT -5
Maybe I can ask here or I have to start a new thread? But can I upload data with Liberty basic to a MySql database?
I have data from a calverfeedstation which send data from how many feed they eat and I collect this data want to send it with LB to the database and present it on our website.
Thanks!
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Jun 20, 2022 12:21:49 GMT -5
I am struggling a bit. After the wend I can not display the band$(b). What is wrong. Code is litle bit a mess. I am testing the source datafile: DH99000100000000080009000020800090000308000900004060009000062400090000808000900009080 VH990001DD: 1996 20220620190439???????????????????????????????????????? DN003000000021011500000210004000900080150009000530800000200102000002002010000021030300000214104100800030020008001110100080003215000800035150 VN0030001723 0019625 ????????02B0020687????????????????????????????????? VN0030001843 0008???????????????????????01A0251001????????????????????????????????? VN0030001868 0013???????????????????????01A0230994????????????????????????????????? VN0030001876 0016549 ????????01A0110712????????????????????????????????? VN0030003299 0020624 ????????02A0040625????????????????????????????????? VN0030004141 0014547 ????????01A0280712????????????????????????????????? VN0030004359 0011???????????????????????01A0211001????????????????????????????????? VN0030004600 0007???????????????????????01A0251001????????????????????????????????? VN0030005451 0010???????????????????????01A0211001????????????????????????????????? VN0030005935 0023622 ????????02A0030606????????????????????????????????? VN0030006506 0021623 ????????02A0000625????????????????????????????????? VN0030007408 0022550 ????????02A0000625????????????????????????????????? VN0030007465 0018626 ????????02B0040687????????????????????????????????? VN0030007896 0012???????????????????????01A0260994????????????????????????????????? VN0030008555 0009???????????????????????01A0251001????????????????????????????????? VN0030009334 0015548 ????????01A0150712????????????????????????????????? DN00300100002101150000021000400000200102000002102080000022000200000220102000002139031000021060400000210503100002131031000021320300000313103100003132030000022020200000220302000002150043000021180400000211704300002148043000021490300000314804300003149030000021520400000215304000002104030000021600930000216109300003162093000041620930000216210300002164101 VN0030011723 0019022022060700020000000000040066060100????0000000000000000???0000???0000000001400000000000000864500000000000000000000000000000000026250 VN0030011843 0008012022041200000000000000000100000100????0000000000000000???0000???0000000007000000000000004246800000000000000000000000000000000000000 VN0030011868 0013012022050200000700000000050100050100????0000000000000000???0000???0000000005000000000000004190700000000000000000000000000000000000000 VN0030011876 0016012022060300000901930000055100085100????0000000000000000???0000???0000000001800000000000001421100000000000000000000000000000000000000 VN0030013299 0020022022061600010000000000045100030100????0000000000000000???0000???0000000000500000000000000266000000000000000000000000000000000000000 VN0030014141 0014012022060300000900000000075100075100????0000000000000000???0000???0000000001800000000000001505500000000000000000000000000000000000000 VN0030014359 0011012022041200000000000000000100000100????0000000000000000???0000???0000000007000000000000004588600000000000000000000000000000000000000 VN0030014600 0007012022041200000000000000000100000100????0000000000000000???0000???0000000007000000000000004230000000000000000000000000000000000000000 VN0030015451 0010012022041200000000000000000100000100????0000000000000000???0000???0000000007000000000000004581000000000000000000000000000000000000000 VN0030015935 0023022022061900010000000000050125045075????0000000000000000???0000???0000000000200000000000000133000000000000000000000000000000000000000 VN0030016506 0021022022061600010000000000030075045100????0000000000000000???0000???0000000000500000000000000252000000000000000000000000000000000000000 VN0030017408 0022022022061600010000000000030075050100????0000000000000000???0000???0000000000500000000000000252000000000000000000000000000000000000000 VN0030017465 0018022022060700020000000000040066065100????0000000000000000???0000???0000000001400000000000001071100000000000000000000000000000000017500 VN0030017896 0012012022050200000600000000050100050100????0000000000000000???0000???0000000005000000000000004110000000000000000000000000000000000000000 VN0030018555 0009012022041200000000000000000100000100????0000000000000000???0000???0000000007000000000000004203100000000000000000000000000000000000000 VN0030019334 0015012022060300000802100000050100080100????0000000000000000???0000???0000000001800000000000001444300000000000000000000000000000000000000
I need to extract some data off this file. I do it whit this code. Is it also possible to sort the data? [begin] dim info$(10,10) DefaultDir$ ="C:\Users\info\Documents\KMW_Transfer" if fileExists(DefaultDir$, "CalfConsumption*.ads") then goto [inlees] else end end if [inlees] n= val(info$(0,0))
print n print info$(n,0) open "C:\Users\info\Documents\KMW_Transfer\" + info$(n, 0) for input as #1 i=1 b=0 while eof(#1) = 0
dim txt$(3000) dim aa$(3000) dim ab$(3000) dim ac$(3000) dim ac(3000) dim ad$(1300) dim ae$(1300) dim af$(1300) dim ag$(1300) dim ag(1300) dim ag(1300) dim ah$(1300) dim ah(1300) dim ai$(1300) dim ai(3000) dim aj$(1300) dim aj(1300) dim ak$(1300) dim al$(1300) dim aitel$(1300) dim auto$(1300) dim kalf$(1300) dim band$(200) dim gift$(200) dim opname$(1200) 'for i = 1 to 3000 'txt$(i) = INPUT$(#1, 22) txt$(i) = INPUTTO$(#1, " ") 'use a blank space as delimiter if instr(txt$(i), "VN003001") = 1 then aa$(i)= INPUT$(#1, 10) ab$(i)= INPUT$(#1, 4) ac$(i)= INPUT$(#1, 2) ad$(i)= INPUT$(#1, 8) ae$(i)= INPUT$(#1, 2) af$(i)= INPUT$(#1, 2) ag$(i)= INPUT$(#1, 3) ah$(i)= INPUT$(#1, 7) ai$(i)= INPUT$(#1, 3) aj$(i)= INPUT$(#1, 3) ak$(i)= INPUT$(#1, 3) al$(i)= INPUT$(#1, 3) end if
if ab$(i)= "" then [next] if ac$(i)= "02"then
ag(i) =val(ag$(i)) ai(i) =val(ai$(i)) aj(i) =val(aj$(i)) ag(i)=((ai(i)/aj(i))*100)/10 ''ag(i)=200 auto$(i)="StBr" b=b+1 end if if ac$(i)= "01"then
ag(i) =val(ag$(i)) ai(i) =val(ai$(i)) aj(i) =val(aj$(i)) ag(i)=ag(i)/10
auto$(i)="DH" b=b+1 end if kalf$(i) = ab$(i)+" "+ auto$(i) 'print kalf$(i),i 'print kalf$(i), ac$(i), ad$(i), ae$(i), af$(i),using( "####", ag(i)), ai(i)/10, aj(i), ak$(i), al$(i) band$(b)= ab$(i) gift$(b)=using( "##.#", ag(i)) opname$(b)= Str$(ai(i)/10) print band$(b), b
[next] i=i+1
'print i
if i>=5000 then exit while
wend [einde] print b for b = 1 to b if kalf$(b)="" then next b print kalf$(b) 'print b 'next b 'for b = 1 to b 'print gift$(b) 'next b 'for b = 1 to b 'print opname $(b) 'next b print "einde"
close #1 end
function fileExists(path$, filename$) 'dimension the array info$( at the beginning of your program files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by Rod on Jun 20, 2022 13:34:29 GMT -5
Not had time to debug but first thoughts are that you use i twice 0-3000 and 0-200 do you not need two index variables.
To sort ALL of the data you need to get it in a single multi dimensioned array not dozens of different arrays. Then you can sort each record on any column and all other columns will stay in that order.
|
|
|
Post by tsh73 on Jun 20, 2022 14:57:36 GMT -5
After the wend I can not display the band$(b). What is wrong. easy, just do it
[einde] print b for j = 1 to b print band$(j), j next b
(it *does* work with for b = 1 to b as well, but this makes me feel uneasy)
EDIT having DIM inside a while loop effectively clears all arrays on each loop so band$(j) will always be "" (nothing)
So move all DIM's before WHILE
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Jun 21, 2022 12:17:28 GMT -5
Yes I see what I have done wrong. Newbie Thanks!! How can I print all the values from example band$(j) in one line, comma seperated? Like: band$(1),band$(2),band$(3),band$(4),band$(5),band$(6),band$(7),band$(8),........ and so on till the end off all values
|
|
|
Post by tsh73 on Jun 21, 2022 13:31:50 GMT -5
b=5 for j = 1 to b band$(j)=str$(j) next j
for j = 1 to b print band$(j); if j<>b then print ","; else print end if next j print "*over*"
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Jun 21, 2022 14:46:02 GMT -5
This is my result:
19,08,13,16,20,14,11,07,10,23,21,22,12,09,15 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 0,0,5,7.5,4.5,7.5,0,0,0,3,3,3,5,0,7.5
But I need to put the text before to make a graphic, but if I try I get the text before each aray
Title,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
And if I want to sort the first line, how to do with the other lines? That the right aray is by the right aray?
This what is has to be:
|
|
|
Post by tsh73 on Jun 21, 2022 15:21:24 GMT -5
Use build-in SORT command For that you should put your data in 2d array Since you are generating the data, you likely could do it more easily then me But then done, rest is really easy... (but I edited it third time because something still wrong %) )
16 source Title,19,8,13,16,20,14,11,7,10,23,21,22,12,9,15 Gift,0,0,6.5,9,5,9.5,0,0,0,4,4,4,5.5,0,8.5 Opname,0,0,5,7.5,4.5,7.5,0,0,0,3,3,3,5,0,7.5 sorted 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
a$="Title,19,08,13,16,20,14,11,07,10,23,21,22,12,09,15" b$="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" c$="Opname,0,0,5,7.5,4.5,7.5,0,0,0,3,3,3,5,0,7.5"
print numWords(a$) 'print numWords(b$) 'print numWords(c$) 'all says 16. Good... N=numWords(a$) dim a(N,3) for i = 2 to N a(i,1)=val(word$(a$,i,",")) a(i,2)=val(word$(b$,i,",")) a(i,3)=val(word$(c$,i,",")) next
print "source" gosub [showArr]
sort a(), 2,N,1
print "sorted" gosub [showArr]
end
[showArr] print word$(a$,1,",");","; for i=2 to N print a(i,1);word$(",", i<N); next print
print word$(b$,1,",");","; for i=2 to N print a(i,2);word$(",", i<N); next print
print word$(c$,1,",");","; for i=2 to N print a(i,3);word$(",", i<N); next print
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
|
|
|
Post by tsh73 on Jun 21, 2022 15:38:35 GMT -5
hope it is right now (print screen from LibreOffice)
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Jun 22, 2022 11:48:39 GMT -5
Thanks for the help!
How to get an array of this:
print word$(a$,1,",");","; for i=2 to N print a(i,1);word$(",", i<N);
|
|
|
Post by Rod on Jun 22, 2022 12:46:14 GMT -5
if you can print it then you can just as easily assign it.
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Jun 22, 2022 13:35:15 GMT -5
I tried with this code:
'print numWords(band$) 'print numWords(gift$) 'print numWords(opname$) 'all says 16. Good... N=numWords(band$) dim a(N,3) for i = 2 to N a(i,1)=val(word$(band$,i,",")) a(i,2)=val(word$(gift$,i,",")) a(i,3)=val(word$(opname$,i,",")) next
'print "source" gosub [showArr]
sort a(), 2,N,1
'print "sorted" gosub [showArr]
end
[showArr] print "Title"+word$(band$,1,","); for i=2 to N print #csv, a(i,1);word$(",", i<N); next print #csv,""
print "Gift"+word$(gift$,1,","); for i=2 to N print #csv, a(i,2);word$(",", i<N); next print #csv,""
print "Opname"+word$(opname$,1,","); for i=2 to N print #csv, a(i,3);word$(",", i<N); next print #csv,""
return
close #1 close #csv end
With this result:
8,13,16,14,11,7,10,12,9,15 0,6,9.5,10,0,0,0,4.5,0,9 0,5,7,7.5,0,0,0,2.5,0,7.5 7,8,9,10,11,12,13,14,15,16 0,0,0,0,0,4.5,6,10,9,9.5 0,0,0,0,0,2.5,5,7.5,7.5,7 How to do that the first three lines are not printed?
And it give a error for the file. I can not figure out what I do wrong?
Runtime error: Invalid file handle: #csv
Error(Exception)>>defaultAction Error(Exception)>>activateHandler: <anUndefinedObject> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'Invalid file handle:...'> BasicProgram(Object)>>error: <'Invalid file handle:...'> BasicProgram>>terminateRun: <anError> [] in BasicProgram>>errorHandlerBlock ExceptionHandler>>evaluateResponseBlock: <aBlockClosure> for: <anError> [] in ExceptionHandler>>handle: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>invisibleEnsure: <aBlockClosure> ExceptionHandler>>handle: <anError> ExceptionHandler>>findHandler: <anError> Error(Exception)>>activateHandler: <anExceptionHandler> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'Invalid file handle:...'> BasicProgram(Object)>>error: <'Invalid file handle:...'> [] in BasicProgram>>deviceAt: LinearHashTable>>lookUpValue: <'#csv'> for: <aDictionary> ifAbsent: <aBlockClosure> Dictionary>>at: <'#csv'> ifAbsent: <aBlockClosure> BasicProgram>>deviceAt: <'#csv'> [] in PrintCommand>>deviceCr:handle: BlockClosure>>value: <aBasicProgram> value: <'#csv'> value: <aBasicStringContext> BasicTripleParameterContextHolder>>value [] in BasicProgram>>begin ExceptionHandler>>evaluateProtectedBlock: <aBlockClosure> [] in ExceptionHandler>>activateDuring: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>invisibleEnsure: <aBlockClosure> ExceptionHandler>>activateDuring: <aBlockClosure> ExceptionHandler class>>handle: <anError class> with: <aBlockClosure> during: <aBlockClosure> BlockClosure>>on: <anError class> do: <aBlockClosure> BasicProgram>>begin BasicProgram>>run [] in BasicSourcePane>>run BasicCompiler class>>compileFromString: <'[begin] dim txt$(30...'> notify: <aBasicSourcePane> ifSuccess: <aBlockClosure> BasicSourcePane>>run BasicSourceWindow>>run BasicEditorModel>>run: <aToolbarButton> BasicEditorModel(Object)>>perform: <#run:> with: <aToolbarButton> ToolbarButton>>triggerClickedEvent Message>>perform NotificationManager>>runPendingEvents NotificationManager>>runEventLoop Message>>perform Message>>evaluate Process>>safelyEvaluate: <aMessage> Process>>evaluate: <aMessage>
|
|