Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 27th, 2005, 11:47 AM   #1
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
unicode

Hey

I need to find the width/height for japenese text so I was wondering how can I make my text boxes work for unicode characters. I searched a found something about "Microsoft Forms 2.0 Library" or something, I looked in my components and it was not there so any other way I can get it to work, or does someone know where I can get a hold of this dll.

thanks
cloud- is offline   Reply With Quote
Old Aug 28th, 2005, 10:09 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Quote:
Originally Posted by cloud-
Hey

I need to find the width/height for japenese text so I was wondering how can I make my text boxes work for unicode characters. I searched a found something about "Microsoft Forms 2.0 Library" or something, I looked in my components and it was not there so any other way I can get it to work, or does someone know where I can get a hold of this dll.

thanks
VB is designed to work with Unicode transparently, and also has inbuilt functions for dealing with the Eastern IME as well in the vba namespace. Standard windows controls (textboxes, labels etc) should accept/display properly so long as the OS is set up to do so (language packs installed, extended fonts, etc) as it uses the MS Unicode abstraction layer. This also means that resource files localise correctl y on a MUI English or localised system.

Obviously the VB data types do so as well, the only areas to be careful are when marshalling to COM or converting a string to a byte array, in which case you'd need to handle the encoding manually.

As for getting the size of characters, so long as you have the Japanese UI components and fonts installed, your system display encoding is set to Unicode, and you have set the Font property of the object you're printing too (e.g. a PictureBox) to an extended font like MS Mincho, the TextHeight("something japanese") and TextWidth methods should return the size of the japanese string or character.
Rory is offline   Reply With Quote
Old Aug 29th, 2005, 7:41 AM   #3
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
thanks ill try
cloud- is offline   Reply With Quote
Old Sep 17th, 2005, 2:01 PM   #4
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
Hi, I can't seem to get it to work just by opening the text with unicode in and adding it to a textbox. Here is the code i tried :/
Private Sub Label2_Click()
On Error GoTo EndSub
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Script Files (*.ssa, *.ass)|*.ssa;*.ass"
CommonDialog1.ShowOpen
OpenScript CommonDialog1.FileName
EndSub:
End Sub
Function OpenScript(FileName As String)
Dim fso, ts, s
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(FileName, ForReading, TristateTrue)
s = ts.ReadAll
Text1.Text = s
ts.Close
End Function
Private Sub Label5_Click()
If (Label5.Caption = "Unicode > SJIS") Then
Label5.Caption = "SJIS > Unicode"
DisableItems
Else
Label5.Caption = "Unicode > SJIS"
EnableItems
End If
End Sub
Function DisableItems()
Check1.Enabled = False
Check2.Enabled = False
End Function
Function EnableItems()
Check1.Enabled = True
Check2.Enabled = True
End Function

in the script..is just some japenese text...
Dialogue: 1,0:04:04.09,0:04:14.46,*Default,,0000,0000,0000,,空は飛べないけど翼ならあるのさ
Dialogue: 1,0:04:20.42,0:04:24.94,*Default,,0000,0000,0000,,慰めながら不謹慎だけど

and the output i get is:
ÿþ
which is nothing similar lol
anyone know how i can at least make it open the unicode txt.
thanks alot
cloud- is offline   Reply With Quote
Old Sep 21st, 2005, 4:50 PM   #5
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Try copying and pasting your japanese string into a resource file with the langID set to unicode so you can load a unicode string into memory, and check it displays on the form correctly. If you get a load of squares or question marks, it means your font doesn't support unicode characters.

Judging by your code, I'd say your file containing unicode text isn't being read as unicode but as ASCII/ANSI. Try setting the encoding to unicode somewhere, or alternatively use the native VB binary I/O and run StrConv(Something(), vbUnicode) on the resultant byte array to decode it to a string as unicode.
Rory is offline   Reply With Quote
Old Oct 23rd, 2005, 11:06 AM   #6
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
thankyou very much rory!!!!!!!! ^_^
i got it working by reading in binany.
now i have another question...XD
i have 2 kinds of strings in my program a japanese one and an english one.
the 2 will never be in 1. The program i am making returns the size of charecters i have that working now but for the japanese strings if a unsupported font is chosen i would like to change to the default font for that encoding.
so basically is there anyway to find the default font for its codepage 128 i think. or just the default unicode font. unless u already know what that font would be (im not sure if it varies).
thanks alot again ^^
cloud- is offline   Reply With Quote
Old Oct 23rd, 2005, 2:03 PM   #7
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Hmm, I believe that the core windows fonts (MS Sans Serif, Arial, MS Mincho, Times New Roman etc) should all support any language, as the MUI language packs simply extend them. You can get fonts that'll definitely work with a particular language by going into a web browser and seeing which ones it defaults to for particular encodings (e.g. firefox uses Latha for pages in Tamil languages.)
Rory is offline   Reply With Quote
Old Oct 23rd, 2005, 4:59 PM   #8
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
ok now that makes me think that what im doing is wrong lol.
i didnt add the binary to a byte array, or convert to unicode, i just did a string variable and added to the textbox, but it outputted to a textfile perfect (i could see the japanese..unicode..worked) but wont display in the textbox(not really important)..or picturebox(for the widths important..else ill get wrong values)..
heres some of the code:
Private Sub Label2_Click()
On Error GoTo EndSub
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Script Files (*.ssa, *.ass)|*.ssa;*.ass"
CommonDialog1.ShowOpen
OpenScript CommonDialog1.FileName
EndSub:
End Sub
Function OpenScript(FileName As String)
Dim i As String
Dim i2 As String
Text1.text = ""
List1.Clear
i2 = FreeFile
Open FileName For Binary As #i2
Do Until (EOF(i2))
Line Input #i2, i
If (Len(Text1.text) = "0") Then
Text1.text = i
Else
Text1.text = Text1.text & vbCrLf & i
End If
If (Left(i, 6) = "Style:") Then
' not important :p
End If
Loop
Close #1
End Function

I had the font set as arial, i guess that shoulda worked but didnt
any ideas? does the byte vars/converting functions make any differences?

side note: does anyone know about indenting in vb6? my code always looks scruffy..all to the left >D

thanks a lot ^_^
cloud- is offline   Reply With Quote
Old Oct 24th, 2005, 1:59 PM   #9
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
I'd give it a go reading it into a byte array and then doing the conversion nevertheless, to ensure its unicode. Also in If (Len(Text1.text) = "0") Then the quotes are unecessary and actually slow your loop down (double conversion to string and back).
Rory is offline   Reply With Quote
Old Oct 24th, 2005, 3:58 PM   #10
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
Quote:
Originally Posted by Rory
I'd give it a go reading it into a byte array and then doing the conversion nevertheless, to ensure its unicode. Also in If (Len(Text1.text) = "0") Then the quotes are unecessary and actually slow your loop down (double conversion to string and back).
I see, thanks didnt know that (about the quotes).
i tried the bite and converting but i can a type mismatch with the line input, how else can i get the text file line to the byte string or fix this.
Function OpenScript(FileName As String)
Dim i As Byte
Dim i2 As String
Text1.text = ""
List1.Clear
i2 = FreeFile
Open FileName For Binary As #i2
Do Until (EOF(i2))
Line Input #i2, i
If (Len(Text1.text) = 0) Then
Text1.text = StrConv(i, vbUnicode)
Else
Text1.text = Text1.text & vbCrLf & StrConv(i, vbUnicode)
End If
If (Left(i, 6) = "Style:") Then
' ...
End If
Loop
Close #1
End Function
thanks
cloud- is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC