The important point is that it's simple, can easily be extended.
(Un-comment two lines in the source to get a different behavior for example)
There is hardly any practical use for this (normally),
but the way I made the code it would be possible to use it as a very cool "busy" state when doing lookups or calculations. (instead of a looping progressbar which is kinda wrong per design guidelines)
It sure beats a "Busy..." or "Working..." though right?
Also as noted in the source (un-comment the specified line to see it),
you can keep changing the value passed to the routine.
PS! The beep stuff was done like this since Beep_() does not work on Vista x64 it seems (no beep driver?). The beep I do here should work as long as windows sounds are enabled obviously.
Oh yeah! This source is considered public domain, use and abuse, have fun.
Code: Select all
EnableExplicit
Procedure.s NumberCruncher(number.q,size.i,length.i,characters$)
Static cycle.i=0
Protected result$,c.i,l.i,n.i,cycles.i,text$,*chars.Character,*numbers.Character
result$=Str(number)
l=Len(result$)
cycles=Len(characters$)-1
If l<size
l=size
EndIf
result$=RSet(result$,l,"0")
If length>0 And size>0 And cycles>0
c=cycle
n=l-length
;The char pointers is similar to Mid() only faster as
;we are working with purely known values/limits.
*chars=@characters$+(c*SizeOf(Character))
Repeat
;Just a quick hack to show the characters random instead.
;*chars=@characters$+(Random(cycles)*SizeOf(Character))
*numbers=@result$+(n*SizeOf(Character))
*numbers\c=*chars\c
n+1
Until n=l
cycle+1
If cycle>cycles
cycle=0
EndIf
EndIf
ProcedureReturn result$
EndProcedure
;Debug NumberCruncher(12345678,10,1,"|\-/")
Define event.i,number.q,crunch$,length.i,size.i,time.l,oldtime.l,oldtime2.l
If OpenWindow(0,0,0,322,40,"Number Cruncher (Visual Effect)",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
StringGadget(0,8,10,306,20,"",#PB_String_ReadOnly)
;The series of characters to show while "crunching".
crunch$="0123456789"
number=12345678 ;The number to display.
size=10 ;How long you want the number to be, will be padded if needed.
length=10 ;How much of the number to "crunch", normally you set this t the same as size.
time=ElapsedMilliseconds()
oldtime=time
oldtime2=time
Repeat
event=WaitWindowEvent(1)
time=ElapsedMilliseconds()
If (time-oldtime)>=100
If length>0
SetGadgetText(0,NumberCruncher(number,size,length,crunch$))
If (time-oldtime2)>=2000
length-1 ;reduce crunch length to simulate progress.
;Uncomment the next line for a special "live" of a changing code, aka "crunch'n'sync".
;number*2
;Since Beep_() do not work on Vista x64, this is a good alternative, or use PB's PlaySound()
sndPlaySound_("beep.wav",#SND_ASYNC)
oldtime2=time
EndIf
EndIf
oldtime=time
EndIf
Until event=#PB_Event_CloseWindow
EndIf