Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2003, 11:42 AM
Authorized User
 
Join Date: Jul 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help required to handle unicode characters

Hi ,

I need a help in handling double byte characters( Japanese, Chinese kanji characters) and writing into an Ascii file.
My requirement is to write data into the file in fixed positions., Eg. col 1-40 will have one value, 41-72 will have another value and so on. The column positions are fixed for each value. If the value doesn't occupy the entire column width, then it has to be filled with blank spaces. For eg., if the col1 value is "Hello" then the remaining 35 positions will be filled with blank spaces.

Now suppose I write a Chinese/japanese character, then every character being a double byte character, it is supposed to occupy 2 positions. Suppose a string has 5 double bytes, then it is supposed to occupy 10 column positions in ascii file. Now because the col1 width is 40 , now I'm supposed to add only 30 blank spaces, otherwise it'll spill over into the next column.

( If the file opened with a proper code page , then it will show the actual characters, but if it is opened with a English code page, then you'll actually see these characters occupying 10 positions but all of them appear as junk.)

So in my VB code, I'm currently doing this:
First convert string into byte array,
Loop over byte array, and check if the character is a double byte or not.

(Because VB stores all characters as unicode, byte array would occupy the double the size of a string.
So if the character is a double byte, then both b(0) and b(1) to have value greater than 0.
If the character is a Ascii, then b(0) will have value greater than 0, but b(1) will be 0.
I checked the AscW value for these characters, some are greater than 255 and some have negative values also.)

b = myStr

 For i = 0 To UBound(b) Step 2

  If b(i + 1) <> 0 Then 'Implies double byte character
    NoOfDoubleByte = NoOfDoubleByte + 1
  End If

Next

then based on the no. of double bytes, reconstruct the string with appropriate no. of spaces.
Suppose the string is supposed to occupy positions 1-40, then decrement the No of double bytes in the string and add that many spaces.

mystr = mystr & space$(40-(len(mystr + NoOfDoubleByte ))

Then finally write this into an ascii file.

Open FileName For Append As #intFile
Print #intFile, myStr

Now the problem.
The logic appeared to work fine so far. But suddenly I find that there are some Japanese characters, though being double byte is appeared to occupy only one position,. ( When opened in note pad with a English code page , a few charaters have occupied 2 positions , but a few of them have occupied only one position.)
so this entire logic of building string has gone haywire. Can some one direct me to the correct way of handling this.

Any help is highly appreciated.

Regards

Rajesh



 
Old July 11th, 2003, 12:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do you do the conversion? This is what I do, and it works fine.
Marco

    Dim ss As String * 25 ' any length you need
    ss = "anything"
    Dim xx() As Byte
    xx = StrConv(ss, vbFromUnicode)
    Open myFile For Binary Access Write As fileno
    Put fileno, , xx
    Close fileno
 
Old July 12th, 2003, 01:56 AM
Authorized User
 
Join Date: Jul 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried this , but didn't work.
Moment I convert using strconv function, all the characters are lost, and byte array displayed only question marks.

 
Old July 14th, 2003, 12:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If the starting strings is a wide characters string you could hardly get
anything else than question marks from a converted byte array...
Are your regional settings set to the correct language? StrConv uses
the LCID for the conversion.
Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to display unicode characters in datagridview usmanshakeel ASP.NET 1.x and 2.0 Application Design 0 October 19th, 2007 02:27 AM
Does MYSQL server supports Unicode characters POLITE Java Databases 0 December 25th, 2006 01:39 AM
Unicode Characters Lazy ADO.NET 6 November 7th, 2006 04:57 AM
Help required to handle unicode in VB rajeshnerenki VB How-To 0 July 11th, 2003 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.