By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

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

P: 15
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
May 9 '08 #1
Share this Question
Share on Google+
1 Reply


QVeen72
Expert 100+
P: 1,445
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
May 9 '08 #2

Post your reply

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