cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
View Original Published Thread

How do I increment a loop using hexadecimal format?

kjdoran
Level II

Hello,

 

I want to create a list and populate it with the following entries: AB63, AB64,... AB79, AC63,...AZ79.

 

Unfortunately, I have not been able to figure out how to increment hexadecimally ("J" = Hex(4A) ,etc.)

 

So, for the letters J-O (Hex4A - Hex4F), I created separate loops, which is very cumbersome.

 

Does anyone know of a way to increment hexadecimally, so I can keep this all within one loop?

 

Thank you for your help.

 

Kevin

JMP17

 

// Loop rows AB-AI; loop columns 63-79
// A = ASCII (41)
// I = ASCII (49)
For( firstChar = 41, firstChar < 42, firstChar++, 
	For( secondChar = 41, secondChar < 50, secondChar++, 
		For( number = 63, number < 80, number++, 
			// Build the list element
			firstCharVal = Hex To Char( Char( firstChar ) );
			secondCharVal = Hex To Char( Char( secondChar ) );
			dataList[listIndex] = firstCharVal || secondCharVal || Char( number );
			// Increase the index
			listIndex++;
		);
	);
);

// Loop row AJ; loop columns 63-79
// J = ASCII (4A)
For( firstChar = 41, firstChar < 42, firstChar++, 
		For( number = 63, number < 80, number++, 
			// Build the list element
			firstCharVal = Hex To Char( Char( firstChar ) );
			dataList[listIndex] = firstCharVal || Hex To Char( "4A" ) || Char( number );
			// Increase the index
			listIndex++;
		);
);
 
Kevin Doran
1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User


Re: How do I increment a loop using hexadecimal format?

good call on ForEach!

first = {"A", "B"};
second = {"D", "E", "F"};
number = 9 :: 11;
For Each( {f}, first, //
	For Each( {s}, second, //
		For Each( {n}, number, //
			Write( Eval Insert( "\!n^f^^s^^right(char(/*6 digits of leading zeros*/1e6+n),2)^" ) )
		)
	)
);

AD09
AD10
AD11
AE09
AE10
AE11
AF09
AF10
AF11
BD09
BD10
BD11
BE09
BE10
BE11
BF09
BF10
BF11

 

Craige

View solution in original post

6 REPLIES 6


Re: How do I increment a loop using hexadecimal format?

You might have a look at the For Each() loop structure.  It has a much more flexible indexing structure.

Craige_Hales
Super User


Re: How do I increment a loop using hexadecimal format?

good call on ForEach!

first = {"A", "B"};
second = {"D", "E", "F"};
number = 9 :: 11;
For Each( {f}, first, //
	For Each( {s}, second, //
		For Each( {n}, number, //
			Write( Eval Insert( "\!n^f^^s^^right(char(/*6 digits of leading zeros*/1e6+n),2)^" ) )
		)
	)
);

AD09
AD10
AD11
AE09
AE10
AE11
AF09
AF10
AF11
BD09
BD10
BD11
BE09
BE10
BE11
BF09
BF10
BF11

 

Craige
kjdoran
Level II


Re: How do I increment a loop using hexadecimal format?

Craige,

 

Wow, thank you very much.  I will spend some more time with understanding the "Write" line.  I appreciate your help!

 

Kevin

Kevin Doran
lala
Level VIII


Re: How do I increment a loop using hexadecimal format?

txt="hex";first = {"A", "B"};
second = {"D", "E", "F"};
number = 9 :: 11;
For Each( {f}, first, //
	For Each( {s}, second, //
		For Each( {n}, number, //
			txt=txt||( Eval Insert( "\!n^f^^s^^right(char(1e6+n),2)^" ) )
		)
	)
);
d1=Open( Char To Blob(txt), "text" );
  • All to Craige! Learned it.

Thanks Experts!

Craige_Hales
Super User


Re: How do I increment a loop using hexadecimal format?

@lala  - interesting example. Explanation: the open function usually uses a filename for its first parameter, but can take a blob parameter of the actual data, which requires a second parameter since there is no file extension. "text" means interpret the data as a text file, which means a CSV-like file. This CSV has one value per line and no commas.

 

Craige
lala
Level VIII


Re: How do I increment a loop using hexadecimal format?

Thank Craige!

2024-05-17_18-04-34.png