VBA/Excel/Access/Word/Data Type Functions/CSng
Версия от 16:33, 26 мая 2010; (обсуждение)
CSng() converts value to Single
Sub singValue()
Debug.Print CSng(25 * 5.5)
End Sub
To avoid the Type Mismatch error, use the built-in CSng function to convert the string stored in the value1 variable to a Single type number
Sub AddTwoNums2()
Dim myPrompt As String
Dim value1 As String
Dim mySum As Single
Const myTitle = "Enter data"
myPrompt = "Enter a number:"
value1 = InputBox(myPrompt, myTitle, 0)
mySum = CSng(value1) + 2
MsgBox mySum & "(" & value1 & "+2)"
End Sub