« Home « Chủ đề lập trình VBScript

Chủ đề : lập trình VBScript


Có 40+ tài liệu thuộc chủ đề "lập trình VBScript"

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 20

tailieu.vn

space(46) &. space(20) &. space(31) &. space(26) &. space(34) &. space(22) &. space(37) &. space(17) &. space(10) &. If intPlayGame = 6 Then ‘User elected to play the game. strAnswerOne = InputBox(“What was the Science Officer’s name in the “ &. “original Star Trek series. “spock” Then intNumberCorrect = intNumberCorrect + 1 End If. Else ‘User doesn’t want to play....

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 21

tailieu.vn

Do…While. The Do...While statement creates a loop that runs as long as a specified condition is true.. VBScript supports two different versions of the Do...While loop. The syntax for the first ver- sion of the Do...While loop is as follows:. In this example, the expression ( intCounter <. 10 ) allows the loop to continue as long as the value...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 22

tailieu.vn

After testing to see whether the script works as expected, retest it to see whether you can break it. Once you’re satisfied with the operation of the script, keep reading. One is by opening the Windows Command Console and typing in the name of an execution host, followed by the path and filename of your scripts at the Windows Command...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 23

tailieu.vn

“\\GuessANumber.lnk”). objNewShortcut.TargetPath = “C:\ GuessANumber.vbs”. What makes working with the Quick Launch toolbar different than working with other Windows special folders is that you must specify the location of the Quick Launch toolbar within the special folder ( AppData ) that contains it.. Figure 6.17 shows how the Quick Launch toolbar appears once the shortcut of your VBScript game has...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 24

tailieu.vn

As I deliberately avoided using procedures in the script from Chapter 6, I had to use other techniques for organizing the script’s programming logic. What I chose to do was put every- thing in the script’s main processing section as follows:. Added statements that generate a random number. Added a Do...Until loop that controls the game’s execution. Embedded an If...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 25

tailieu.vn

Space(15) &. “Rules and “ &. “Instructions” &. Space(32) &. Space(31) &. Try to get to “ &. “21 without going over.” &. Aces count as “ &. The dealer “ &. “must stop at 17 or later.” &. Space(16) &. Space(17) &. Space(18) &. Space(14) &. Space(11) &. Space(12) &. Space(9) &. Space(10) &. Space(13) &. Space(19) &. Space(33)...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 26

tailieu.vn

This is a pretty big script, so you may have to fix a few syntax errors introduced by typos you may have made when keying in the script. In this chapter you learned how to use procedures to streamline the organization of your VBScripts, allowing you to develop larger and more complex scripts, and, of course, games.. In addition, you...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 27

tailieu.vn

‘a line of text to a text file.. strFileName = “C:\Temp\Sample.txt”. Set objFileHandle = objFso.OpenTextFile(strFileName, 8) Else. ‘Write 3 lines of text to the text file. objFileHandle.WriteLine “Once upon a time there was a little boy who”. objFileHandle.WriteLine “lived in a shoe. objFileHandle.WriteLine “too small!”. ‘Close the file when done working with it objFileHandle.Close(). You do this by using the...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 28

tailieu.vn

You can copy one or more files using the CopyFile() method. This method also supports an additional parameter that allows you to specify what to do if the script attempts to copy a file to a folder that already contains a file with the same name. The following example demonstrates how to copy all files with a .txt file extension...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 29

tailieu.vn

The script’s main processing section controls the overall execution of the script. The first loop is controlled by a For statement that is responsible for making sure that the script generates the number of sets of lottery numbers specified by the player. The second loop is controlled by a Do Until and is responsible for making sure that a full...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 30

tailieu.vn

Dim FsoObject ‘Sets up a reference to the FileSystemObject Dim OpenFile ‘Sets up a reference to the script’s .ini file. Dim strKeyName ‘Represents a key in the script’s .ini file Dim strSourceFile ‘Specifies the name of the script’s .ini file Dim strInput ‘Represents a line in the script’s .ini file. MsgBox “The .ini file is missing. ‘for the selection of...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 31

tailieu.vn

With proper testing of all the components of a script, most run-time errors can be discov- ered and fixed during script development. I say “most” because not all run-time errors can be caught—those caused by unforeseen circumstances may be impossible to detect during script development. Perhaps the person running the script incorrectly supplied input in a manner that you could...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 32

tailieu.vn

To use the Clear() method, place it at the end of your error-handling routine, as demonstrated in the previous example. Without this method, the only way that you could test your error-handling routines would be to deliberately introduce an error sit- uation into your code. Err.Raise(500). For example, if you save the previous statement as a script and run it,...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 33

tailieu.vn

‘The Player wants to quit the game If strProcessGuess = “ExitFunction” Then. Exit Function End If. ‘The player typed invalid input If strProcessGuess <>. “SkipRest” Then. “IncorrectAnswer” Then. ‘the interim stage of the word as currently guessed by player strTempStringTwo. ‘Check to see if the player has guessed the word blnGameStatus = CheckIfGameWon(). Exit Do End If. ‘Set the value...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 34

tailieu.vn

‘Initialize variables displayed by the game’s initial pop-up dialog intNoMisses = 0. ‘Get the game a mystery word strGameWord = RetrieveWord(). ‘Let the player start guessing Do Until intNoMisses = 6. ‘Collect the player’s guess. ‘Determine if the player has quit If strChoice. Exit Function End If. ‘The player wants to quit the game If strProcessGuess = “ExitFunction” Then. ‘The...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 35

tailieu.vn

Figures 10.1 through 10.6 demonstrate the overall flow of the game from beginning to end.. Figure 10.1. Figure 10.2. Figure 10.3. Figure 10.4. The flow of the game runs exactly. By the time you’ve finished writing the new Hangman setup script and modifying the orig- inal Hangman game, you’ll have a basic understanding of the Windows Registry and what it...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 36

tailieu.vn

This script will create and store a Registry key called Hangman in the HKEY_CURRENT_USER root key (referred to in the script as HKCU. Within this key, a value called ListLocation will be created and assigned a string iden- tifying the location where you plan to store your Hangman word files. Set up the controlling logic in the Main Processing Section,...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 37

tailieu.vn

End If. ‘Display the splash screen and ask the user if he or she wants to play strSplashimage = Space(100) &. Space(68) &. Space(18) &. Space(100) &. Space(50) &. Space(15) &. Space(99) &. Space(1) &. Space(17) &. Space(120) &. space(113) &. “Would you like to play a game?” &. ‘Initialize variables displayed in the game’s initial pop-up dialog intNoMisses =...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 38

tailieu.vn

Microsoft WSH and VBScript Programming for the Absolute Beginner, Second Edition. Create new collection of word files to increase the number of categories avail- able to the player.. Add an error-handling routine to the HangmanSetup.vbs script and use it to report any problems that may occur when the script attempts to perform the RegWrite() method.. Modify HangmanSetup.vbs to display a...

Microsoft WSH and VBScript Programming for the Absolute Beginner Part 39

tailieu.vn

objFirstHero.DisplayIdentity() ‘Execute the SuperHero object’s method. objsecondHero.DisplayIdentity() ‘Execute the SuperHero object’s method. ‘the SuperHero object is instantiated MsgBox “In a blast of smoke and lightning another new super “ &. As the script runs, pop-up dialogs will be displayed as shown in Figures 11.8 and 11.9 demon- strating the execution of the Class_Initialize event and the object’s DisplayIdentity() method.. Figure...