Home>
I have a question about the title.
I want to store the calculation result of the following code in variable a.
When "", I want to calculate as 0.
If the variable used for calculation (this time variable b) contains "" "etc., how can I calculate without error?
If b = "", what is the state of variable b?
Dim a
Dim b
Dim c
a = "100"
b = ""
IF b<>"" Then
a = a60
ELSE
a = ab60
END IF
Tried source 1
a = CInt (a)CInt (b)60
Tryed source 2
a = CInt (a)60
a = CInt (a)CInt (b)
Tried source 3
IF b<>"" Then
a = a60
ELSE
b = 0
a = ab60
END IF
I want to store
a = 40

Answer # 1

Answer # 2
Variables
a
andb
are assumed to be strings only consisting of numbers,
The quickest way is to add0
to the left of the "0" target variable whenCInt ()
.a = "100" b = "" a = CInt ("0"&a)CInt ("0"&b)60
Related articles
 python  about the average value calculation method of mass calculation
 calculation of the value corresponding to the vba min value
 vbscript  is there a way to get the return value by launching an application created in vbnet from vbsctipt?
 javascript  acquisition of select value, calculation in which select value and input value are mixed
 javascript score total value calculation and output method
 vbscript  i want to know why vbs txt file operation cannot be done with html
Trends
CInt will fail if the argument cannot be converted to int.
If
ab60
is written, type conversion is performed internally.At this time, "" cannot be converted to int, so an error occurs.
Also, I feel that I don't understand the condition specification of the If statement.
It becomes.
IsNumeric function can be used to determine if it is a number.
Therefore, I think that it would be good to calculate separately when it can be converted as a number and when it cannot be converted.
(This is not only when "", but when it cannot be recognized as a numerical value. If only "", change the condition of the If statement as such)