Creating an interactive riddle In Excel VBA

josaah

Board Regular
Joined
Oct 1, 2016
Messages
54
Hi My Friends,
I'm trying to create an interactive riddle that uses comments as the riddle description, an image and a confirmation statement to confirm a correct answer.

At start, a start button in the woorksheet is clicked to randomly assign the block of 16 cells with the riddle descriptions as comments. (once the cells are commented, the start button is disabled)

When the user points the mouse at a comment the programme uses speech.speak to read it. The user enters the answer in the cell and clicks a submit button to submit the answer. The answer is compared with a word or phrase corresponding to the description in the cell comment.

If the answer is not correct, the user is requested to try again. (The request must be both wrtten and spoken/read by the programme).

If the answer is correct, the programme loads a corresponding image and a confirmation message in a frame and the comment for that cell is cleared. (The message is read by the programme.) This is done until all the questions are answered, but there is the option on the frame whether the user would like to continue, restart or exit the game.

Every attempt is counted so that when the game is over the total correct answers are multiplied by the score per question and the percentage of that result is found of the total attempts multiplied by the score per question. (total correct answers*score per question/ number of attempts*score per question)*100

We will use the names of 16 animals as the answers.

The arrays below show the names of the animals, the riddles which go into the comment text note and the names of the images

names of the animals

myAnswer(1) = "baboon"
myAnswer(2) = "black marlin"
myAnswer(3) = "deer"
myAnswer(4) = "chimpanzee"
myAnswer(5) = "ostrich"
myAnswer(6) = "oarfish"
myAnswer(7) = "stonefish"
myAnswer(8) = "peregrine falcon"
myAnswer(9) = "wolf"
myAnswer(10) = "cheetah"
myAnswer(11) = "shark"
myAnswer(12) = "gazelle"
myAnswer(13) = "gorilla"
myAnswer(14) = "orangutan"
myAnswer(15) = "octopus"
myAnswer(16) = "flying fish"


the riddles which go into the comment text note

myQuestion(1) = "I am a large ground-dwelling monkey. " & Chr(10) & "I have a long pointed face like a dog and my teeth are large. " & Chr(10) & "I can be found in Africa and Asia. "
myQuestion(2) = "I am a very large fish. " & Chr(10) & "I can be found in the warm tropical waters of the Indian and Pacific Oceans. " & Chr(10) & "I am the fastest fish in the world. "
myQuestion(3) = "I am an animal with long legs. " & Chr(10) & "I eat grass, leaves, etc. " & Chr(10) & "I can run fast. " & Chr(10) & "Most of my males have horns shaped like branches. "
myQuestion(4) = "I am a very intelligent African ape. " & Chr(10) & "I am small. " & "I have long dark-brown hair, but there are no hairs in my face and on my ears. " & Chr(10) & "I am native to equatorial Africa. "
myQuestion(5) = "I am a very large African bird. " & Chr(10) & "I have a long neck and long legs. " & Chr(10) & "I cannot fly, but I am the fastest bird on land. "
myQuestion(6) = "I am a long, eel-shaped fish. " & Chr(10) & "I can grow up to 7 m/23 ft. " & Chr(10) & "I have a red head fin and dorsal fin. " & Chr(10) & "I can be found in the tropical Atlantic waters. "
myQuestion(7) = "I am a fish. " & Chr(10) & "My body looks like rock. " & Chr(10) & "I use that to hide from my enemies. " & Chr(10) & "My bite is poisonous. " & Chr(10) & "I can be found among the rocks in the sea. " & Chr(10) & "I live in the tropical waters. "
myQuestion(8) = "I am a blue-grey black and white bird. " & Chr(10) & "I hunt other birds for my food. " & Chr(10) & "I am therefore known as a bird of prey. " & Chr(10) & "I can be trained to hunt for sport. " & Chr(10) & "I am the fastest bird in the air. " & Chr(10) & "I can fly up to 320 km/h (200mph). " & Chr(10) & "I can be found on every continent. "
myQuestion(9) = "I am a large wild dog. " & Chr(10) & "I hunt and eat other animals. " & Chr(10) & "We live and hunt in groups. " & Chr(10) & "Our group is called a pack. " & Chr(10) & "You can find us in North America and Eurasia. "
myQuestion(10) = "I am a large cat. " & Chr(10) & "I wear a yellowish brown and black-spotted coat. " & Chr(10) & "I have a small head, slender body, and long legs. " & Chr(10) & "I am the fastest animal on land. " & Chr(10) & "I can be found in Africa and Southwestern Asia. "
myQuestion(11) = "I am a large fish with a long body and sharp teeth " & Chr(10) & "I have a thick and rough skin. " & Chr(10) & "I have a cartilaginous skeleton and two dorsal fins on back. " & Chr(10) & "I can sometimes be seen above the water. "
myQuestion(12) = "I am a small graceful and swift antelope." & Chr(10) & "I have long ringed horns, large eyes and black face markings. " & Chr(10) & "I can be found in plains of Africa and Asia. "
myQuestion(13) = "I am the largest ape. " & Chr(10) & "I have a short but very powerful body and coarse dark hair." & Chr(10) & "You can find me in the western and central part of Africa."
myQuestion(14) = "I am a large long-armed ape. " & Chr(10) & "I am like a monkey, but I don't have a tail. " & Chr(10) & "I have reddish hair. " & Chr(10) & "You can find me in the islands of Borneo and Sumatra in the Pacific Ocean. " & Chr(10) & "My name means forest person. " & Chr(10) & "I look like a human being, but I have hairs all over my body. "
myQuestion(15) = "I am a sea creature. " & Chr(10) & "I have a big head, a soft oval body, well-developed eyes, and eight long arms. " & Chr(10) & "I live on the ocean floor. " & Chr(10) & "I can be found in the big seas. "
myQuestion(16) = "I am a fish. " & Chr(10) & "I have fins that can be held like wings. " & Chr(10) & "I can glide short distances above the surface of the water using my very large fins. " & Chr(10) & "You can find me in the warm or tropical seas. "



