Field Codes Macrobuttons

F

frogman

I have a word document with field codes and what I want to do is when
the user types the feet in the first field that the second field
automaticly displays the metric equivelant.


I found the code to convert to metric but I need help with the field
codes.

Public Const InchToMeter As Double = 0.0254
Public Const FootToMeter As Double = 0.3048
Public Const DecimalSign As String = "."
Public Const FootInd As String = "'"
Public Const InchInd As String = """"


Enum SrcType
Imperial = 1
Metric = 2
End Enum


Public Sub Convert()
Dim strConvert As String


strConvert = ConvertSys("7'29", 1)
'strConvert = ConvertSys("26.5", 2)


MsgBox "the converted number is " & strConvert
End Sub


Public Function ConvertSys(ByVal InputVal As String, ByVal SourceType
As SrcType) As String


Dim lFoot As Long
Dim lInch As Long
Dim dMeter As Double
Dim dFoot As Double
Dim dInch As Double
Dim dTemp As Double
Dim sResult As String
Dim arrTemp As Variant


Select Case SourceType
Case 1
arrTemp = Split(InputVal, FootInd)
lFoot = CLng(arrTemp(0))
If UBound(arrTemp) = 0 Then
lInch = 0
Else
lInch = CLng(Val(arrTemp(1)))
End If
dMeter = (lFoot * FootToMeter) + (lInch * InchToMeter)
sResult = CStr(Format(dMeter, "standard")) & " meters"
Case 2
dTemp = (CDec(InputVal) / FootToMeter)
arrTemp = Split(dTemp, DecimalSign)
lFoot = CLng(arrTemp(0))
dInch = Round((dTemp - lFoot) * 12)
sResult = CStr(lFoot & "' " & dInch & Chr(34))
End Select
ConvertSys = sResult
End Function


looks:
___ ft [___ m]


field codes:
the Q is red color
{MACROBUTTON NoMacro {Quote "___" \*CharFormat}} ft [{MACROBUTTON
NoMacro {Quote "___" \*CharFormat}} m]
 
W

Word Heretic

G'day "frogman" <[email protected]>,

if you use a formfield and protect the section for forms, you can then
link your macros to the onexit routine, and read the value to operate
from using the bookmark of the field.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


frogman reckoned:
 
C

Charles Kenyon

For that matter, if you mark the field to calculate on exit, you can use a
calculation field (not even a formfield) to display the results. No need for
any macros.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

Word Heretic said:
G'day "frogman" <[email protected]>,

if you use a formfield and protect the section for forms, you can then
link your macros to the onexit routine, and read the value to operate
from using the bookmark of the field.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


frogman reckoned:
I have a word document with field codes and what I want to do is when
the user types the feet in the first field that the second field
automaticly displays the metric equivelant.


I found the code to convert to metric but I need help with the field
codes.

Public Const InchToMeter As Double = 0.0254
Public Const FootToMeter As Double = 0.3048
Public Const DecimalSign As String = "."
Public Const FootInd As String = "'"
Public Const InchInd As String = """"


Enum SrcType
Imperial = 1
Metric = 2
End Enum


Public Sub Convert()
Dim strConvert As String


strConvert = ConvertSys("7'29", 1)
'strConvert = ConvertSys("26.5", 2)


MsgBox "the converted number is " & strConvert
End Sub


Public Function ConvertSys(ByVal InputVal As String, ByVal SourceType
As SrcType) As String


Dim lFoot As Long
Dim lInch As Long
Dim dMeter As Double
Dim dFoot As Double
Dim dInch As Double
Dim dTemp As Double
Dim sResult As String
Dim arrTemp As Variant


Select Case SourceType
Case 1
arrTemp = Split(InputVal, FootInd)
lFoot = CLng(arrTemp(0))
If UBound(arrTemp) = 0 Then
lInch = 0
Else
lInch = CLng(Val(arrTemp(1)))
End If
dMeter = (lFoot * FootToMeter) + (lInch * InchToMeter)
sResult = CStr(Format(dMeter, "standard")) & " meters"
Case 2
dTemp = (CDec(InputVal) / FootToMeter)
arrTemp = Split(dTemp, DecimalSign)
lFoot = CLng(arrTemp(0))
dInch = Round((dTemp - lFoot) * 12)
sResult = CStr(lFoot & "' " & dInch & Chr(34))
End Select
ConvertSys = sResult
End Function


looks:
___ ft [___ m]


field codes:
the Q is red color
{MACROBUTTON NoMacro {Quote "___" \*CharFormat}} ft [{MACROBUTTON
NoMacro {Quote "___" \*CharFormat}} m]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top