Results 1 to 4 of 4

Thread: [RESOLVED] Is there a better way to do this

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] Is there a better way to do this

    Code:
       Dim n As Long
       
       Dim tempArray() As Byte
       ReDim tempArray(Len(StringData))
          
       For n = 1 To Len(StringData)
         tempArray(n - 1) = Asc(Mid(StringData, n, 1))
       Next n


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Is there a better way to do this

    If you want to convert string into byte array then there is a better way - just use StrConv() function:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim StringData As String
    Dim tempArray() As Byte
    Dim i As Integer
    
        StringData = "Hello World!"
        tempArray = StrConv(StringData, vbFromUnicode)
        
        'test
        For i = 0 To UBound(tempArray)
            Debug.Print Chr(tempArray(i))
        Next i
    
    End Sub

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Is there a better way to do this

    OK, thanks, RB, that's what I was looking for instead of the For loop.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4

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