VBA/Excel/Access/Word/Data Type Functions/CSng

Материал из VB Эксперт
Перейти к: навигация, поиск

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