0

To check the Text Width, how to set the scale mode?

Is it -

    Debug.Print .ScaleMode = 1

Or

    Me.ScaleMode = 1

Which one does it work?

I test it with below code

Private Sub Command1_Click()
Dim xStr As String
    xStr = "W"
    With frmLabel
        .Font.Name = "Arial"
        .Font.Size = 10
        'Debug.Print .ScaleMode = 1

        '0 to 7
        Me.ScaleMode = 7
        Debug.Print .TextWidth(xStr) ' TextWidth = 435
        .Font.Size = 14
        Debug.Print .TextWidth(xStr) ' TextWidth = 645
    End With
End Sub

How could I define the kind of measure or unit? I'm looking for inch.

Thank you.

soclose
  • 2,773
  • 12
  • 51
  • 60

2 Answers2

3

In the context of a Form, UserControl, or UserDocument "Me" is already part of the namespace, so just use something like:

ScaleMode = vbInches

You can use redundant overqualification if you wish, as in:

Me.ScaleMode = vbInches

Since you can't write code inside of a PictureBox (and thus there is no local "Me" anyway) you are writing in the context of its container, so to set the property of a picScrollbox you'd write:

picScrollbox.ScaleMode = vbInches

The same is true for a Printer object.

But please avoid magic numbers and make use the intrinsic Enum ScaleModeConstants that provides symbolic names easier for the next guy to read.

Bob77
  • 13,167
  • 1
  • 29
  • 37
0
Me.Font.Name = "Arial"
Me.Font.Size = 10
Me.ScaleMode = vbInch ' 5

TextWidth returns the width if the text were output using Print with the current Font of the Form. You aren't setting the Font of the Form in the code in your question. Set Me.Font. http://msdn.microsoft.com/en-us/library/aa267168(v=vs.60).aspx

The value is returned in units as determined by ScaleMode property of the form. The possible values of ScaleMode are in the docs http://msdn.microsoft.com/en-us/library/aa445668(v=vs.60).aspx

Another time why not try context-sensitive help? In the VB6 IDE code view put the cursor in ScaleMode and press F1 to go straight to the ScaleMode topic in the docs.

MarkJ
  • 30,070
  • 5
  • 68
  • 111