une


Is there a simple way to justify text in a messgae box Consdier the following text;

The number of lions = 23

The number of tigers = 2

The number of monkeys = 34

I would like the words and the equals signs to be left justified in the message box and I would like to right justify everything to the right of this. This would mean the numbers would all be right justified and line up properly as follows;

The number of lions = 23

The number of tigers = 2

The number of monkeys = 34

Is there a simple way to do this I am using VBA under MSWord 2002.




Re: Justifying text in message box

sjoo


Hello Une

VBA doesnot support to justify text. but you can make it with an API function, MemCopy()

MemCopy() copies an address to the another address.

I've just written some codes for you.

'// API declaration must be in the modules

Declare Sub MemCopy Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&)

Sub JustifyString()

Const MAXLEN = 30
Dim arrAnimal(2) As String
Dim arrNumber(2) As Long

Dim strAnimal As String
Dim bytAnimal(MAXLEN) As Byte
Dim i As Long, j As Long, lb As Long


arrAnimal(0) = "The number of lions ="
arrAnimal(1) = "The number of tigers ="
arrAnimal(2) = "The number of monkeys ="

arrNumber(0) = 23
arrNumber(1) = 2
arrNumber(2) = 150

For j = 0 To 2

strAnimal = arrAnimal(j)
lb = Len(strAnimal)

MemCopy bytAnimal(0), ByVal strAnimal, lb

For i = lb To UBound(bytAnimal)
bytAnimal(i) = 32
Next

strAnimal = String(UBound(bytAnimal) - LBound(bytAnimal) + 1, " ")
MemCopy ByVal strAnimal, bytAnimal(0), MAXLEN
strAnimal = strAnimal & Format(arrNumber(j), "@@@")

Debug.Print strAnimal
Next

End Sub






Re: Justifying text in message box

une

Thanks a lot. I was hoping for a simpler way, but I will examine your code and learn fom it.