the names of the images

myImage(1) = "baboon.jpeg"
myImage(2) = "black marlin.jpeg"
myImage(3) = "deer.jpeg"
myImage(4) = "chimpanzee.jpeg"
myImage(5) = "ostrich.jpeg"
myImage(6) = "oarfish.jpeg"
myImage(7) = "stonefish.jpeg"
myImage(8) = "peregrine falcon.jpeg"
myImage(9) = "wolf.jpeg"
myImage(10) = "cheetah.jpeg"
myImage(11) = "shark.jpeg"
myImage(12) = "gazelle.jpeg"
myImage(13) = "gorilla.jpeg"
myImage(14) = "orangutan.jpeg"
myImage(15) = "octopus.jpeg"
myImage(16) = "flying fish.jpeg"


Let the confirmation message be "Yes, I'm a/an + the name of the animal"

Indicate where the image path should be (or you may use any image you like)

There will be a messagebox that requests for bale/bail out if the user is not able to answer a given riddle after three attempts. Clicking yes produces the riddle, the image and the answer "I am a/an" + the name.

if you need further information, let me know and I'll provide.
if possible, add notes so i can learn from the code.
Thanks for your usual cooperation.



Thanks very much. I'll try it and give you feedback. Have a blessed day
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
you can use userform to create the UI. you can display and hide images with code signed to a specific button.
 
Upvote 0
HI, Mr. DachickenMind,
I have finally been able to load the picture by your method, but not yet into the frame on the userform or the image in the worksheet.

Thanks very much


The problem was that when you hover the mouse over the pictures, it shows "jpeg", but I used hyperlink to insert it into the worksheet in order to get the fullpath and I got "jpg" when i changed it, the picture loaded.

But the scores do not appear.

I have been trying to change the font properties of the riddle (comment) by the concatenated parts, but I got an error

object required

this is the code

Code:
For I = 1 To 4
For j = 1 To 4
Cells(myHiddenAnswerPOX + I, myHiddenAnswerPOY + j) = myAnswerBlock(I, j)
Cells(myinitPOSX + I, myinitPOSY + j).Select
Selection.AddComment
Selection.Comment.Visible = False




