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?
Tried source 1
Dim a Dim b Dim c a = "100" b = "" IF b<>"" Then a = a-60 ELSE a = a-b-60 END IF
Tryed source 2
a = CInt (a)-CInt (b)-60
Tried source 3
a = CInt (a)-60 a = CInt (a)-CInt (b)
I want to store
IF b<>"" Then a = a-60 ELSE b = 0 a = a-b-60 END IF
a = 40
Answer # 1
CInt will fail if the argument cannot be converted to int.
a-b-60is 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.
If b<>"" Then If 'b is not "" Else When 'b is "" End If
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)
'Determines whether it can be converted to a numeric value using the IsNumeric function If can be converted as a number? Then 'If it can be converted as a number a = CInt (a)-CInt (b)-60 Else 'If it cannot be converted as a number a = CInt (a)-60 End If If you want to change 'b permanently, you may use the following method. If can't be converted as a number? Then 'If it cannot be converted as a number b = "0" End If a = CInt (a)-CInt (b)-60
Answer # 2
bare assumed to be strings only consisting of numbers,
The quickest way is to add
0to the left of the "0" target variable when
a = "100" b = "" a = CInt ("0"&a)-CInt ("0"&b)-60
- 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?
- vbscript - i want to know why vbs txt file operation cannot be done with html