我需要在visual basic中编写一个简单的计数器。我正在做一个“多少舔到一个tootsie流行计数器的中心”。将打开一个对话框,询问他们是否已到达中心。如果回答否,它将循环并再次询问。
如果回答是,它将结束程序并计算有多少循环。任何人都可以帮我这个吗?
非常感谢
如果有帮助,我有java代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Counter
{
public static void main(String[] args) throws IOException
{
int counter = 0;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Are you are the center? ");
String answer = input.readLine();
while(answer.equals("no")) {
System.out.print("Are you are the center? ");
counter++;
answer = input.readLine();
}
System.out.println("It took " + ++counter + " licks.");
}
}
答案 0 :(得分:2)
虽然Jon Lin问你要问的是什么,但我很想回复这篇文章。我也是新用户,这是第一个容易让我回答的问题。所以我希望我不会在这里越过界限,但这是我的回答,这对我有用:
Sub HowManyClicks()
Dim numberOfClicks As Integer
Dim title As String
Dim question As String
Dim answer As VbMsgBoxResult
title = "How many (c)licks"
question = "Are you at the center?"
answer = vbNo
Do
answer = MsgBox(question, vbQuestion + vbYesNo, title)
numberOfClicks = numberOfClicks + 1
Loop While answer = vbNo
MsgBox "it took" & Str(numberOfClicks) & " (c)licks", , title
End Sub