E
E
Eugene2018-10-01 18:54:06
VBScript
Eugene, 2018-10-01 18:54:06

How to cast type "string" to number in VBS?

Hello! I understand VBS. I'm looking into the user interaction functions MsgBox() and InputBox(). I wrote a simple script that should calculate the sum of the numbers entered by the user:

Option Explicit
Dim a,b,Result
a = InputBox("Введите первое число","Сумма чисел")
b = InputBox("Введите второе число","Сумма чисел")
Result = a+b
MsgBox Result

The script does not return the sum of numbers, but the sum of strings, although the "+" operator must convert strings to numbers. What am I doing wrong? How to make VBS count numbers? How to convert strings entered by the user into numbers? Is it a separate function?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-10-01
@webinar

although the "+" operator should convert strings to numbers

who should? It concatenates two strings and does the right thing
Too early you began to ask such questions. First you need to master the search
give two numbers and put a plus between them. If you give strings - the number will fail, but you already know it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question