From: Henning on

"GS" <gesansom(a)netscape.net> skrev i meddelandet
news:htpsbg$qk$1(a)news.eternal-september.org...
> on 5/28/2010, Henning supposed :
>> "Derek" <derekrss(a)yahoo.ca> skrev i meddelandet
>> news:527036a6-1c91-40a9-8f89-673eb78cd857(a)q13g2000vbm.googlegroups.com...
>> On May 28, 4:13 pm, GS <gesan...(a)netscape.net> wrote:
>>> I'm thinking that I should retain the delimited values and dump it into
>>> an array using Split(). This would, at least, preserve the individual
>>> values return by the Hex2Dec function. Problem is, as you say, how to
>>> determine what the original string was from the resulting string. For
>>> example, returning Hex(14) returns "E" and not "0E".
>>>
>>> Any suggestions you have would be greatly appreciated.
>>>
>>
>> Returning RIGHT$(HEX$(256 + 14), 2) would return "0E"
>>
>> Cheers
>>
>> Derek
>>
>> ----
>> And so will Right$("0" & Hex$(14),2)
>>
>> /Henning
>
> True for this pair of hex digits. Not going to work for all pairs as does
> using '256'. Results using "0" instead of '256':
>
> Original hexString: "0E0E00000505000C20450164A5A5"
> Returns DecString: "14,14,0,0,5,5,0,12,32,69,1,100,165,165"
> Restore DecString returns: "EE00550C2045164A5A5", which is not what we
> want.
>
> regards,
>
> --
> Garry
>
> Free usenet access at http://www.eternal-september.org
> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>
>

Yes it *is* the same thing.

On a Form add a Commandbutton and a TextBox

Option Explicit



Private Sub Command1_Click()
Dim i As Long

Dim s1 As String
Dim s2() As String

s1 = "14,14,0,0,5,5,0,12,32,69,1,100,165,165"
s2 = Split(s1, ",")
Text1.Text = ""

For i = 0 To UBound(s2)
Text1.Text = Text1.Text & Right$("0" & Hex$(Val(s2(i))), 2)
Next
End Sub

The ouput in Text1.Text is "0E0E00000505000C20450164A5A5"

/Henning


From: Henning on

"GS" <gesansom(a)netscape.net> skrev i meddelandet
news:htprog$ube$1(a)news.eternal-september.org...
> Henning wrote :
>> "GS" <gesansom(a)netscape.net> skrev i meddelandet
>> news:htoutg$r7r$1(a)news.eternal-september.org...
>>> Thanks to all for replying! Unfortunately, after diligently trying each,
>>> none of the suggestions are working as expected. Here's what I'm trying
>>> to do:
>>>
>>> I have the following string of Hex values:
>>> "0E0E00000505000C20450164A5A5"
>>>
>>> which I need to convert to a delimited string of Dec values. The
>>> expected result is:
>>> "14,14,0,0,5,5,0,12,32,69,1,100,165,165"
>>>
>>> Since the source string of Hex values are paired, a delimited version of
>>> this would be:
>>> "0E,0E,00,00,05,05,00,0C,20,45,01,64,A5,A5"
>>>
>>> I was able to get the result using an Excel WorkSheetFunction provided
>>> by the Analyss Toolpak addin called Hex2Dec(). I would like to duplicate
>>> that function in VB6.
>>>
>>> Thanks in advance, again, for any suggested solutions.
>>>
>>> -- Garry
>>>
>>> Free usenet access at http://www.eternal-september.org
>>> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>>>
>>>
>>
>> That is not a string of Hex values, just a string of Hex digits.
>> For Hex values s = Chr$(14) & Chr$(14) & Chr$(0) & ....
>>
>> /Henning
>
> No, it's not a string of Hex values! It's a string of Dec values created
> by passing the original HexString (or Hex digits, as you say) to Excel's
> Analysis Toolpak Hex2Dec() function.
> For the record, Chr$(14) returns "", same as does Chr$(&H0E).
>
> The point of the exercise is to duplicate what Excel's Hex2Dec() does
> using VB[A]. What concerns me is the user claims to get different result
> for Chr$(&H0E), reporting that it returns "3045"!<???> I suspect he's
> using either a custom Hex2Dec() function, or a custom Chr() function, or
> both.
>
> regards,
>
> --
> Garry
>
> Free usenet access at http://www.eternal-september.org
> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>
>

