reserved words n.
Skip this Video
Loading SlideShow in 5 Seconds..
Reserved Words PowerPoint Presentation
Download Presentation
Reserved Words

Reserved Words

136 Vues Download Presentation
Télécharger la présentation

Reserved Words

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Reserved Words There are words in VB that have been reserved for special meanings. In general, if you use one of these words to (name) an object in your own programs, their special meaning is lost and your use takes over. That can be an inconvenience or that can be a calamity depending on the word used and what is desired. Special Words & Functions

  2. Loss of Features “Date” is a word that is used in VB to return the number of days that have passed since January 1, 1900 (there will be more on this later). If you (name) a variable, or a command “Date” then it will not be possible to include any feature that uses the current date in that program. Special Words & Functions

  3. Real Calamity “Sub” is used in VB in the processing of a subroutine or event. (The word is automatically added to the beginning of the code block of every event in the program.) If you (name) any variable or command “Sub” the program will fail to even compile. The diagnostic may not even point to the problem. Special Words & Functions

  4. So What? Do not (name) objects with what seem to be very common names. When in doubt, deliberately misspell the name. Best of all use the Microsoft convention of naming things with the 3 character prefix that “types” the object. Most important, when you observe that there is a diagnostic that makes no sense, look for a problem with reserved words and names. Special Words & Functions

  5. System words: Sub, End, Procedure, Dim, Single, Long, Visible, Else, ... Reserved words: Date, Time, Beep, Sin, Rnd, Randomize, ... Reserved Words Special Words & Functions

  6. Date “Date” is a built-in function that returns the number (this must be a long integer) of days that have passed since December 31, 1899. Thus January 1, 1900 is day number 1 in this system and December 31, 1999 is day number 36525. This is called “The Julian Date” and takes into account leap years and the Y2K problems. Special Words & Functions

  7. Date In this system Label1.Caption = Date will insert today’s date as a label caption. Dim dteY as date dteY = 365. * 100 + 100 / 4 + 1 Label1.Caption = dteY will insert 1/1/2000 into the label. (why did I put a decimal point after the 365?) Special Words & Functions

  8. Time “Time” is a built-in function that returns the fraction of a day that has passed since midnight. Thus at noon time returns a value of 0.50000000 and one minute later time returns a value of 0.5006944 [.0006944 = 1/(24*60)] Special Words & Functions

  9. Time If you wish to time some event, measure the time at the beginning of the event, then measure the time at the end of an event. The difference is the fraction of a day that has passed between these two measurements. This can be converted to more conventional units. Special Words & Functions

  10. Time Option Explicit Dim sglX As Single Private Sub cmdStart_Click() sglX = Time End Sub Private Sub cmdStop_Click() Label1.Caption = Format((Time - sglX) _ * 24 * 60 * 60, "0.00") End Sub (there is an error here, what is it?) Special Words & Functions

  11. Rnd The Rnd function returns a value between 0 and 1 that appears to be a random number. It is not. It follows a complicated formula that obeys many of the rules of random numbers. The exact same sequence is generated each time unless the Randomize function is called first. Special Words & Functions

  12. Rnd Private Sub Form_Load() randomize End Sub Private Sub RollThem_Click() Label1.Caption = Int(rnd * 6 + 1) Label2.Caption = Int(rnd * 6 + 1) End Sub (why did we add 1?} Special Words & Functions