Click here to Skip to main content
15,906,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a Jeopardy like game for a school teacher to use in a classroom environment. I have the program working, but she has also requested that the program has the ability to be able to show a picture for each question. As of now, I am using StreamWriter and StreamReader to save the values of the game variables, but I am stumped as to how to include pictures into this same file. I have looked through articles but I haven't had any luck finding exactly what I am looking for. The only solution that I have been able to come up with is to copy each picture she wants to a new directory and save the location of that picture to my already created text file, but that is not how I want to do it as it creates a lot of areas where things can be deleted. Maybe there is a method of combining text and image files into a separate file like a Zip file? I am still pretty new to VB, so any help would be appreciated. For reference, I have attached the two subroutines below for reading and writing my text file.

VB
Private Sub SaveFileTo()
        Dim sfd As New SaveFileDialog()

        sfd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        sfd.Filter = "Jeopardy Games | *.jpd"
        sfd.DefaultExt = "jpd"
        If sfd.ShowDialog(Me) = Windows.Forms.DialogResult.OK And sfd.FileName.Length > 0 Then
            If File.Exists(sfd.FileName) Then
                If MsgBox("File already exists! Do you want to overwrite this file?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.Question, "File Exists!") = MsgBoxResult.Ok Then
                    FileName = sfd.FileName
                    WriteFile()
                End If
            Else
                FileName = sfd.FileName
                WriteFile()
            End If

        End If

    End Sub


VB
Private Sub WriteFile()
        Dim i As Short

        Using sw As StreamWriter = New StreamWriter(FileName)
            For i = 0 To 4
                sw.WriteLine(Topic(i))
            Next
            For i = 0 To 24
                sw.WriteLine(Jeopardy(i).Question)
                For j = 0 To 3
                    sw.WriteLine(Jeopardy(i).Answer(j))
                    sw.WriteLine(Jeopardy(i).Enable(j))
                    sw.WriteLine(Jeopardy(i).Correct(j))
                Next
                sw.WriteLine(Jeopardy(i).InfoReady)
                sw.WriteLine(Jeopardy(i).MultAnsw)
            Next
            sw.WriteLine(NegScore)
            sw.WriteLine(TeamNum)
        End Using
    End Sub
Posted
Updated 21-Aug-12 10:15am
v3

As Christian stated above, serialization is a good way to go. I'd suggest creating a class with public properties for the image and text, and using serialization to store and retrieve them. This way you can store all the image/text pairs in a single file.

Here's a page of links to get you started: http://msdn.microsoft.com/en-us/library/ms172360%28v=vs.100%29.aspx[^]
 
Share this answer
 
You should see if you cant find anything useful here:
http://msdn.microsoft.com/en-us/library/c520bdhb%28v=vs.80%29.aspx[^]

Looks to give you a complehencive overview of the possibilities :)
 
Share this answer
 
To save images, not their location, in to a file, your best bet is serialisation. This will allow you to define a list of a class that contains your data, and just save it.

Here[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900