MS Small Basic第七章: Fun with Shapes(玩形)(Part6: Clock, Desktop, and Dictionary Objects)

Lesson 2.5: Clock, Desktop, and Dictionary Objects

The Clock Object

Date, Weekday, and Time

You can get the current system date, day of the week, and time by using the Date property, the WeekDay property, and the Time property, respectively.

DrawBoundText(x, y, width, text) 在螢幕的特定位置繪製一條文本線

  • x = The x co-ordinate of the text start point
  • y = The y co-ordinate of the text start point
  • width = 最大允許寬度。該參數説明定義何時文本應當換行
  • text = 待繪製的文本

The Year Property

You can use the Year property of the Clock object to get the current system year. Let’s take an example that uses this property to calculate the user’s age.

Month and Day

You can use the Month and the Day property of the Clock object to get the current month and current day, respectively. How about writing a program that greets you on your birthday?

照著範例打, 並且輸入今天的日期(7月22日), 也確定電腦系統設定的時間是7月22日, 為什麼沒有祝我生日快樂?

Hour, Minute, and Second

You can get the current hour, minute, and second of the day by using the HourMinute, and Second properties of the Clock object. Let’s combine these properties to display a digital clock in the graphics window.

In this example, we used the HourMinute, and Second properties of the Clock object to display a digital clock. We defined the clock status as PM if the current system hour is greater than or equal to 12; otherwise, the clock status is AM. To make the digital clock run continuously, we have used the Goto statement to jump to up: after 1000 milliseconds.

The Desktop Object

You can set a desktop wallpaper of your choice by using the the SetWallPaper operation of the Desktop object.

You can also retrieve the size of your current desktop and use the information to specify the location of objects on the screen.

When you use the SetWallPaper operation, you can choose your wallpaper image from any local file, network file, or Internet URL. You can get the screen height and width of the primary desktop by using the Height and Width properties, respectively, of the Desktop object. Let’s apply these properties to the graphics window.

這個程式執行完會改掉原本的桌面, 所以要記得手動改回來.

The Height and Width properties of the Desktop object are very useful when you want to display a text or graphics window in the same position relative to the top and left side of the desktop at various resolutions. In this example, the graphics window is 400 pixels high and 500 pixels wide. To display this window in the center of the desktop, subtract the window’s height and width from the height and width of the primary desktop, and then divide the results by 2. (藍色這句話是關鍵)

The Dictionary Object

The Dictionary object is a useful resource that you can include as part of your Small Basic program. You can use this object to retrieve the meaning of a specified word from the online Dictionary service. The Dictionary object has two operation—GetDefinition and GetDefinitionInFrench

You must be connected to the Internet to use the Dictionary object in Small Basic.

You can obtain the meaning of an English word by using the GetDefinition operation. For a definition in French, use the GetDefinitionInFrench operation.

For example, let’s use the GetDefinition operation to find the meaning of “anacoluthon.”

DrawText(x, y, text) 在螢幕的特定位置繪製一條文本線

  • x : 文本開始點的 x 座標
  • y : 文本開始點的 y 座標
  • text : 繪製文本


  • (1)不知道如何斷行, 避免內容超出視窗邊界, 例如上圖內容的第四行
  • (2)不知道可不可以自行選擇線上字典, 例如Merriam-Webster?

About leeoxygen

本篇發表於 我的Small Basic學習記錄 並標籤為 , 。將永久鏈結加入書籤。


在下方填入你的資料或按右方圖示以社群網站登入: Logo

您的留言將使用 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )


您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s