Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Byte (size) problem

Status
Not open for further replies.

ridzz

Programmer
Sep 30, 2001
23
0
0
MY
Hi,
I have a problem with the variable type byte. At the moment, I have to use an existing Java class which recieves a byte array for its argument and will also return a byte array (byte[]).. But for testing, i hardcoded the Java method to return the array {89,65,80} (Basically making the word "YAP")

When i use StrConv on the returning argument, i cannot get back the word "YAP". Here's a snippet of my code.


dim from() as byte
dim result(0 to 2) as byte
dim m as string

'== The java object named crypt ==
Set test = GetObject("java:cryp")

'== Wrote the returning argument into a binary file ==
Open "f:\tempp.x" For Binary Access Write As #3
Put #3, 1, test.ByteIn(result(0))
Close #3

'== Read back binary file into from array ==
dum = FreeFile
Open "f:\tempp.x" For Binary Access Read As #dum
Get #dum, 1, from
Close #dum

'== converting back into readable string ==
m = StrConv(from, vbUnicode)
msgbox m


Is there something missing?
What i got back was sorta wierd text. Something like when you have the wrong encoding method with boxes and stuff.

Hope somebody can help me. Or at least tell me if it is possible to pass a byte array into a java class and get back a compatible byte array.
 
Is it possible you got back unicode text perhaps?
 
Yup.. i think i did..

After some debugging, it seems that what i got back was some control characters (e.g ETX, SOH, FF) along with the characters that i hard coded.. I think that is caused by me writing to the binary file before i converted it by using StrConv

I also found out that for each character 'Y', 'A', 'P' is represented in TWO bytes each in VB and Microsoft..

So i think, i need to do some processing before I can get back the original intended data..

But i have to ask.. is there another way to extract the data without any processing or at least minimize the processing?
 
erm.. nevermind..
I think i can manage with the processing part. Thanks anyway..
 
I think strconv can be called to convert from unicode to normal ascii text.

mmilan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top