Mega Code Archive

 
Categories / VisualBasic Script / Data Type Functions
 

To avoid the Type Mismatch error, use the built-in CSng function to convert the string stored in the value1 variable t

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