Vb6 Printer Object Print Japanese - object

I want to use printer (windows driver) to print Japanese in a vb 6 project.
My project is in Japanese Windows Environment (the OS is English Originally, set Japan region and related language).
I use Printer object to print a simple string type of Japanese such as "レジースター", the code like
Dim s As String
s="レジースター"
Printer.Print s
Printer.EndDoc
but the output result is a set of messy code like "􀀀OEvƒOEƒ|􀀀[ƒg"
Does anybody who can succeeded in printing out Japanese with Vb6 Printer Object in Japanese language Windows Envrionment, please help me.
Finally find the key is simple, it's a little bit tricky but I still don't know why. Just set the font of the Printer Object like "Printer.Font.Charset = 128" (128 for Japanese)
ATTN: Pls pay attention to my case, my OS is English with the language and region setting to Japanese.
What make me confused is that the default ANSI of Windows. As we know, the default value of Printer.Font.Charset is 0, it means ANSI (IF the language environment is Japanese then it will use code page 932, if it is English, it will use Windows-1252).
My OS is Japanese (set to Japanese, not purely, Originally English OS), when I try to Write a file in Japanese it can display Japanese, but when I use the Printer Object to Print, it does have 0(ANSI) value of .Font.Charset, but actually it still use the original OS code page, so it is wired. And when I try to set the system to Chinese and Korean, both of the language is normal, only Japanese have this problem.

