2015-06-24 2 views
0

У меня есть макрос VBA, который выбирает выбор типа данных пользователя для других вычислений.VBA «Ошибка компиляции: аргумент не является обязательным»

Sub Function1() 
' Give the user macro options based on how fast or slow the computer is using advanced conditional compliling 
MsgBox ("This macro by default treats all numbers as decimals for maximum precision. If you are running this macro on an old computer, you may want to relare numbers as singles, to speed up the macro.") 
MsgBox ("Decimals are reccomended for any scientific conclusions.") 
MsgBox ("Decimal: reccomended for maximum precision. Also slower." & vbNewLine & "Double: not reccomended." & vbNewLine & "Single: not reccomended. A lightweight double." & vbNewLine & "Long: rounds to nearest number. Massive range of possible values." & vbNewLine & "Integer: designed for quick estimates of data.") 
vuserChoice = InputBox("Select a data type:" & vbNewLine & "1. Decimal" & vbNewLine & "2. Long" & vbNewLine & "3. Single" & vbNewLine & "5. Integer") 

Select Case IsNumeric(vuserChoice) 
    Case IsNumeric = True 
     MsgBox ("A number cannot be entered for data type.") 
    Case IsNumeric = False 
     struserChoice = CStr(vuserChoice) 

If struserChoice = "Decimal" Or "decimal" Or "1" Or "one" Or "on" Or "Dec" Or "dec" Then 
    Call FunctionDecimal 
ElseIf struserChoice = "Double" Or "double" Or "2" Or "two" Or "to" Then 
    FunctionDouble 
ElseIf struserChoice = "Single" Or "single" Or "3" Or "three" Or "three" Or "thee" Then 
    FunctionSingle 
ElseIf struserChoice = "Long" Or "long" Or "4" Or "four" Or "for" Or "foor" Then 
    FunctionLong 
ElseIf struserChoice = "Integer" Or "integer" Or "int" Then 
    FunctionInteger 
Else 
    FunctionNotValidVarType 
End If 
' MEeff = measure of efflux due to crudely purified HDL in scintillation 
MsgBox "For additional information about this macro:" & vbNewLine & "1. Go to tab Developer" & vbNewLine & "2. Select Visual Basic or Macro." & vbNewLine & "See the comments or MsgBoxes (message boxes)." 
End Sub 

Вот виновный строка кода:

Case IsNumeric = True 

Что мне нужно сделать, чтобы исправить это? Я знаю, что IsNumeric - это встроенная функция VBA.

+1

Is * what * numeric? –

+0

В любом случае - зачем использовать оператор case (в отличие от if-then-else) при выборе двух возможностей? –

+0

@JohnColeman это код. –

ответ

4

Метки должны быть значениями, а не именами функций. Попробуйте

Case True 
+0

Спасибо, это исправляет! –

Смежные вопросы