Public Function convertcm(amcm As String, value As DataRow) As Decimal
Dim cmovrnd As Decimal
If amcm.Contains(" ") = False AndAlso amcm.Contains("/") Then
Dim slam() As String = amcm.split("/")
Dim ihcam As Decimal = CSng(slam(0))
Dim ihdam As Decimal = CSng(slam(1))
Dim ihaam As Decimal = ihcam / ihdam
cmovrnd = Format(Eval(ihaam * 2.54,value),"###0.###")
Else
Dim sam() As String = amcm.split(" ")
Dim iham As Decimal = CDec(sam(0))
If sam.Length = 1 Then
cmovrnd = Format(Eval(iham * 2.54,value),"###0.###")
Else
Dim slam() As String = sam(1).split("/")
Dim ihcam As Decimal = CSng(slam(0))
Dim ihdam As Decimal = CSng(slam(1))
Dim ihaam As Decimal = ihcam / ihdam
cmovrnd = Format(Eval((iham + ihaam) * 2.54,value),"###0.###")
End If
End If
return cmovrnd
end function
调用
dim cmovrnd = convertcm(“123”, Tables("表A").current.DataRow)
msgbox(cmovrnd)