简体   繁体   English

vbscript循环,如果然后发出

[英]Vbscript loop, if then issue

I need some assistance. 我需要一些帮助。 I am new to vbscript and I have a problem/question. 我是vbscript的新手,但有一个问题。

I am trying to give an end user the ability to start a program over. 我试图使最终用户能够重新启动程序。 I have done research on MSDN and googled various other sites that involve tutorials based on if then statements, subroutines, functions and do,while,until loops 我已经在MSDN上进行了研究,并在Google的其他各个站点上进行了搜索,这些站点都基于if then语句,子例程,函数以及do,while,until循环进行了教程

all the loop tutorials or explanations have a program looping through numbers and string lengths. 所有循环教程或解释中都有一个程序循环遍历数字和字符串长度。 I have developed a common stock transaction program: 我开发了一个普通股票交易程序:

'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 & "."

After this program concludes, I would to give the end user an option to evaluate another stock price..etc. 该计划结束后,我将为最终用户提供一个评估其他股票价格的选择。

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

My logic assumes that you would now proceed with an if statement of some kind that basically says: that if tryAgain equals "y" then proceed back to the top, if "n" then exit program with a thank you conclusion, if invalid character then state that the end user entered an invalid response, allowing them the oppurtunity to try again. 我的逻辑假设您现在将继续执行某种基本的if语句:如果tryAgain等于“ y”,则返回顶部,如果“ n”,则退出程序并给出一个谢谢的结论,如果无效字符,则指出最终用户输入的响应无效,这使他们有机会再次尝试。

I couldn't figure it out. 我不知道。 functions and subroutines need arguments (i assume) and subroutines do not give data output. 函数和子例程需要参数(我假设),并且子例程不提供数据输出。 functions do but this code doesnt classify. 函数可以,但是此代码未分类。 I was hoping that their was a syntax that would allow the program to start over. 我希望它们的语法可以使程序重新开始。 I think a loop of some kind is probably the answer but i dont have the knowledge or the experience. 我认为某种循环可能是答案,但我没有知识或经验。

Is their anyone that can assist me??? 他们的任何人都可以帮助我吗???

Thanks 谢谢

This could be one of the simplest solutions. 这可能是最简单的解决方案之一。

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM