Results 1 to 7 of 7

Thread: Memory Moving

  1. #1

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Memory Moving

    I need to put a byte array of ASCII character codes into a standard VB string.

    Any ideas?

    so . ..

    MyString = MyBytes()

    would be the assignment I would like to achieve. The above code doesn't work, of course!

    Cheers chaps

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    This any good?
    VB Code:
    1. Dim i As Long
    2. Dim MyBytes() As Byte
    3. Dim strString As String
    4.  
    5. For i = 0 To UBound(MyBytes)
    6.     strString = strString & MyBytes(i)
    7. Next i
    8.  
    9. MsgBox strString

  3. #3

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    The application I am trying to do is buffered screen displays. So for instance I have a console window of 78 x 50. This is displayed in a text box, so really I am trying to assign the byte array (2 dimensional) to the .Text property of the textbox.

    I currently do it the way you suggest, but to me it feels clumsy. I have tried CopyMemory (Aka RtlMoveMemory) but this doesn't appear to work.

    I really need more ideas . . .

  4. #4
    jim mcnamara
    Guest
    You cannot CopyMemory to the .Text property because it is actually the argument of a function, not a string array.

    Chrisjk gave you a good answer. Consider locking update on the control while you're moving stuff in there. Speeds things up a lot.

  5. #5
    New Member
    Join Date
    Mar 2001
    Location
    The Netherlands
    Posts
    7
    You can use this function to copy a byte array to a string.
    DataSize = Length of string

    Code:
    Public Function GetString(ByRef Data() As Byte, ByVal DataSize As Long) As String 
        GetString = Space$(DataSize)
        CopyMemory ByVal GetString, Data(0), DataSize
    End Function
    Hope this helps,
    Pieter

  6. #6

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    I've got it working on one dimensional bytes arrays - but not on two dimensions.

    I really want to use RtlMoveMemory, I just can't figure out how to coerce the damn array in.

    [When I said .Text, it was for clarity - I put it in a local string first]

  7. #7

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    I am now using the 'TextOut' API function. This allows direct mappings of strings to DC's

    Perfect.

    Cheers for your help

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