472,119 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Problem converting byte() to string and then back to byte() in VB SCRIPT

3
Hi ,
I have tried all the methods available to convert byte () to string and vice versa in VBSCRIPT.

Expand|Select|Wrap|Line Numbers
  1. Function ByteArray2Text(varByteArray)
  2. Dim rs
  3. Const adLongVarChar = 201
  4. Set rs = CreateObject("ADODB.Recordset") 
  5. rs.Fields.Append "temp", adLongVarChar, LenB(varByteArray)
  6. rs.Open
  7. rs.AddNew
  8. rs("temp").AppendChunk varByteArray
  9. rs.Update    ByteArray2Text = rs("temp")
  10. rs.Close
  11. Set rs = Nothing
  12. End Function
  13.  
  14.  
  15. Function ByteArray2Text(varByteArray)
  16. Dim byt
  17. Const adTypeText = 2
  18. Const adTypeBinary = 1
  19. Set byt = CreateObject("ADODB.Stream")
  20. byt.Type = adTypeBinary
  21. byt.Open 
  22. byt.Write varByteArray
  23. byt.Position = 0
  24. byt.Type = adTypeText
  25. byt.CharSet = "us-ascii" 
  26. ByteArray2Text = byt.ReadText 
  27. byt.Close    Set byt = Nothing
  28. End Function
  29.  
  30.  
  31. Function ByteArray2Text(varByteArray)   
  32.  'Convert byte array into a string with VBScript   
  33.  '60kb = 2 seconds, 100kb = 5 seconds, 200kb = 25 seconds    
  34. Dim strBuffer, lngCounter    
  35. strData = ""   
  36.  strBuffer = ""    
  37. For lngCounter = 0 to UBound(varByteArray) 
  38.        strBuffer = strBuffer & Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1)))
  39.         'Keep strBuffer at 1k bytes maximum
  40.         If lngCounter Mod 1000 = 0 Then
  41.             strData = strData & strBuffer
  42.             strBuffer = ""
  43.         End If
  44.     Next    ByteArray2Text = strData & strBuffer
  45. End Function
these are some of the methods i tried..
In all these methods i get microsoft V B script runtime error - Object doesnt support this type or method. some body please help me out
Mar 2 '07 #1
4 3660
willakawill
1,646 1GB
Hi. Would it be possible to say what it is your are trying to achieve with this conversion?
Mar 4 '07 #2
arunfr
3
i would like to get some help to convert byte array to string and vice versa..
Mar 6 '07 #3
willakawill
1,646 1GB
i would like to get some help to convert byte array to string and vice versa..
Thanks, I understand that part. What I wanted to know was why you are performing this conversion.
Mar 6 '07 #4
arunfr
3
Thanks, I understand that part. What I wanted to know was why you are performing this conversion.
i have to convert the string to bytearray n compare it with the bytearray in the binary file..similarly i have to convert the byte array in the binary file to string and perform comparison with the original string value of that byte array. i m able to read from binary file n the only problem i face is i m not able to perform this conversion.

For eg:
string : The Scripts - I must convert this to byte array n if try to convert this byte array back to string i must get the original string . ie (The Scripts) similarly for byte array...
Mar 7 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Hal Vaughan | last post: by
5 posts views Thread by c duden | last post: by
7 posts views Thread by john | last post: by
3 posts views Thread by Joshua Russell | last post: by
21 posts views Thread by Mike | last post: by
4 posts views Thread by Petr Jakes | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.