Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Become a VB Expert!

Join 149,624 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,986 people online right now. Registration is fast and FREE... Join Now!





Basic Spell this Picture Game

The bare bones of a childrens spelling game, display an image and lets the user spell the word. The only button is to exit the game

Submitted By: KeyWiz
Actions:
Rating:
Views: 4,031

Language: Visual Basic

Last Modified: October 26, 2006
Instructions: Create a form with 1 picturebox, 1 textbox and 1 button

create a cow image and put it at

c:\My Images\Cow.bmp

copy and paste this code to the form (remoe the existing Form_Load procedure)

Snippet


  1.  
  2. [code]
  3. Option Explicit
  4. Public thisImage As String
  5. Public thisWord As String
  6. Public correctAnswers As Integer
  7. Public msgOK
  8.  
  9. Private Sub Command1_Click()
  10. Unload Me
  11. End Sub
  12.  
  13. Private Sub Form_Load()
  14. GetNextPicture
  15. End Sub
  16.  
  17. Private Sub GetNextPicture()
  18.  
  19. 'look up your next image
  20. ' there are many ways to do this, I can't do it all for you
  21. ' I will use only 1 image "c:\My Images\Cow.bmp"
  22.  
  23. thisImage = "c:\My Images\Cow.bmp"
  24. thisWord = "Cow"
  25. Text1.Text = "" ' empty textbox
  26. 'display your image
  27. Picture1.Picture = LoadPicture(thisImage)
  28. Picture1.Refresh
  29.  
  30. End Sub
  31.  
  32. Private Sub Form_Unload(Cancel As Integer)
  33. Close All ' close all datasources
  34. End ' exit program
  35. End Sub
  36.  
  37. Private Sub Text1_Change()
  38.  
  39. If Text1.Text = LCase(thisWord) Then
  40. msgOK = MsgBox("Thats Right!!!!", vbOKOnly)
  41. correctAnswers = correctAnswers + 1
  42. If correctAnswers >= 5 Then
  43. msgOK = MsgBox("Fantasic! you are done!", vbOKOnly)
  44. Unload Me ' call closing routine (same as clicking X in form corner)
  45.  
  46. End If
  47. GetNextPicture
  48. Else
  49. ' if user types two letter more than word length
  50. If Len(Text1.Text) > (Len(thisWord) + 2) Then
  51. msgOK = MsgBox("I'm sorry, try again", vbOKOnly)
  52. Text1.Text = ""
  53. End If
  54. End If
  55. End Sub
  56. [code]

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month