Hint:
ASCII &H30 = "0" , ASCII &H45 = "E" in the ASCII table.

/Henning


From: Henning on

"GS" <gesansom(a)netscape.net> skrev i meddelandet
news:htprog$ube$1(a)news.eternal-september.org...
> Henning wrote :
>> "GS" <gesansom(a)netscape.net> skrev i meddelandet
>> news:htoutg$r7r$1(a)news.eternal-september.org...
>>> Thanks to all for replying! Unfortunately, after diligently trying each,
>>> none of the suggestions are working as expected. Here's what I'm trying
>>> to do:
>>>
>>> I have the following string of Hex values:
>>> "0E0E00000505000C20450164A5A5"
>>>
>>> which I need to convert to a delimited string of Dec values. The
>>> expected result is:
>>> "14,14,0,0,5,5,0,12,32,69,1,100,165,165"
>>>
>>> Since the source string of Hex values are paired, a delimited version of
>>> this would be:
>>> "0E,0E,00,00,05,05,00,0C,20,45,01,64,A5,A5"
>>>
>>> I was able to get the result using an Excel WorkSheetFunction provided
>>> by the Analyss Toolpak addin called Hex2Dec(). I would like to duplicate
>>> that function in VB6.
>>>
>>> Thanks in advance, again, for any suggested solutions.
>>>
>>> -- Garry
>>>
>>> Free usenet access at http://www.eternal-september.org
>>> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>>>
>>>
>>
>> That is not a string of Hex values, just a string of Hex digits.
>> For Hex values s = Chr$(14) & Chr$(14) & Chr$(0) & ....
>>
>> /Henning
>
> No, it's not a string of Hex values! It's a string of Dec values created
> by passing the original HexString (or Hex digits, as you say) to Excel's
> Analysis Toolpak Hex2Dec() function.
> For the record, Chr$(14) returns "", same as does Chr$(&H0E).
>
> The point of the exercise is to duplicate what Excel's Hex2Dec() does
> using VB[A]. What concerns me is the user claims to get different result
> for Chr$(&H0E), reporting that it returns "3045"!<???> I suspect he's
> using either a custom Hex2Dec() function, or a custom Chr() function, or
> both.
>
> regards,
>
> --
> Garry
>
> Free usenet access at http://www.eternal-september.org
> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>

*If* the string is always pairs of hex digits:

On a Form with 2 TextBoxes and a CommandButton

Option Explicit

Private Sub Command1_Click()
Dim i As Long
Dim s0 As String
Dim s1 As String
Dim s2() As String

s0 = "0E0E00000505000C20450164A5A5"
Text1.Text = ""
Text2.Text = ""

For i = 1 To Len(s0) Step 2
s1 = s1 & Val("&H" & Mid$(s0, i, 2)) & ","
Next
s1 = Left$(s1, Len(s1) - 1) 'to remove the extra ","
Text1.Text = s1
s2 = Split(s1, ",")

For i = 0 To UBound(s2)
Text2.Text = Text2.Text & Right$("0" & Hex$(Val(s2(i))), 2)
Next
End Sub

/Henning


