Connecting Tech Pros Worldwide Help | Site Map

Convert ASCII to Character in VB6.0 (By Hisham)

Newbie
 
Join Date: Jul 2007
Posts: 15
#1: May 9 '08
hi i had array whicle nearly 2 lakhs ascii character. Now i converting to character by following code

for i= 1 to ubound(AsciiArray) 'ubound size=2,00,000
str= str + Asc(AsciiArray(i))
next i

but it takes more than 10 minutes so i want to code which minimize this the time. could anyone help me.

with regards

Hisham
QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#2: May 9 '08

re: Convert ASCII to Character in VB6.0 (By Hisham)


Hi,

Use Microsoft Script Control

Add Microsoft Script Control to your form and name it as mscr.

Check this code:

Expand|Select|Wrap|Line Numbers
  1. Dim sSQL As String
  2. Dim NewStr As String
  3. '
  4. sSQL = Join(AsciiArray, ") & Chr(")
  5. sSQL = "Chr(" & sSQL
  6. sSQL = Left(sSQL, Len(sSQL) - 6)
  7. '
  8. mscr.AddCode _
  9.     "Function MyFunction()" & vbCrLf & _
  10.     "    MyFunction = " & sSQL & vbCrLf _
  11.     & _
  12.     "End Function"
  13. NewStr = mscr.Eval("MyFunction()")
  14.  
  15.  
This works very fast..
Logic here is :
Join all the Ascii Numbers with Chr( ) and Concatenate
and Evaluate the End result with the Script Control.
This worked fine here for 1000 records...
For 2lakh records , if you are getting error, Split the Array into smaller arrays of say 10000 items. find the result of each and Concatenate the end result...
Also Note : AsciiArray should be declared as Datatype =String..(or else JOIN function will err)


Regards
Veena
Reply