- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How do I increment a loop using hexadecimal format?
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++;
);
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I increment a loop using hexadecimal format?
Thank Craige!