From: GS on
Henning formulated on Saturday :
> "GS" <gesansom(a)netscape.net> skrev i meddelandet
> news:htpsbg$qk$1(a)news.eternal-september.org...
>> on 5/28/2010, Henning supposed :
>>> "Derek" <derekrss(a)yahoo.ca> skrev i meddelandet
>>> news:527036a6-1c91-40a9-8f89-673eb78cd857(a)q13g2000vbm.googlegroups.com...
>>> On May 28, 4:13 pm, GS <gesan...(a)netscape.net> wrote:
>>>> I'm thinking that I should retain the delimited values and dump it into
>>>> an array using Split(). This would, at least, preserve the individual
>>>> values return by the Hex2Dec function. Problem is, as you say, how to
>>>> determine what the original string was from the resulting string. For
>>>> example, returning Hex(14) returns "E" and not "0E".
>>>>
>>>> Any suggestions you have would be greatly appreciated.
>>>>
>>>
>>> Returning RIGHT$(HEX$(256 + 14), 2) would return "0E"
>>>
>>> Cheers
>>>
>>> Derek
>>>
>>> ----
>>> And so will Right$("0" & Hex$(14),2)
>>>
>>> /Henning
>>
>> True for this pair of hex digits. Not going to work for all pairs as does
>> using '256'. Results using "0" instead of '256':
>>
>> Original hexString: "0E0E00000505000C20450164A5A5"
>> Returns DecString: "14,14,0,0,5,5,0,12,32,69,1,100,165,165"
>> Restore DecString returns: "EE00550C2045164A5A5", which is not what we
>> want.
>>
>> regards,
>>
>> -- Garry
>>
>> Free usenet access at http://www.eternal-september.org
>> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>>
>>
>
> Yes it *is* the same thing.
>
> On a Form add a Commandbutton and a TextBox
>
> Option Explicit
>
>
>
> Private Sub Command1_Click()
> Dim i As Long
>
> Dim s1 As String
> Dim s2() As String
>
> s1 = "14,14,0,0,5,5,0,12,32,69,1,100,165,165"
> s2 = Split(s1, ",")
> Text1.Text = ""
>
> For i = 0 To UBound(s2)
> Text1.Text = Text1.Text & Right$("0" & Hex$(Val(s2(i))), 2)
> Next
> End Sub
>
> The ouput in Text1.Text is "0E0E00000505000C20450164A5A5"
>
> /Henning

Thanks for persisting! - What you post today is not what you posted
yesterday.

Today's post Works!
For i = LBound(v) To UBound(v)
Dec2Hex = Dec2Hex & Right$("0" & Hex$(Val(s2(i))), 2)
Next

Yesterday's did not work (as substituting "0" for '256' was implied)!
For i = LBound(v) To UBound(v)
Dec2Hex = Dec2Hex & Right(Hex("0" + CLng(v(i))), 2)
Next

Try what you posted yesterday in my code samples to see for yourself!
This works: Right(Hex(256 + CLng(v(i))), 2)
This does not: Right(Hex("0" + CLng(v(i))), 2)

I'm just working with Hex/Dec for the first time, and so I'm relying on
you folks for guidance. I feel I do a pretty thorough job of testing my
stuff before using it (most times, anyway). That process also includes
testing offerings from others in context to my usage needs. Up to now,
I've relied on Excel's Hex2Dec and Dec2Hex functions to do all the
'behind-the-scenes' stuff. Please know I appreciate your efforts AND
patience. It has made me a better VB6 programmer than I was before this
got started.<bg!> Props to all who have contributed...

regards,

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


From: GS on
> Hint:
> ASCII &H30 = "0" , ASCII &H45 = "E" in the ASCII table.
>
> /Henning

Thanks again! I now understand what my user is trying to do. Here's the
scenario:
1. User has automated equipment that uses NC code to operate.
2. Manufacturer of said equip. loads progs as per user needs.
3. My user wants to load their own progs.

How it works:
1. The equipment is operated from a control panel.
Input is via keys on the Control Panel.
Keystrokes are converted to HexDigits.
PostProcessor compiles user input to NC MachineCode.

2. The equipment executes the NC MachineCode.

So this is essentially a 2-stage process. The equip. can store NC progs
to be recalled as needed. What my user wants to do is program from a PC
and pass the string of HexDigits to the control panel via its RS232
port, thus eliminate having to stand in front of the control panel. An
additional benefit is having more storage capacity on their PC than
what's built into the equipment controller. They could then just
download whatever progs they need to use at runtime.

Thanks to your hint here, I now understand what my user was showing me
by the compiled output of the PostProcessor. I suspect the underlying
methodology of the operating scheme works similar to property=value
pairs. So you just informed me of how to create the expected NC
MachineCode. The sample I was provided for HexDigit 0E is the Ascii
value '3045'. That tells me the equipment is parsing in pairs, and so
is why it uses HexDigits for user input, and Ascii (machine code) for
runtime execution.

This means I can get busy with adding a feature that generates the
expected MachineCode so my user can verify this at the control panel as
a QC step.

Input is always appreciate...

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc