` Comment on an Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Add a comment to an Icetips Article

Please add your comments to this article. Please note that you must provide both a name and a valid email address in order for us to publish your comment. Comments are moderated and are not visible until they have been approved. Spam is never approved!

Your Name:  
Email:  
Header text/Subject:  

Please enter your comment in the box below:

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Par2: Dynamically Dimensioned Arrays
2002-05-25 -- Randy Goodhew
 
Don't dismiss Routines as useless. They certainly have their place. Here's an example that uses a Routine to create Dynamically Dimensioned Arrays. Normally the DIM() value must be a constant, but in the context of a Routine, the DIM() value can be a variable, e.g.: ---------------------- DatHash PROCEDURE(STRING password)! ,STRING Dim LONG,AUTO ! Ushorts array dim Sum USHORT,AUTO ! sum of Ushorts SumBytes BYTE,DIM(2),OVER(Sum) ! parse bytes from Ushort Result STRING(16),AUTO ! two char password CODE Dim = LEN(CLIP(password)) / 2 ! calc array dimensions DO R_Calc Result = '''<<' & SumBytes[1] & ',' & SumBytes[2] & '>''' RETURN(Result) ! string like '<99,88>' R_Calc ROUTINE DATA ! Routine-level dynamic data Ushorts USHORT,DIM(Dim),OVER(password) ! dynamic array J LONG,AUTO ! loop counter CODE Sum = 0 ! init Sum LOOP J = 1 TO Dim ! loop thru password as Ushorts Sum += Ushorts[J] ! sum of Ushorts END !loop EXIT ------------------ BTW, this little algorithm will calculate the 16 bit Relative Password Hash for a Clarion DAT file (if the password is known). Note: Regardless of how large a password is for a Clarion DAT file, they can be reduced to one of 64K possible two character clones. Thus, the longer the password, the more coincidental dups there will be, essentially one in every 64K of character combinations. Routines are also useful in writing recursive algorithms, where the Routine can call itself, i.e. classical QuickSort algorithm.


Today is November 23, 2024, 3:31 am
This article has been viewed 35224 times.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: