Results 1 to 8 of 8

Thread: [RESOLVED] Check Image.

  1. #1

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Resolved [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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  2. #2
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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.

  3. #3

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Check Image.

    Quote 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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  4. #4

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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...

  6. #6
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    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:
    1. 'Load the images into an array
    2.         Dim images As Image() = {Image.FromFile("C:\pic1.bmp"), Image.FromFile("C:\pic2.bmp"), Image.FromFile("C:\pic3.bmp")}
    3.  
    4.         'Open a filestream to the file to be created
    5.         Dim fs As New IO.FileStream("C:\images.dat", IO.FileMode.Create)
    6.  
    7.         'Create new BinaryFormatter object and serialize the data
    8.         Try
    9.             Dim bs As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
    10.             bs.Serialize(fs, images)
    11.         Catch ex As Exception
    12.             MessageBox.Show("Serialization of data failed for the following reason: " & ex.Message)
    13.         End Try
    14.  
    15.         'Close the file stream
    16.         fs.Close()
    17.  
    18.         'Now retrieve the images from the file.  Get a handle to the file
    19.         Dim newFS As New IO.FileStream("C:\images.dat", IO.FileMode.Open)
    20.  
    21.         'Deserialize the data and retrieve the array
    22.         Try
    23.             Dim bs As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
    24.             Dim newImages As Image() = bs.Deserialize(newFS)
    25.         Catch ex As Exception
    26.             MessageBox.Show("Deserialization of data failed for the following reason: " & ex.Message)
    27.         End Try
    28.  
    29.         'Now we can use the images again
    30.         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"

  7. #7
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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:
    1. Private questionNo As Integer = 0
    2. Private Images As New Arraylist
    3. Private Answers As New Arraylist
    4.  
    5. Sub AddQuestion(ByVal ans As String, ImageName As String)
    6.  Images.Add(Bitmap.FromFile(ImageName) 'load bitmap file and add to array
    7.  Answers.Add(ans) 'add answer to array
    8. End Sub
    9.  
    10. Sub Load
    11.   AddQuestion("The Red Dog","c:\reddog.bmp")
    12.   AddQuestion("Monkey","c:\ink.bmp")
    13. End Sub

    you will use questionNo to determine what question is being used
    to load the question
    VB Code:
    1. 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:
    1. If LCase(TextBox1.Text) = LCase(answers(questionNo)) Then
    2.   questionNo += 1 'move onto next question
    3.   'and your sub to display the new question
    4. Else
    5.  'you're wrong!
    6. 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.

  8. #8

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width