Wrox Programmer Forums
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 5th, 2011, 08:32 PM
Registered User
 
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ? on code

Am a newbie to scripting doing as an learn on my own kinda thing and in the microsoft wsh & vbscript programming for the absolute beginner there is a challenge at the end of the chapter and am looking to change the code so that it displays the correct answer for any question that the player misses. I open it/modify it in NotePad and dbl click the file to launch Windows Script Host to run the quiz... VBScript


Any help will be appreciated.

Code:
'Perform script initialization activities

Option Explicit

Dim intPlayGame, strSplashImage, strAnswerOne, strAnswerTwo, strAnswerThree
Dim strAnswerFour, strAnswerFive, intNumberCorrect, strFederationRank
Dim objFsoObject

Const cTitlebarMsg = "The Star Trek Quiz Game"

'Start the user's score at zero
intNumberCorrect = 0

'Display the splash screen and ask the user if he or she wants to play
strSplashImage = space(11) & "********" & vbCrLf & _
  "  ******************" & space(20) & "**************************" & _
  space(15) & vbCrLf & "*" & space(30) & "*" & space(18) & _
  "**" & space(39) & "*" & vbCrLf & "  ******************" & _
  space(20) & "*************************" & vbCrLf & space(31) & _
  "******" & space(26) & "***" & vbCrLf & _
  space(34) & "******" & space(22) & "***" & vbCrLf & _
  space(37) & "******" & space(17) & "***" & vbCrLf & _     
  space(26) & " ****************************" & vbCrLf & _
  space(26) & "*******************************" & vbCrLf & _
  space(26) & "******************************" & vbCrLf & _
  space(26) & " ****************************" & vbCrLf & vbCrLf & vbCrLf & _
  "Would you like to boldly go where no one has gone before?"

intPlayGame = MsgBox(strSplashImage, 36, cTitlebarMsg)

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?", cTitlebarMsg)
  
If LCase(strAnswerOne) = "spock" Then
  intNumberCorrect = intNumberCorrect + 1
End If 

Else 'User doesn't want to play

  MsgBox "Thank you for taking the Star Trek Quiz © Jerry Ford 2002." & _
    vbCrLf & vbCrLf & "Live long and prosper!", , cTitlebarMsg  
  WScript.Quit()

End If

strAnswerTwo = InputBox("What Star Trek villain appeared in both the " & _
  "original series and a Star Trek movie?", cTitlebarMsg)

If LCase(strAnswerTwo) = "khan" Then
  intNumberCorrect = intNumberCorrect + 1
End If

strAnswerThree = InputBox("What was the numeric designation of " & _
  "Voyager's on-board Borg?", cTitlebarMsg)

If CStr(strAnswerThree) = "7" Then
  intNumberCorrect = intNumberCorrect + 1
ElseIf CStr(strAnswerThree) = "7 of 9" Then
  intNumberCorrect = intNumberCorrect + 1
End If

strAnswerFour = InputBox("Name the only Star Trek character to " & _
  "regularly appear on two series and at least two Star Trek " & _
  "movies?", cTitlebarMsg)

If LCase(strAnswerFour) = "worf" Then
  intNumberCorrect = intNumberCorrect + 1
End If

strAnswerFive = InputBox("What is the last name of your favorite " & _
  "Captain?", cTitlebarMsg)
  
If Len(strAnswerFive) > 3 Then
  If Instr(1, "kirkpicardsiscojanewayarcher", LCase(strAnswerFive), 1) _
  <> 0 Then
    intNumberCorrect = intNumberCorrect + 1
  End If
End If

Select Case intNumberCorrect
  Case 5 'User got all five answers right
    strFederationRank = "Admiral"
  Case 4 'User got 4 of 5 answers right 
    strFederationRank = "Captain"    
  Case 3 'User got 3 of 5 answers right
    strFederationRank = "Commander"
  Case 2 'User got 2 of 5 answers right
    strFederationRank = "Lieutenant-Commander"
  Case 1 'User got 1 of 5 answers right
    strFederationRank = "Lieutenant"
  Case 0 'User did not get any answers right
    strFederationRank = "Ensign"
End Select

MsgBox "You answered " & intNumberCorrect & " out of 5 correct." & _
  vbCrLf & vbCrLf & "Your Star Fleet rank is : " & _
  strFederationRank, , cTitlebarMsg

Last edited by davewillis; March 5th, 2011 at 08:47 PM..
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to save html page source code? Jaymond Flurrie Access VBA 2 July 2nd, 2019 06:04 PM
Double clicking control does not add code to Code Behind Paul Walton BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 September 25th, 2009 05:40 PM
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.