Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-04-2009
Member
 
Join Date: Mar 2009
Posts: 89
Issue with Visual Basic Code

Hello friends,

I have written one code where you select either ball,bat or stump instead of that it gives you only one winner (Computer wins),but in my code it just displays all the Message boxes.I don't know where i have made mistake.

Code:
'Formally declare variables used by the script before trying to use them
Dim WshShl, Answer, CardImage

'Create an instance of the WScript object in order to later use the
'Popup method
Set WshShl = WScript.CreateObject("WScript.Shell")

'Display the rules of the game
WshShl.Popup "Welcome to ball, bat and stump game. Here are the " & _
  "rules of the game: 1. Guess the same thing as the computer " & _
  "to tie. 2. Bat covers Ball and wins. 3. Ball breaks " & _ 
  "stump and wins. 4. Stump hit bat and wins."

'Prompt the user to select a choice
Answer = InputBox("Type  Ball, Bat and Stump.", _
  "Let's play a game!")

'Time for the computer to randomly pick a choice
Randomize
GetRandomNumber = Round(FormatNumber(Int((3 * Rnd()) + 1)))

'Assign a value to the randomly selected number
If GetRandomNumber = 3 then CardImage = "Ball"
If GetRandomNumber = 2 then CardImage = "Bat"
If GetRandomNumber = 1 then CardImage = "Stump"

'Display the game's results so that the user can see if he or she won
WshShl.Popup "You picked: " & Answer & Space(12) & "Computer picked: " & _
  CardImage

If Answer = "ball" & CardImage <> "bat" then _
MsgBox "Bat Covers Ball:Computer wins!"

If Answer = "bat" & CardImage <> "Stump" then MsgBox "Stump Cuts bat:Computer wins!"

If Answer = "stump" & CardImage <> "ball" then MsgBox "Ball Breaks Stump:Computer wins!"

If CardImage = "ball" & Answer <> "bat" then MsgBox "Bat Covers ball:You wins!"

If CardImage = "bat" & Answer<> "Stump" then MsgBox "Stump Cuts Bat:You wins!"

If CardImage = "stump" & Answer <> "ball" then MsgBox "Ball Breaks Stump:You wins!"

If CardImage = "bat" & Answer <> "bat" then MsgBox "TIE!"

If CardImage = "stump" & Answer<> "stump" then MsgBox "TIE!"

If CardImage = "ball" & Answer <> "ball" then MsgBox "TIE!"
Reply With Quote
  #2  
Old 10-04-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Issue with Visual Basic Code

Sure i will help you out with this as i can you you have made a very small mistake while using Operator

In your Code you have written as

Code:
If Answer = "ball" & CardImage <> "bat" then _
but it has to be as follows


Code:
If Answer = "ball" AND  CardImage <> "bat" then _
try to replace it every where you have put & as AND.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Issue with Visual Basic Code"
Thread Thread Starter Forum Replies Last Post
Protect Visual Basic for Applications code Jalela Windows Software 6 10-07-2011 11:13 AM
Tips for Debugging Visual Basic for Applications Code jhon Tips & Tweaks 2 12-03-2010 06:14 AM
Save button code in visual basic 2008 Chrisch Software Development 4 23-08-2009 01:20 AM
Error Code 1330 while installing Visual Basic 2008 Capers Windows Software 2 02-05-2009 07:11 PM
Issue with connection database in Visual Basic Capers Software Development 3 08-04-2009 08:40 PM


All times are GMT +5.5. The time now is 07:45 PM.