How do I display ascii character omega in a picture box with regular letters?

I'm relatively new to visual basic and wrote a program to calculate ohms law. Displaying units for volts and amps is easy of course, but what of displaying something like picture1.print answer & "k" & "ohms", replacing ohms with the omega symbol. I can change the picture box font to symbols, then char(87) equals the omega symbol, but then everything else is junk. How do I insert the omega symbol and not change anything else and get a proper display?
xetronAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

List244Commented:
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As Size) As Long

Private Type Size
  Width As Long
  Height As Long
End Type

Private Sub Command1_Click()
Dim CharSize As Size
Picture1.Print answer & "k"
GetTextExtentPoint32 Picture1.hdc, answer & "k", 4, CharSize
Picture1.Font = "symbol"
Picture1.CurrentX = CharSize.Width * Screen.TwipsPerPixelX
Picture1.CurrentY = 0
Picture1.Print Chr(87)
picture1.font = "Times New Roman" ''' Or whichever starting font was...
End Sub

This will write the first part, change the font, then write the OMEGA after
the first part. Hope that helps.
0
dbrckoviCommented:
Try this:
This function will raplace all "Ohm" in your text with actual Omega signs.
Just use PrintOhms function in the place where you originaly used Picture1.Print
'------------------------------------------
Private Sub Command1_Click()
    PrintOhms "Result of calculation was 13 kOhm, but measured value was 12.5 kOhm."
End Sub

Sub PrintOhms(Text As String)
    Text = Replace(Text, "Ohm", Chr(87), 1, -1, vbTextCompare)

    OldY = Picture1.CurrentY
    OldFont = Picture1.Font

    For Char = 1 To Len(Text)
        Character = Mid(Text, Char, 1)
        If Asc(Character) = 87 Then
            Picture1.Font = "Symbol"
        Else
            Picture1.Font = OldFont
        End If
        Picture1.Print Character
        Picture1.CurrentY = OldY
        Picture1.CurrentX = Picture1.TextWidth(Left(Text, Char))
    Next Char

    Picture1.Font = OldFont
End Sub
'-----------------------------------------------
0
Erick37Commented:
Here is another alternative using a unicode characterset and the TextOutW API call:

Option Explicit

Private Declare Function TextOutW Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long

Private Sub Command1_Click()

    Dim sOMEGA As String
    Dim sOut As String
   
    sOMEGA = ChrW$(&H3A9) 'This is the unicode omega value
   
    'Use Verdana cause it has the Omega symbol
    Picture1.FontName = "Verdana"
    Picture1.FontSize = 14
   
    Picture1.Cls
   
    'Here is a sample string
    sOut = "The answer is 330 " & "k" & sOMEGA
   
    'Print the unicode text, remember that x and y are in pixels
    Call TextOutW(Picture1.hdc, 0, 20, StrConv(sOut, vbUnicode), Len(sOut))

End Sub
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Erick37Commented:
Note:
It seems that most fonts have the Ohm sign at ChrW(&H2126) so you are not limited to only Verdana.  You can use almost any unicode truetype font and get the ohm sign using TextOutW.
0
xetronAuthor Commented:
Thanks for all your help. I think List244 is on the right track. Here is a chunk of the code I'm trying to improve. z = 0, k = 1000, m = 1000000, ohm1 is single.

If (z < ohm1) And (ohm1 < 1) Then
    Picture1.Print Round((ohm1 * k), 2) & " m" & "ohms"
    ElseIf (z < ohm1) And (ohm1 < k) Then
    Picture1.Print Round((ohm1), 2) & " ohms"
    ElseIf (k <= ohm1) And (ohm1 <= 999999) Then
    Picture1.Print Round((ohm1 / k), 2) & " k" & "ohms"
    ElseIf (m <= ohm1) Then
    Picture1.Print Round((ohm1 / m), 2) & " M" & "ohms"
  End If

I hope this helps.
Thanks again,
Viktor
0
dbrckoviCommented:
try this:

  If (z < ohm1) And (ohm1 < 1) Then
        PrintOhms Round((ohm1 * k), 2) & " m" & "ohm"
        ElseIf (z < ohm1) And (ohm1 < k) Then
        PrintOhms Round((ohm1), 2) & " ohms"
        ElseIf (k <= ohm1) And (ohm1 <= 999999) Then
        PrintOhms Round((ohm1 / k), 2) & " k" & "ohm"
        ElseIf (m <= ohm1) Then
        PrintOhms Round((ohm1 / m), 2) & " M" & "ohm"
  End If

'add this function
Sub PrintOhms(Text As String)
    Text = Replace(Text, "Ohm", Chr(87), 1, -1, vbTextCompare)

    OldY = Picture1.CurrentY
    OldFont = Picture1.Font

    For Char = 1 To Len(Text)
        Character = Mid(Text, Char, 1)
        If Asc(Character) = 87 Then
            Picture1.Font = "Symbol"
        Else
            Picture1.Font = OldFont
        End If
        Picture1.Print Character
        Picture1.CurrentY = OldY
        Picture1.CurrentX = Picture1.TextWidth(Left(Text, Char))
    Next Char

    Picture1.Font = OldFont
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
List244Commented:
Your new function:
If (z < ohm1) And (ohm1 < 1) Then
    PrintToPicture Picture1, Round((ohm1 * k), 2) & " m"
    ElseIf (z < ohm1) And (ohm1 < k) Then
   PrintToPicture Picture1, Round((ohm1), 2)
    ElseIf (k <= ohm1) And (ohm1 <= 999999) Then
   PrintToPicture Picture1, Round((ohm1 / k), 2) & " k"
    ElseIf (m <= ohm1) Then
   PrintToPicture Picture1, Round((ohm1 / m), 2) & " M"
  End If

Declarations:
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As Size) As Long

Private Type Size
  Width As Long
  Height As Long
End Type

Private Function PrintToPicture(PBox As PictureBox, PrintText As String) 'Print function/autowrite omega
Dim CharSize As Size, PFont As String, CurrY As Long
CurrY = PBox.CurrentY
PFont = PBox.Font
PBox.Print PrintText
GetTextExtentPoint32 PBox.hdc, PrintText, Len(PrintText), CharSize
PBox.Font = "symbol"
PBox.CurrentX = CharSize.Width * Screen.TwipsPerPixelX
PBox.CurrentY = CurrY
PBox.Print Chr(87)
PBox.Font = PFont
End Function

There, that should make it easy on you. Now whenever you need to write the
omega you simply do:

PrintToPicture Pictureboxname,"TEXT TO PRINT"

The rest is done for you.
0
List244Commented:
dbrckovi and myself have both provided for the user what he/she has asked. I recommend
splitting points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.