Selection.Comment.Text Text:="Riddle, riddle" & Chr(10) & myQuestionBlock(I, j) & Chr(10) & "Who am I?"
Selection.Comment.Shape.Width = 350 ' msoFalse, msoScaleFromTopLeft
Selection.Comment.Shape.Height = 100 'ScaleHeight 0.86, msoFalse, msoScaleFromTopLeft


Selection.Comment.Text.Characters(15 ).Font.Color = RGB(0, 255, 255)


                                                          .FontStyle = "Bold Italic"
                                                          .Name   =   "Tahoma"
                                                           .size      = 9




Selection.Comment.Text.Characters(15, Len (myQuestionBlock(I, j))).Font.Color = RGB(255,  0,  255)


                                                          .FontStyle = "Bold Italic"
                                                          .Name   =   "Script MT Bold"
                                                           .size      = 16


Selection.Comment.Text.Characters(Len (myQuestionBlock(I, j))+ 16, 10).Font.Color = RGB(0, 255, 255)


                                                          .FontStyle = "Bold Italic"
                                                          .Name   =   "Tahoma"
                                                           .size      = 9





'Range("A1").Comment.Shape.Height


'Appliction.Speech.Speak "Riddle, riddle" & Chr(10) & myQuestionBlock(i, j) & Chr(10) & "Who am I?", True




'Cells(myinitPOSX + i, myinitPOSY + j).Comment.Shape.Select
'Selection.ShapeRange.ScaleWidth 3.68, msoFalse, msoScaleFromTopLeft
'Selection.ShapeRange.ScaleHeight 0.86, msoFalse, msoScaleFromTopLeft
'Selection.Comment.Shape.TextFrame.AutoSize = True
Next j
Next I
 
Upvote 0
HI, Mr. DachickenMind,
I have finally been able to load the picture into the image control in the worksheet.
I will clean the code an paste the current resultant one here later

Thanks very much. I'm very grateful

Would anyone help me to change the font properties of the cell comments?


Code:
[/COLOR]For I = 1 To 4
For j = 1 To 4
Cells(myHiddenAnswerPOX + I, myHiddenAnswerPOY + j) = myAnswerBlock(I, j)
Cells(myinitPOSX + I, myinitPOSY + j).Select
Selection.AddComment
Selection.Comment.Visible = False




Selection.Comment.Text Text:="Riddle, riddle" & Chr(10) & myQuestionBlock(I, j) & Chr(10) & "Who am I?"
Selection.Comment.Shape.Width = 350 ' msoFalse, msoScaleFromTopLeft
Selection.Comment.Shape.Height = 100 'ScaleHeight 0.86, msoFalse, msoScaleFromTopLeft


Selection.Comment.Text.Characters(15 ).Font.Color = RGB(0, 255, 255)


                                                          .FontStyle = "Bold Italic"
                                                          .Name   =   "Tahoma"
                                                           .size      = 9




Selection.Comment.Text.Characters(15, Len (myQuestionBlock(I, j))).Font.Color = RGB(255,  0,  255)


                                                          .FontStyle = "Bold Italic"
                                                          .Name   =   "Script MT Bold"
                                                           .size      = 16


Selection.Comment.Text.Characters(Len (myQuestionBlock(I, j))+ 16, 10).Font.Color = RGB(0, 255, 255)


                                                          .FontStyle = "Bold Italic"
                                                          .Name   =   "Tahoma"
                                                           .size      = 9





'Range("A1").Comment.Shape.Height


'Appliction.Speech.Speak "Riddle, riddle" & Chr(10) & myQuestionBlock(i, j) & Chr(10) & "Who am I?", True




'Cells(myinitPOSX + i, myinitPOSY + j).Comment.Shape.Select
'Selection.ShapeRange.ScaleWidth 3.68, msoFalse, msoScaleFromTopLeft
'Selection.ShapeRange.ScaleHeight 0.86, msoFalse, msoScaleFromTopLeft
'Selection.Comment.Shape.TextFrame.AutoSize = True
Next j
Next I[COLOR=#333333]

I'll be very grateful
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,991
Members
449,094
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top