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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hisham123
    New Member
    • Jul 2007
    • 15

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

    hi i had array whicle nearly 2 lakhs ascii character. Now i converting to character by following code

    for i= 1 to ubound(AsciiArr ay) '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
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Use Microsoft Script Control

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

    Check this code:

    [code=vb]
    Dim sSQL As String
    Dim NewStr As String
    '
    sSQL = Join(AsciiArray , ") & Chr(")
    sSQL = "Chr(" & sSQL
    sSQL = Left(sSQL, Len(sSQL) - 6)
    '
    mscr.AddCode _
    "Function MyFunction()" & vbCrLf & _
    " MyFunction = " & sSQL & vbCrLf _
    & _
    "End Function"
    NewStr = mscr.Eval("MyFu nction()")

    [/code]

    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

    Comment

    Working...