On Mar 6, 2006, at 2:58 PM, Eric Richards wrote:

Hello -

I came across some code for visual basic that I wanted to try to port to Rb for my personal use, however there are a few lines that go beyond my knowledge
of what they do and why also how to make it work in Rb.

Here are the lines. Could some help me with this ?


Text2.Text = (Mid(Text1.Text, 1, 4) - &H69) Xor &H69 // HUH??? Rb doesn't like this. I get the mid( ) but not the rest

Text2.Text = Chr(BitwireXor((Asc(Mid(Text.Text, 1, 4)) - &h69), &h69))

You need the Chr() and Asc() as RB doesn't automatically typecast single-character strings to integers, or vice versa. You can also replace "Mid(Text1.Text, 1, 4)" with "Left(Text1.Text, 4)" in this case. And, as Asc() only looks at the leftmost character in a string, you can do "Left(Text1.Text, 1)" instead. However, if the string's encoding is not UTF-8, you'll probably want to use AscB(), LeftB(), and ChrB() instead. Either that, or convert the string's encoding back to UTF-8. IIRC, &h69 = "i". Also, the code is probably assuming something about the character set by using '-'. To be sure, you should probably use a bitwise AND against a mask of &h69 instead; if the string in Text1.Text happened to contain a character whose ASCII value < 105 (&h69 = 105 decimal), you'll get a negative value with the subtraction. Oopsie!

and

Text2.Text = Format(Hex(Text2.Text), "00") // Rb doesn't like this either.

Just do

Dim temp As String

temp = Hex(Val(Text2.Text))
While Len(temp) < 2
  temp = "0" + temp
Wend
Text2.Text = temp

Thanks

Eric

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


William H Squires Jr
4400 Horizon Hill #4006
San Antonio, TX 78229
[EMAIL PROTECTED] <- remove the .nospam

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to