|
Post by Rod on Nov 26, 2022 5:21:42 GMT -5
Can anyone see why Liberty gets hung up on this?
for n=1 to 10 n$=right$("000"+str$(int(rnd(0)*200)),3) next
|
|
|
Post by tsh73 on Nov 26, 2022 6:01:05 GMT -5
Interesting. It depends on randomize, so with randomize 0.1 it dies on 12 th number I tried to print these numbers If n= 12 then print rnd(0)*200 but I see nothing interesting  But moving rnd out of formula ( assigning to a variable) helps. Also Number in error message is string length under right$. And removing right$ removes error. Also Saving string into a var and then making right$ removes error. Also removing str$ and int does not help n$=right$("000";rnd(0)*200,3) Still dies. Left$ and mid$ seems work OK.
|
|
|
Post by Rod on Nov 26, 2022 7:56:10 GMT -5
This is my error log, My guess is that either the loop index or string index is being compromised. One for Carl. I am pretty sure I have used such code in the past.
Error log timestamp Saturday 26/11/22 12:55:11
Runtime error: index: 6 is outside of collection bounds
Error(Exception)>>defaultAction Error(Exception)>>activateHandler: <anUndefinedObject> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'index: 6 is outside ...'> BasicProgram(Object)>>error: <'index: 6 is outside ...'> 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: <'index: 6 is outside ...'> String(Object)>>error: <'index: 6 is outside ...'> String(IndexedCollection)>>errorInBounds: <6> String(IndexedCollection)>>checkIndex: <6> String>>at: <6> String>>replaceFrom: <1> to: <3> with: <'00089'> startingAt: <4> String(IndexedCollection)>>copyFrom: <4> to: <6> [] in BasicRight class>>using:program: BasicVariableAssigner>>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: <' for n=1 to 10 n$=...'> 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>
|
|
|
Post by tsh73 on Nov 26, 2022 13:57:25 GMT -5
Just for a record, it shows same problems in LB 4.04 and JB 2, JB 1.01
|
|
|
Post by pierre on Nov 26, 2022 17:29:24 GMT -5
for n=1 to 10 n$=right$("000"+str$(int(rnd(0)*200)),3) print n$ next
runs without any problem in RunBASIC and in LB 5 alpha
|
|
|
Post by xxgeek on Nov 26, 2022 22:06:56 GMT -5
hmm, very interesting.
As you'll see in the code many different experiments have been conducted.
NOTE: This code creates a file named testRandom.txt in DefaultDir$
A couple of possible "theories" to question. Just thoughts and more questions. The type a new LB programmer might ask.
1. Does n$ (or should I say int(rnd(0)*200) become too long and gets converted to an e num eg .00000000.......123 e^ and right$ or int() doesn't know what to do with it? I ask because during experiments I did see some of those numbers.
2. Does right$ use up too much memory trying to read a number longer than a set limit on strings (set by LB)? I ask because according to tsh73 and confirmed here.
---------
The lines in testRamdom.txt with numberHmmmm happen only when there is NO error.
on error goes straight to [errorr] without completing n$ -that's expected.
If n$ could be captured and investigated some more light could be shed. Anyone able to capture n$ when an error occurs?
on error goto [errorr] [start] open "testRandom.txt" for append as #1 [newNloop] #1 "Starting a new n loop" while errorr <1200 for n=1 to 100 x = x + 1 'n$=right$(rnd(0)*200,3) 'n$=right$("000";( (rnd(0) )*200),3) 'n$=right$(str$(int(rnd(0)*200)),3) 'n$=right$("000"; str$(( (int( (rnd(0)*200 ) ) ) )) , 3) 'n$=right$( "000"+str$( int( (rnd(0) ) *200)) ,3) #1 right$("000"+str$(int(rnd(0)*200)), 3)+ "Hmmm" '#1 "n$ = right$+000+str$(int(rnd(0)*200)) = ";right$("000"+str$(int(rnd(0)*200)), 3) 'print right$(n$, 3) + "right$(n$,3) = "; 'print mid$(n$, 4, 3),mid$(n$, 4, 3) + "mid$(n$, 4, 3) = " 'print left$(n$, (len(n$))-len(n$) ) + right$(n$, 3) + "left$(n$, (len(n$))-len(n$) ) + right$(n$, 3)" 'n$=right$("000"+str$(int(rnd(0)*200)),3) 'print "n = ";n 'print "n$ = ";n$ 'print "x = " ;x '#1 "n = ";n : #1 "n$ = ";n$ scan next scan wend scan goto [newNloop] [errorr] errorr = errorr + 1 if errorr > 1000 then close #1 : end #1 "Errorr - n = ";n #1 "Errorr - n$ = ";n$ '#1 "n$ = right$+000+str$(int(rnd(0)*200)) = ";right$("000"+str$(int(rnd(0)*200)), 3) '#1 "right$(n$,3) = ";right$(n$, 3);right$(n$, 3) '#1 "mid$(n$, 4, 3) = ";mid$(n$, 4, 3) 'n$=right$("000"+str$(int(rnd(0)*200)),3) #1 "x = " ;x #1 "n = ";n' : #1 "n$ = ";n$ #1 errorr;" errors out of ";x;" attempts" close #1 goto [start]
|
|