|
-
Dec 26th, 2011, 03:21 AM
#1
Thread Starter
Junior Member
Add Grick or latin symbol of alfabate to vb project
How to add Greek alphabet symbol to vb project?
-
Dec 26th, 2011, 09:09 AM
#2
Frenzied Member
Re: Add Grick or latin symbol of alfabate to vb project
use a suitable font and the gerenate a set of constants that bring up what you expect...
e.g. constPI constMU etc
where the constant is either the character or code of the letter as it appears in the font
so
... i'll just check a font in charactermap
Ψ character u+03a8 in tahoma font
so use chrw(&h3a8) to generate it
constPSI=chrw(&h3a8)
you can always make the name smaller
if you store the whole definition in a module you can import your greek module for use in what ever...
here to talk
-
Dec 26th, 2011, 10:55 AM
#3
Thread Starter
Junior Member
Re: Add Grick or latin symbol of alfabate to vb project
Thanks incidentals for the reply.
I tried but no success. Perhaps, I couldn't understand your meaning.
Here is what I did. Please let me know, where is the mistake?
Option Explicit
Private Sub Command1_Click()
Dim constPSI As String
constPSI = ChrW(&H3A8)
Font.Size = 12
Font.Bold = True
CurrentX = 2
CurrentY = 2
Print constPSI
End Sub
-
Dec 26th, 2011, 11:16 AM
#4
Frenzied Member
Re: Add Grick or latin symbol of alfabate to vb project
what font are you using?
what appeared when you printed?
when test printing in such cases I use sometninh before and after my print to test the actual thing i am printing
e.g print "[" & constPSI & "]"
to get [x] where x is the test character
when it works you do not
dim constPSI as string
you
CONST constPSI = chrw(&h3a8)
ina module so that the whole program can use it and noone can change it
Last edited by incidentals; Dec 26th, 2011 at 11:21 AM.
-
Dec 26th, 2011, 02:41 PM
#5
Thread Starter
Junior Member
Re: Add Grick or latin symbol of alfabate to vb project
I am using tahoma font for the Form1.
On running the bellow project (according to your suggestion) ...
Private Sub Command1_Click()
Font.Size = 12
Font.Bold = True
Const PSI = ChrW(&H3A8)
CurrentX = 2
CurrentY = 2
Print PSI, "(" & constPSI & ")"
End Sub
A Compile Error displayed: "Constant expression required"
-
Dec 26th, 2011, 03:43 PM
#6
Frenzied Member
Re: Add Grick or latin symbol of alfabate to vb project
oops...
try
const psi as string = chrW(&h3a8)
and use
print psi
print "[" & psi & "]"
not constPSI if you declared PSI
and let me know
-
Dec 26th, 2011, 05:11 PM
#7
Thread Starter
Junior Member
Re: Add Grick or latin symbol of alfabate to vb project
Code:
Private Sub Command1_Click()
Dim psi As String
psi = ChrW(&H3A8)
Print psi
Print "[" & "psi" & "]"
End Sub
It displays only:
?
"psi"
-
Dec 26th, 2011, 10:03 PM
#8
Re: Add Grick or latin symbol of alfabate to vb project
Vb6 printer object Is ANSI only and so are Vb6 controls with the exception of MSHFlexGrid.
While you might get away with setting a Font that supports Greek CharSet you really need Unicode for this.
One trick is to borrow the hDc handle for the ANSI printer object and use DrawTextW or TextOutW to print Unicode.
This is not a complete solution since it does not handle updating CurrentX/CurrentY and page breaks.
Sample code:
Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Const DT_TOP As Long = &H0& 'Justifies the text to the top of the rectangle.
Const DT_LEFT As Long = &H0& 'Aligns text to the left.
Const DT_CENTER As Long = &H1& 'Centers text horizontally in the rectangle.
Const DT_RIGHT As Long = &H2& 'Aligns text to the right.
Const DT_VCENTER As Long = &H4& 'Centers text vertically. This value is used only with the DT_SINGLELINE value.
Const DT_BOTTOM As Long = &H8& 'Justifies the text to the bottom of the rectangle. This value is used only with the DT_SINGLELINE value.
Const DT_WORDBREAK As Long = &H10& 'Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the lpRect parameter. A carriage return-line feed sequence also breaks the line. If this is not specified, output is on one line.
Const DT_SINGLELINE As Long = &H20& 'Displays text on a single line only. Carriage returns and line feeds do not break the line.
Const DT_EXPANDTABS As Long = &H40& 'Expands tab characters. The default number of characters per tab is eight. The DT_WORD_ELLIPSIS, DT_PATH_ELLIPSIS, and DT_END_ELLIPSIS values cannot be used with the DT_EXPANDTABS value.
Const DT_TABSTOP As Long = &H80& 'Sets tab stops. Bits 158 (high-order byte of the low-order word) of the uFormat parameter specify the number of characters for each tab. The default number of characters per tab is eight. The DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX values cannot be used with the DT_TABSTOP value.
Const DT_NOCLIP As Long = &H100& 'Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.
Const DT_EXTERNALLEADING As Long = &H200& 'Includes the font external leading in line height. Normally, external leading is not included in the height of a line of text.
Const DT_CALCRECT As Long = &H400& 'Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If the largest word is wider than the rectangle, the width is expanded. If the text is less than the width of the rectangle, the width is reduced. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.
Const DT_NOPREFIX As Long = &H800& 'Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off. For example, input string:"A&bc&&d", normal:"Abc&d", DT_NOPREFIX:"A&bc&&d". Compare with DT_HIDEPREFIX and DT_PREFIXONLY.
Const DT_INTERNAL As Long = &H1000& 'Uses the system font to calculate text metrics.
Const DT_EDITCONTROL As Long = &H2000& 'Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is calculated in the same manner as for an edit control, and the function does not display a partially visible last line.
Const DT_PATH_ELLIPSIS As Long = &H4000& 'For displayed text, replaces characters in the middle of the string with ellipses so that the result fits in the specified rectangle. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash. The string is not modified unless the DT_MODIFYSTRING flag is specified. Compare with DT_END_ELLIPSIS and DT_WORD_ELLIPSIS.
Const DT_END_ELLIPSIS As Long = &H8000& 'For displayed text, if the end of a string does not fit in the rectangle, it is truncated and ellipses are added. If a word that is not at the end of the string goes beyond the limits of the rectangle, it is truncated without ellipses. The string is not modified unless the DT_MODIFYSTRING flag is specified. Compare with DT_PATH_ELLIPSIS and DT_WORD_ELLIPSIS.
Const DT_MODIFYSTRING As Long = &H10000 'Modifies the specified string to match the displayed text. This value has no effect unless DT_END_ELLIPSIS or DT_PATH_ELLIPSIS is specified.
Const DT_RTLREADING As Long = &H20000 'Layout in right-to-left reading order for bi-directional text when the font selected into the hdc is a Hebrew or Arabic font. The default reading order for all text is left-to-right.
Const DT_WORD_ELLIPSIS As Long = &H40000 'Truncates any word that does not fit in the rectangle and adds ellipses. Compare with DT_END_ELLIPSIS and DT_PATH_ELLIPSIS.
Const DT_NOFULLWIDTHCHARBREAK As Long = &H80000 'Windows 98/Me, Windows 2000/XP: Prevents a line break at a DBCS (double-wide character string), so that the line breaking rule is equivalent to SBCS strings. For example, this can be used in Korean windows, for more readability of icon labels. This value has no effect unless DT_WORDBREAK is specified.
Const DT_HIDEPREFIX As Long = &H100000 'Windows 2000/XP: Ignores the ampersand (&) prefix character in the text. The letter that follows will not be underlined, but other mnemonic-prefix characters are still processed. For example, input string:"A&bc&&d", normal:"Abc&d", DT_HIDEPREFIX:"Abc&d". Compare with DT_NOPREFIX and DT_PREFIXONLY.
Const DT_PREFIXONLY As Long = &H200000 'Windows 2000/XP: Draws only an underline at the position of the character following the ampersand (&) prefix character. Does not draw any other characters in the string. For example, input string:"A&bc&&d", normal:"Abc&d",DT_PREFIXONLY:" _ ". Compare withDT_HIDEPREFIX andDT_NOPREFIX.
Private Declare Function DrawTextW Lib "user32" (ByVal hdc As Long, ByVal lpStr As Long, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Sub PrintUni(ByVal strUni As String)
Dim rct As RECT
Dim lPtr As Long
lPtr = StrPtr(strUni)
If lPtr Then
Printer.FontName = "Tahoma"
Printer.Orientation = vbPRORPortrait 'Portrait
Printer.PaperSize = vbPRPSA4 'A4
Printer.Print Chr$(0) 'for initializing - to get the hdc
DrawTextW Printer.hdc, lPtr, -1, rct, DT_CALCRECT 'Set rct
OffsetRect rct, 120, 120 'Emulate margins (8px * 15 Twips/Pixel)
DrawTextW Printer.hdc, lPtr, -1, rct, 0 'Print
Printer.EndDoc
End If
End Sub
Private Sub Form_Load()
Dim strUni As String
strUni = "GRK: " & ChrW$(&H39A) & ChrW$(&H3B1) & ChrW$(&H3BB) & ChrW$(&H3CE) & ChrW$(&H3C2) & " " & ChrW$(&H3AE) & ChrW$(&H3BB) & ChrW$(&H3B8) & ChrW$(&H3B1) & ChrW$(&H3C4) & ChrW$(&H3B5) & vbCrLf & _
"CHS: " & ChrW$(&H6B22) & ChrW$(&H8FCE) & vbCrLf & _
"JPN: " & ChrW$(&H3088) & ChrW$(&H3046) & ChrW$(&H3053) & ChrW$(&H305D) & vbCrLf & _
"KOR: " & ChrW$(&HC5EC) & ChrW$(&HBCF4) & ChrW$(&HC138) & ChrW$(&HC694)
Call PrintUni(strUni)
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|