VBA 语法错误如果字符串变量等于“a”或“b”或“c”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18858891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Syntax Error If string variable equals "a" or "b" or "c"
提问by Richard Pullman
I'm trying to write code that does the following in VBA but i get error: Type mismatch
我正在尝试编写在 VBA 中执行以下操作的代码,但出现错误:类型不匹配
Quark is a string variable
Quark 是一个字符串变量
If quark = "F" Or "DE" Or "ED" Then
采纳答案by Elias
Each "OR" is its own boolean statement.
每个“OR”都是它自己的布尔语句。
If quark = "F" Or quark ="DE" Or quark ="ED" Then
You could acheive what you are trying to do with a case though I think
虽然我认为你可以通过一个案例实现你想要做的事情
Select Case quark
Case "F","DE","ED"
stuffHere
end select
EDIT: I see that you were getting a type mismatch, did you dim quark as a string?
编辑:我看到您遇到了类型不匹配问题,您是否将夸克调暗为字符串?
dim quark as string
回答by Rahul Tripathi
You may try like to compare like this:-
您可以尝试像这样比较:-
If quark = "F" Or quark = "DE" Or quark = "ED" Then
instead of:-
代替:-
If quark = "F" Or "DE" Or "ED" Then
回答by basher
You need to compare quark to the strings.
您需要将夸克与弦进行比较。
If quark = "F" Or quark = "DE" Or quark = "ED" Then