the trick that i have used for something like this is to use double StrConv() functions, one with the vbFromUnicode constant and the other with the vbToUnicode constant.
It takes alittle experimenting to get right , but it should look something like this, swap the constants and/or codepage values until you get the right conversion for your system
Dim s as string
s="レジースター"
Dim newS as string
newS = StrConv((StrConv(s,FromUnicode,CodePage1),ToUnicode,CodePage2)
Printer.Print newS
CodePage*N* is the Windows codepage value, 1252 for English, 932 for Japanese

Despite all strings in VB6 are Unicode (UTF-16), when it comes to interfacing with the world VB6 is completely non-Unicode.
You cannot store レジースター in your project file because the file is in ANSI.
You cannot simply pass a string to a declared API function because it will undergo an automatic conversion to ANSI first. To avoid this, you have to declare string parameters as pointers.
Apparently same happens to the Print call - the string gets converted to the currect ANSI codepage before it reaches the printer driver.
You can try printing manually by creating a device context and printing on it.
Or you can search for another solution, like this one (I did not try it).

Related

Issues with Å, Ä, and Ö (for other users) when coding in VBA

I have a problem coding in another language than English (when the input is in another language). For example, it is important to be able to write "LÅNG" and then use that input for my macros. However, when I have sent this to other computers, the "Å" get distorted and the macro does not work. Is there a way to fix this?
I guess I could write code that translate "Lång" to "Lang" etc., but even the code going is already distorted:/ What to do?
Edit: Code example (words have been edited):
MsgBox "Område saknas" 'free text-an error message prompting user action. This got completely distorted
Dim ColumnProjekt as String
ColumnProjekt = "Höst" . 'This changed when to something difference resulting in many, many errors in my other code.
Select Case Tidshorisont 'this is declared as a string and could contain "Lång"
Case "Lång"
Here is a great article about Unicode, explaining why the umlauts are changed on other computers:
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
Long story short - it is not a bug and there is no excuse to write code in German, naming variables in German (or in any other language but English). In the documentation, you may write in German (or in any other language).
If the idea is to write the MsgBox() in German, then the correct way to do it in Excel is something like this:
MsgBox tblSettings.Range("C5")
And in tblSettings.Range("C5") write the string. However, if it is opened in a computer, which does not support German as a regional system language (probably about 99% of the world PCs), then the following actions should be carried out by the user:
Clock And Region (search in start menu)
Region (link)
Administrative (tab)
Change system locale (button)
Current System Locale - Germany (drop down)
Or as a workaround - write "Laeng" and relax - it would work.

Reading txt file & opening with excel

Using Delphi 2007 & trying to read a txt file with greek characters & opening with Excel, I am not getting greek characters but symbols...Any help?
The text file is created with this code
CSVSTRList.SaveToFile('c:\test\xxx2.txt');
where CSVSTRList is a TStringList.
Looking at your code in your previous question it seems you are taking a stock TStringList and calling SaveToFile. That encodes the text as ANSI. Your Greek characters cannot be encoded as ANSI.
You want to export text using a Unicode encoding. For instance, in a modern Delphi you would use:
StringList.SaveToFile(FileName, Encoding.Unicode);
for UTF-16, or
StringList.SaveToFile(FileName, Encoding.UTF8);
for UTF-8.
I would expect that Excel will understand either of these encodings.
Since you are using a non-Unicode Delphi, things are somewhat more difficult. You'll need to change all you code, every single piece of string handling, to be Unicode aware. So you cannot use the stock string list any more, for example, because it contains 8 bit ANSI strings. The simplest way to do this with legacy Delphi is with the TNT Unicode library.
Or you could take the step of moving to a Unicode Delphi. If you care about international text it is the most sensible option.

Why pointer show unicode string reversed?

I have problems with unicode strings. My pointer to a string in farsi (saved as Unicode, codepage 1200) return the string reversed. Why? I know that farsi is a right-to-left language, but this is a C/C++ matter. My pointer to a string should point to the start of secuence as is stored in file.
I'm using VC++2005, standard console app.
Any help will be welcomed, I have attached screenshot and sample project.
test project
screen capture
Regards,
Juan
If the order is reversed in VC++2005, then probably it just does not handle directionality right, i.e. it displays Arabic letters left to right instead of properly obeying their inherent directionality. Such things happen in many editors and development tools. It does not as such affect the behavior of applications.

VB6 text appears as gibberish in one EXE but Hebrew in another

I have strange problem and minimal knowledge on VB6,
I got an EXE file that takes text (for button captions) from a text file.
This EXE which I don't has it code present all Hebrew text correctly.
I have build another EXE file (Identical to the previous) and all the functionally is working but it present all Hebrew as Gibberish!!
my text file encoding is Unicode.
Can you help me? Is there encoding for vb6 exe?
The default VB form/control fonts do not support all "foreign" characters.
If you set the font at runtime to "MS Shell Dlg" then Windows will translate this to the default UI font for that version of Windows which should handle most languages.
You'll also need to check the encoding of the file. If it's UTF-8 or a specific code page, then you'll need to use the MultibyteToWidechar() function to convert to UTF-16 for use in VB after reading it.
the perfect solution to resolve this issue is to change the font.Charset to 177 that represent HEBREW_CHARSET.
For example:
Text1.Font.Charset = 177
http://www.example-code.com/vb/vb6-display-unicode.asp

Does VS C++ Character Set compiler setting influence character encoding?

Are there any direct consequences of toggling between Unicode, MBCS, and Not Set for the VS C++ compiler settings Configuration Properties->General->Character Set, apart from the setting of the _UNICODE, _MBCS and _T macros (which then, of course, indirectly has consequences through the generic text mappings for string functions)?
I am not expecting it to, but since the documentation says "Tells the compiler to use the specified character set", I'd like to be certain that, specifically, it doesn't have any influence on how any literal non-ASCII text put into strings or wstrings is encoded? (I am aware that non ASCII literals in the source is not portable, but am maintaining a solution where this is used heavily.)
Thanks in advance.
No, it only affects the macro definitions. Which in turn can have wide-ranging effects on anything from <tchar.h> or the Windows T string pointer types (LPTSTR etc).
If you use any non-ASCII codes in your string literals then you depend heavily on the way the compiler decodes the text in your source code file. The default encoding it assumes is your system code page as configured in Control Panel + Regional and Language options. This will not work well when your source code file ever strays too far away from your machine. Specifying utf8 with a BOM is wise so this is never a problem. In the IDE that's set with Save As, arrow on the Save button, "Save with encoding", pick 65001. Support for utf8 encoded source code files is spotty in older versions of C++ compilers.
For unadorned strings, C++ follows C: it's ASCII. If you wrap them with anything, the game changes.
C++0x standardises Unicode strings. UTF in particular. This is a new feature.

Resources