Vbscript循环,如果那么问题

时间:2015-10-04 19:54:44

标签: vbscript

我需要一些帮助。我是vbscript的新手,我有一个问题/问题。

我试图让最终用户能够启动程序。 我已经在MSDN上进行了研究,并搜索了各种其他涉及教程的网站,这些网站基于if语句,子例程,函数和do,同时,直到循环

所有循环教程或解释都有一个循环数字和字符串长度的程序。我开发了一个普通股票交易程序:

'Stock Transaction Program

Option Explicit
Dim stockPrice, commission, stocksBought, stockCommission, stockTotal, totalCost, tryAgain


Wscript.StdOut.Write "Stock price: "
stockPrice = CDbl(Wscript.StdIn.ReadLine)
Wscript.StdOut.Write "Number of stocks bought: "
stocksBought = CDbl(Wscript.StdIn.ReadLine)
Wscript.StdOut.Write "Stock Commission percentage in whole number (i.e 2 for 2%): "
commission = CDbl(Wscript.StdIn.ReadLine)

stockTotal = stockPrice * stocksBought
stockCommission = commission * stockTotal / 100
totalCost = stockCommission + stockTotal

Wscript.StdOut.WriteLine "You payed a total commission of $" & stockCommission & " on the stocks you bought."
Wscript.StdOut.WriteLine "Your total price for you purchasing " & stocksBought & " stocks is $" & totalCost & "."

在此计划结束后,我会给最终用户一个评估另一个股票价格的选项..等等。

Wscript.Stdout.Writeline "Would you evaluate another stock price? (i.e y or n): "
tryAgain = lcase(wscript.stdin.readline)

我的逻辑假设您现在要进行某种基本上说的if语句:如果tryAgain等于" y"然后回到顶部,如果" n"然后退出程序,谢谢你的结论,如果无效的字符然后说明最终用户输入了无效的响应,允许他们的机会再次尝试。

我无法弄明白。函数和子程序需要参数(我假设),子程序不提供数据输出。函数但是这段代码没有分类。我希望他们的语法可以让程序重新开始。我认为某种循环可能是答案,但我没有知识或经验。

他们的任何人都可以帮助我吗?

谢谢

1 个答案:

答案 0 :(得分:0)

这可能是最简单的解决方案之一。

Option Explicit
Dim stockPrice, .... , tryAgain

Do
    '....
    ' your stocks code
    '....

    Wscript.Stdout.Writeline "Would you evaluate another stock price? (i.e y or n): "
    tryAgain = lcase(wscript.stdin.readline)

Loop While tryAgain="y"