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]
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]