Results 1 to 7 of 7

Thread: Octal String

  1. #1
    RStout
    Guest

    Octal String

    I have a database entry the is in a octal string. So it takes a text string and converts it into a hex.

    Can someone post a code snipit to convert "test this 123" to hex and back?

    Thanks

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Private Sub Command1_Click()
     x = "test this 123"
     MsgBox "test this " & Hex(Right(x, 3))
     MsgBox "test this " & CDbl(&H7B)      'hex uses &H before number
                                          'oct uses &0
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    RStout
    Guest

    Well...

    I need to encode and decode the text string part too.

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Well, it's beyond me....then again a lot of things are.

    Hex Function:
    Returns a String representing the hexadecimal value of a number.
    Oct Fucntion:
    Returns a Variant (String) representing the octal value of a number.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    RStout
    Guest

    Well...

    I need to encode and decode the text string part too.

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Well
    thanks for the lesson in hex....
    Code:
    Private Sub Command1_Click()
    Dim x As String, i As Integer, y As String
      x = "test this 123"
      For i = 1 To Len(x)
        y = y & Hex(Asc(Mid(x, i, 1)))
      Next i
        MsgBox y
          MsgBox UnHex(y)
    
    End Sub
     
    Public Function UnHex(sR As String) As String
        Dim sTemp As String
        Dim i As Integer, iKey As Integer
        
        On Error Resume Next                              'Trap for error
                              
         On Error GoTo 0                                   'Turn off error trapping
        For i = 1 To Len(sR) Step 2                      'Loop through each char in the given string
          sTemp = sTemp & Chr$(Val("&H" & Mid$(sR, i, 2) & "&"))
        
        Next i
        UnHex = Trim$(sTemp)    'Return the string
    End Function
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7
    RStout
    Guest

    Smile Thanks

    That's what I needed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width