Solved

Convert  String <--> Byte Array ?

Posted on 1998-10-07
4
219 Views
Last Modified: 2013-11-13
How do you convert a Byte Array to a String ?
( Without moving big chunks of data )
I have :
Dim anArray(4096) As Byte
Dim StringData As String

I use the Win API
ReadFile(h, anArray(0),BytesToRead, BytesRead, 0) to read the data. I then want to transmit the data with the WinSock
control:

   StringData <-- anArray  ????????????????

   tcpServer.SendData StringData
 
Your help would be appreciated.
Peet
     
0
Comment
Question by:peet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Expert Comment

by:swilt
ID: 1438578
First of all Dim anArray(4096) As Byte declares a 4097 byte array starting at 0
A byte in VB is like a small integer rather than a char
There may be a way of doing this, but it would be using the Win API
4097 bytes is a small chunk of data

    Dim anArray(4) As Byte ' 5 byte array (0 to 4)
    Dim StringData As String
    Dim i As Integer

    anArray(0) = Asc("H")
    anArray(1) = Asc("e")
    anArray(2) = Asc("l")
    anArray(3) = Asc("l")
    anArray(4) = Asc("o")
   
    'StringData = CStr(anArray()) 'This will not work
   
    For i = LBound(anArray) To UBound(anArray)
        StringData = StringData & Chr$(anArray(i))
    Next i
   
    MsgBox StringData

0
 

Accepted Solution

by:
karmi earned 150 total points
ID: 1438579
The following line  will convert the type of the array to string

StringData = StrConv(anArray, vbUnicode)
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1438580
MyString = ""
FOR ndx = 0 to 4095
    MyString = MyString & CHR( anArray( ndx ) )
NEXT ndx


0
 

Author Comment

by:peet
ID: 1438581
karmi,

Thanks a lot for the help

peet
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question