MidStr Hex function needed

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

MidStr Hex function needed

Post by Bob Hansen » Thu Apr 03, 2003 8:41 pm

Need a MidStr HEX function and a HEX to Decimal conversion function.

Example below shows a line from a compiled file. I want to know the HEX value of a MidStr position. Perhaps an option to read MidStr in Hex/Octal vs decimal. Let decimal be default unless new parameter is selected. This would mean no more new commands, just a new parameter which should not affect earlier versions.
Perhaps MidStr>string,start,length,result,dec|hex|oct

Also want to convert a HEX value to a Decimal Value or Hex to Octal.
Perhaps ConvertHD>Hex,Decimal and ConvertHO>Hex,Octal functios?
=================================

Explanation of need:
Here is an example of a compiled file string to read. (Note the "spaces" that may not appear):
" FTP TO Q&A Robert "

The byte values of the file are:
OA 46 54 50 20 54 4F 20 51 26 41 0F 52 6F 62 65 72 74 20
F T P T O Q & A R o b e r t

So new function will allow:
MidStr>File,13,6,Result to get "Robert"
or
MidStr>File,13,6,Result,Hex to get "526F62657274"

I have just written a Macro Scheduler script to convert 2 character bytes from HEX to Decimal, but it would be nice to have a Hex conversion function available in Macro Scheduler. VB has Conversion to HEX, but not from HEX (or did I miss it somewhere?).

The example above was simple to display characters already displayed in decimal format, But the value in position 1 does not show as a readable decimal character, but does contain information that I need. This would allow me to run MidStr>File,1,1,Result,Hex to get "OA". I can now make decisions based on the value in position 1.

MidStr>File,1,2,Result,Hex
If>%Result%=OA,Action1
If>%Result%=OF,Action2
If>%Result%=A2,End

Label>Action1
ConvertHD>%Result%,Decimal
Message>Do Instruction Seventeen %Decimal%.times.
Goto>End

Label>Action2
Message>First value is not important. Do not do Instruction Seventeen
Goto>End

Label>End
=============================
Thanks for listening, maybe next release?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Sat Apr 05, 2003 11:03 am

I should imagine that it would be possible to create such a function with VBScript. I ain't even going to attempt one, for now anyway. :)

Anyway, Marcus is a nice guy, maybe he'll satisfy your request. :shock:

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Sat Apr 05, 2003 5:05 pm

VBSTART
VBEND

Let>DecVal=450
VBEval>Hex(%DecVal%),HexVal
MessageModal>HexVal

VBEval>CInt("&H" & "%HexVal%"),BackToDec
MessageModal>BackToDec
MJT Net Support
[email protected]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Apr 05, 2003 7:02 pm

Thanks for the start Support.

That coding will do the conversion from Hex to Decimal for me. But I still need to be able to read the string in HEX format to begin with. I don't want to convert the decimal character to HEX, I want to read the string into HEX format.

Example:

MidStr>ABCDEFGH,2,3,Result will now give me BCD as Result
MidStr>ABCDEFGH,2,3,Result,Hex would give me 42 43 44 as Result

Real example of file (TextPad macro "tpm file") I am trying to read:

After reading file to variable %Test%, I have:
%Test%=

FTP TO Q&ARobert M Hansen'Parses BUMED FTP file for Q&A importing ÿÿ CMacroStepGoto ÿÿ CMacroStepCommand)€€?ÿÿ CMacroStepReplace
The first character before "FTP" () is actually a decimal value of 10, but I cannot see that or calculate that because it is a "0A" in the compiled version. I want to do MidStr>%Test%,1,1,Result and get Result="0A". then I can convert the OA to 10. the other ""
characters are the same situation. I may want to read any/all of the them individually or as a string, getting the HEX values of the bytes so I can make my decisions based on the contents. The actual contents may be numbers or text, who knows?

I tried using MidStr>%Test%,1,1,Result and then using your code to convert it to HEX. Result =
, but the Hex conversion gives an error message: VB Script compilation error: 1002, Syntax Error, Line 25, column 4.

Hopefully this makes more sense now?
MidStr>%Test%,1,11,Result,Hex would give
Result= 0A 46 54 50 20 54 4F 20 51 26 41

Now I can do normal MidStr>%Result%,start,1,DecVal on any of those characters and convert them to decimal as needed.

Thanks again.....
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts