2013-02-11 19 views

Odpowiedz

11

Od a jest Integer, nie może zawierać String lub być Empty. Użyj Variant a następnie sprawdzić, co zostało zwrócone:

Dim a As Variant 
Dim b As Integer 

a = InputBox("Enter the number", "Program", "", 7000, 6000) 

If Not IsNumeric(a) Then 
    'a is not a number 
Else 
    'a is a number and can be converted to Integer 
    b = CInt(a) 
End If 
4

Masz a zdefiniowane jako Integer. Integer nie może być pusty. Użyj Variant zamiast Integer:

Dim a As Variant 
a = InputBox("Enter the number", "Program", "", 7000, 6000) 
If a = Empty Then 
    ' do code... 
Else 
    MsgBox "Enter the number." 
End If 
+1

+1 do pierwszej poprawnej odpowiedzi - chociaż chcą 'Jeśli IsEmpty (a) Then' – brettdj

+0

mój +1 do Brett) –

+0

@brettdj Dlaczego nie możesz opublikować własną odpowiedź? :) –