如何做一个单行如果声明的VBScript古典ASP? [英] How to do a single line If statement in VBScript for Classic-ASP?

查看:109
本文介绍了如何做一个单行如果声明的VBScript古典ASP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在if语句单行,在C#和VB.NET作为存在于以下格式的许多其他编程和脚本语言

The "single line if statement" exists in C# and VB.NET as in many other programming and script languages in the following format

lunchLocation = (dayOfTheWeek == "Tuesday") ? "Fuddruckers" : "Food Court";

没有人知道,如果有,即使在VBScript和什么是extact语法?

does anyone know if there is even in VBScript and what's the extact syntax?

推荐答案

有条件的三元运算符不存在现成的,但它是pretty容易在VBScript中创建自己的版本:

The conditional ternary operator doesn't exist out of the box, but it's pretty easy to create your own version in VBScript:

Function IIf(bClause, sTrue, sFalse)
    If CBool(bClause) Then
        IIf = sTrue
    Else 
        IIf = sFalse
    End If
End Function

然后,您可以使用此功能,根据您的例子:

You can then use this, as per your example:

lunchLocation = IIf(dayOfTheWeek = "Tuesday", "Fuddruckers", "Food Court")

这比使用单行的优点如果 / 然后 / 否则是,它可以与其他字符串被直接连接起来。使用如果 / 然后 / 否则在同一行必须是在该行的嘛。

The advantage of this over using a single line If/Then/Else is that it can be directly concatenated with other strings. Using If/Then/Else on a single line must be the only thing on that line.

这篇关于如何做一个单行如果声明的VBScript古典ASP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