|
-
Jan 1st, 2006, 06:05 AM
#1
[RESOLVED] Check Image.
Hi All,
I'm working on a Spatial thinking app for Kids and I've a Check problem about that. A little more explaination.
I've got a label and a TextBox, in that Textbox they have to put the solution of the Image. To change the Images in that label I'm using ' Select Case Image -> several cases -> End Select
How can I Check the solution into the TextBox and if the solution is correct the user will be abel to select the next case.
Wkr,
sparrow1
-
Jan 2nd, 2006, 03:24 AM
#2
Re: Check Image.
you shouldn't use case statements to do this, you need a way to retrieve a certain image and its answer, Personally If the questions only go 1 way, i would use serialization to store your images and answers in a .dat file (which will rest in your programs main folder), this would also allow for an easy way to "upgrade" or "extend" your application at a later date.
Of course if you don't want to use files, particulary if there is not many questions, you could just use two arrays, one storing filenames of images you have and the other with the answers.
Also, you should use a PictureBox instead of a label to show your image, that's what theyre for :P
Let me know which way you'd rather use and i'll help you through it.
-
Jan 3rd, 2006, 11:22 AM
#3
Re: Check Image.
 Originally Posted by Phill64
you shouldn't use case statements to do this, you need a way to retrieve a certain image and its answer, Personally If the questions only go 1 way, i would use serialization to store your images and answers in a .dat file (which will rest in your programs main folder), this would also allow for an easy way to "upgrade" or "extend" your application at a later date.
Of course if you don't want to use files, particulary if there is not many questions, you could just use two arrays, one storing filenames of images you have and the other with the answers.
Also, you should use a PictureBox instead of a label to show your image, that's what theyre for :P
Let me know which way you'd rather use and i'll help you through it.
Hi Phill,
I really appreciat your help for this problem.
Because I want to learn more and more....about VB.Net, I'm interested in both ways to solve this problem if you don't mind.
An explaination how to do it, with a small example, could be very usefull.
If you find it nessecary you can always use my E-mail!
Wkr,
sparrow1
-
Jan 11th, 2006, 03:38 PM
#4
Re: Check Image.
Hi,
I tryed to find something about serialization but didn't found something!
Is there someone that can explain how that works, and where I can find some information.
Thanks,
sparrow1
-
Jan 11th, 2006, 04:41 PM
#5
Re: Check Image.
Why not load the images in an image list (a component you add to your form) or an arraylist... you can then retrieve the images and display the one you want in a picturebox or any control you desire (or just store the name so you can run the procedure to load the one you wish from file instead of loading all of them at one time)... and have the questions associated with each image index... Ex.. question 1, show image index 0, question 2, show image index 1, and so on...
-
Jan 11th, 2006, 04:47 PM
#6
Hyperactive Member
Re: Check Image.
Here's an example of both serializing and deserializing images. It assumes that you have three images in the "C:\" directory named "pic1.bmp", "pic2.bmp" and "pic3.bmp":
VB Code:
'Load the images into an array
Dim images As Image() = {Image.FromFile("C:\pic1.bmp"), Image.FromFile("C:\pic2.bmp"), Image.FromFile("C:\pic3.bmp")}
'Open a filestream to the file to be created
Dim fs As New IO.FileStream("C:\images.dat", IO.FileMode.Create)
'Create new BinaryFormatter object and serialize the data
Try
Dim bs As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
bs.Serialize(fs, images)
Catch ex As Exception
MessageBox.Show("Serialization of data failed for the following reason: " & ex.Message)
End Try
'Close the file stream
fs.Close()
'Now retrieve the images from the file. Get a handle to the file
Dim newFS As New IO.FileStream("C:\images.dat", IO.FileMode.Open)
'Deserialize the data and retrieve the array
Try
Dim bs As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim newImages As Image() = bs.Deserialize(newFS)
Catch ex As Exception
MessageBox.Show("Deserialization of data failed for the following reason: " & ex.Message)
End Try
'Now we can use the images again
Me.BackgroundImage = newImages(0)
You can serialize any type of object you wish, but (as far as I know) it has to be an object, i.e. just one. The easiest way is just to throw all the objects into an array or Arraylist and serialize that.
Last edited by Parallax; Jan 12th, 2006 at 11:44 AM.
"Make it idiot-proof and someone will make a better idiot"
-
Jan 12th, 2006, 08:26 AM
#7
Re: Check Image.
sorry i didn't reply earlier i must have missed this thread!
since serialization has been covered, ill show you the memory hogging but simpler way of matching images with answers, im going to use an arraylist for simplicity (since you can add as many items as you like)
VB Code:
Private questionNo As Integer = 0
Private Images As New Arraylist
Private Answers As New Arraylist
Sub AddQuestion(ByVal ans As String, ImageName As String)
Images.Add(Bitmap.FromFile(ImageName) 'load bitmap file and add to array
Answers.Add(ans) 'add answer to array
End Sub
Sub Load
AddQuestion("The Red Dog","c:\reddog.bmp")
AddQuestion("Monkey","c:\ink.bmp")
End Sub
you will use questionNo to determine what question is being used
to load the question
VB Code:
PictureBox1.Image = Images(questionNo)
to test the answer (LCase is included so answer is NOT case sensitive by making both strings lower characters)
VB Code:
If LCase(TextBox1.Text) = LCase(answers(questionNo)) Then
questionNo += 1 'move onto next question
'and your sub to display the new question
Else
'you're wrong!
End If
You can serialize any type of object you wish, but (as far as I know) it has to be an object, i.e. just one. The easiest way is just to throw all the objects into an array or Arraylist and serialize that.
Incorrect, you can only serialize objects marked as serializable, and you can shove as many objects into 1 file as you like, because it's designed to work over streams, so long as you retrieve them in the correct order.
Last edited by Phill64; Jan 12th, 2006 at 08:31 AM.
-
Jan 28th, 2006, 04:40 AM
#8
Re: Check Image.
Hi All,
Thanks for helping me to find a way to check an Image!
I found a solution see this thread!
http://www.vbforums.com/showthread.php?t=383937
Wkr,
sparrow1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|