Vbscript 如何将Select语句与选项数组一起使用

Vbscript 如何将Select语句与选项数组一起使用,vbscript,Vbscript,我想远程/可重用地存储Case语句multi-value ExpressionList 我唯一的想法是,是否有办法将远程列表馈送到案例数组中 这是正常的: Select Case(LCase(strProduce)) Case "apple", "pear", "banana" 'Do Frutie stuff Case "corn", "care-rot", "radish" 'Do Vegitapole stuff (get the spell

我想远程/可重用地存储Case语句multi-value ExpressionList

我唯一的想法是,是否有办法将远程列表馈送到案例数组中

这是正常的:

Select Case(LCase(strProduce))
    Case "apple", "pear", "banana"
        'Do Frutie stuff
    Case "corn", "care-rot", "radish"
        'Do Vegitapole stuff (get the spelling reference?)
End Case
但是这些案例列表被大量使用,我想把它们移到一个中心位置。所以我想要更像的东西,而不必在数百个地方重做代码

aryFruit = Array("apple", "pear", "banana", "grape")
aryVegetable = Array("corn", "carrot", "radish")

Select Case(LCase(strProduce))
    Case In aryFruit
        'Do Fruit stuff
    Case In aryVegetable
        'Do Vegitapole stuff (get the spelling reference?)
End Case

如果案例只是很多单件案例,那么它只会处理变量,但我需要它是一个列表,因为数量可能会发生变化,如上面的“通缉”示例[grape]所示。我试图保留现有的Case语句,而不是转换为大量的if,对于循环,Case不止两个。

您可以创建一个字典,将项目映射到它们各自的类型

Set produce = CreateObject("Scripting.Dictionary")
produce.CompareMode = vbTextCompare

produce("apple")  = "fruit"
produce("pear")   = "fruit"
produce("banana") = "fruit"
produce("grape")  = "fruit"
produce("corn")   = "vegetable"
produce("carrot") = "vegetable"
produce("radish") = "vegetable"
然后进行简单的查找:

Select Case produce(strProduce)
    Case "fruit"
        'Do fruit stuff
    Case "vegetable"
        'Do vegetable stuff
End Case

您可以创建一个字典,将项目映射到它们各自的类型

Set produce = CreateObject("Scripting.Dictionary")
produce.CompareMode = vbTextCompare

produce("apple")  = "fruit"
produce("pear")   = "fruit"
produce("banana") = "fruit"
produce("grape")  = "fruit"
produce("corn")   = "vegetable"
produce("carrot") = "vegetable"
produce("radish") = "vegetable"
然后进行简单的查找:

Select Case produce(strProduce)
    Case "fruit"
        'Do fruit stuff
    Case "vegetable"
        'Do vegetable stuff
End Case

您可以通过将值作为二维数组从数据库中提取,但这取决于体系结构,您是否使用数据库,这是服务器端脚本还是客户端脚本?存储数组或DD不是问题,因为我已经包含了。这是客户端请不要移动目标。您可以通过将值作为二维数组从数据库中提取,但这取决于体系结构,您是否使用数据库,这是服务器端脚本还是客户端脚本?存储数组或DD不是问题,因为我已经包含了。这是客户端,请不要移动目标。我喜欢它,它并不完美,它需要不同的组。西红柿既是一种水果又是一种普通蔬菜,这会打破这种局面。我喜欢它,但它并不完美,因为它需要区分不同的群体。西红柿既是一种水果又是一种普通蔬菜,这就打破了这一局面