Subscribe to our RSS Feeds

【Small Basic】练手小程序1之数的开方

0 Comments »
这是一个命令行程序。代码如下:TextWindow.Write("请输入一个数字:")
org = TextWindow.ReadNumber()
ClearLine()
TextWindow.Write("数字 ")
TextWindow.Write(org)
TextWindow.WriteLine(":")
number = 1
p = 0
TextWindow.Write("  ")
TextWindow.Write(org)
TextWindow.Write("^")
TextWindow.Write(p)
TextWindow.Write("=")
TextWindow.WriteLine(number)
number = number * org
p = p + 1
While (1=1)
  TextWindow.Write("  ")
  TextWindow.Write(org)
  TextWindow.Write("^")
  TextWindow.Write(p)
  TextWindow.Write("=")
  TextWindow.WriteLine(number)
  number = number * org
  p = p + 1
  PauseAndClearMessage()
EndWhile

Sub ChinesePause
  TextWindow.WriteLine("请按任意键继续. . .")
  TextWindow.PauseWithoutMessage()
EndSub

Sub PauseAndClearMessage
  ChinesePause()
  ClearLine()
EndSub

Sub ClearLine
  TextWindow.CursorTop = TextWindow.CursorTop - 1
  TextWindow.CursorLeft=0
  x = TextWindow.CursorTop
  TextWindow.WriteLine("                                                                                                        ")
  TextWindow.CursorTop=x
  TextWindow.CursorLeft=0
EndSub
特点是每次只显示一个,按下任意键才显示接下来的。

用到了一个Sub ClearLine,意思是清除光标上一行。其实这句如果用.NET写的话更简单。

程序作者:蓝蓝小雪
11/16/2008 09:22:00 上午

0 Responses to "【Small Basic】练手小程序1之数的开方"

发表评论

With Blue Snow Studio, Nothing is impossible.