Save Puzzle

I've been Used a  VB6  Puzzle Code  ,  that let the game player choose a picture, devide it into no of Pieces, randomize these parts, then let the  game player  rearrange them again, and it is working fine.
I Need to add extra feature for the game, if the game player start the game, and  would like to continue later,  I'd like to give him the ability to save his work and continue later, which means he load the picture he want, then the system  devided it to  n number of  Pieces and randomize it, he soved  a 80% of the puzzle, and he would like to continue later, and he don't like to start from the   scrach.
I'm facing a problem in saving the picture after deviding it into Pieces and randomizing it .
i used ready made code.
kindly   see this link :
http://www.geocities.com/emu8086/vb/

then   click  on :
Create and Solve a picture Puzzle
 
and download the zip File to see the code.

i need to add my code after this line :
myPuzzle1.RandomizePictures
----
I put this line of code :

SavePicture myPuzzle1.MyPicture, "TEST33.jpg"

but the system saves the same picture befor randomizing.



hopefully you will find me  a solution.



falahatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

veeru_friendCommented:
Hello my dear friend

The state ment below
SavePicture myPuzzle1.MyPicture, "veeru2.bmp"

call's the below function in myPuzzle usercontrol

Public Property Get MyPicture() As Picture
    Set MyPicture = picMAIN.Picture
End Property

where you are returning picMain.Picture

but you are not change picMain.Picture (i am mean re-painting)
in RandomizePictures() or in dividePICTURES() function

just you are changing positions of picD() picture array elements

just repaint picMain.Picture after RandomizePicture function will give you expected result.





PaulHewsCommented:
Add the following to the declaration area of myPuzzle in project2:

Public FileName As String

Now add the following to the bottom of myPuzzle in project2 after the last property (MyPicture)

Public Function NumSubPics() As Integer
    NumSubPics = picD.Count
End Function

Public Property Get PicTop(Index As Integer) As Long
    PicTop = picD(Index).Top
End Property
Public Property Let PicTop(Index As Integer, NewValue As Long)
    picD(Index).Top = NewValue
End Property

Public Property Get PicLeft(Index As Integer) As Long
    PicLeft = picD(Index).Left
End Property
Public Property Let PicLeft(Index As Integer, NewValue As Long)
    picD(Index).Left = NewValue
End Property

Now add two command buttons to the form in project1.  Call them cmdSaveGame and cmdLoadGame:
Add this code to the form
Private Sub cmdLoadGame_Click()
    Dim hFile As Integer, i As Integer
    Dim intTemp As Integer
    Dim lngTemp As Long
    Dim strFilename As String
    strFilename = Space(1024)
   
    If Len(Dir(App.Path & "\Puzzle.sav")) > 0 Then
        MsgBox "Saved game doesn't exist"
        Exit Sub
    End If

    hFile = FreeFile
    Open App.Path & "\Puzzle.sav" For Binary As #hFile
    Get #hFile, , strFilename
    Set myPuzzle1.MyPicture = LoadPicture(Trim(strFilename))
    Get #hFile, , intTemp
    myPuzzle1.RowCount = intTemp
    Get #hFile, , intTemp
    myPuzzle1.ColCount = intTemp
   
    myPuzzle1.dividePICTURES
   
    For i = 0 To myPuzzle1.NumSubPics - 1
        Get #hFile, , lngTemp
        myPuzzle1.pictop(i) = lngTemp
        Get #hFile, , lngTemp
        myPuzzle1.picleft(i) = lngTemp
    Next i
    Close #hFile
End Sub

Private Sub cmdSaveGame_Click()
    Dim hFile As Integer, i As Integer
   
   
    If Len(Dir(App.Path & "\Puzzle.sav")) > 0 Then
        Kill App.Path & "\Puzzle.sav"
    End If
    hFile = FreeFile
    Open App.Path & "\Puzzle.sav" For Binary As #hFile
    Put #hFile, , Left$(myPuzzle1.FileName & Space(1024), 1024)
    Put #hFile, , myPuzzle1.RowCount
    Put #hFile, , myPuzzle1.ColCount
    For i = 0 To myPuzzle1.NumSubPics - 1
        Put #hFile, , myPuzzle1.pictop(i)
        Put #hFile, , myPuzzle1.picleft(i)
    Next i
    Close #hFile
   
   
End Sub
It saves the filename, number of rows and columns, then the top and left of each indexed piece of the puzzle.  When loading, it reassigns those properties to the puzzle.
falahatAuthor Commented:
thanks my dear friend (veeru_friend)  for help
but can you explain more to me how to do the   repaint , the full statment
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

falahatAuthor Commented:
thank you PaulHews   for help
but there is a problem in writing in the file can you double check  cmdSaveGame procedure
because it gave me the message  "Saved game doesn't exist", I Opend the Puzzle.sav file
it contained the  following  
"                                                                                                                                                                                                            ژ   ٹ   G   ٹ   ژ       ژ   \       ٹ           G   .   G           \   ژ   .       .   "
MariamSCommented:
   myPuzzle1.RandomizePictures
This statement will change the picture based on the number of rows and columns selected.
So when you save the picture using SavePicture myPuzzle1.MyPicture, "TEST33.jpg" after this myPuzzle1.RandomizePictures, this would save the changed picture & not the one you are trying to save.
So use the statement SavePicture myPuzzle1.MyPicture, "TEST33.jpg" first before you use the myPuzzle1.RandomizePictures

   
PaulHewsCommented:
Saving the picture will ONLY save the picture.  Considering you must first load the picture from a file, that does very little to help, so I put the file name in the saved game file.  

>it gave me the message  "Saved game doesn't exist"

Have you made modifications to the code other than what I stated?  I tested this against the downloaded project and it worked fine.  The only time you should get the "does not exist" message is when the file itself does not exist.  So if you've changed the code to write the file to a different location for example, you will have this problem.  Assuming you haven't changed the code, the length of the saved game file should be 1132 bytes.  It's a binary file, so you may not be able to read it correctly with Notepad.
falahatAuthor Commented:
dear  PaulHews  
kindly what you will get by this line:
Put #hFile, , Left$(myPuzzle1.FileName & Space(1024), 1024)
PaulHewsCommented:
It saves the filename to the file, padded with spaces at the end until the entire string is 1024 bytes long.  The purpose of padding the string is because when we read it back in, we need to know how many bytes to read back in.  Every other variable that we write to the file has a fixed length, except the string.
falahatAuthor Commented:
dear  PaulHews  
Regarding the line  Put #hFile, , Left$(myPuzzle1.FileName & Space(1024), 1024)
the  myPuzzle1.FileName  doesn't get the file name, I put the the file name hardcoded and it is working fine.
so thank you ...

There is another question related to this question:
How to store the new image resulted from dividing and randomizing the original picture, means I Need to store
the new image itself, not its sub images places?
PaulHewsCommented:
Make this change to the cmdLoadPic button event

Private Sub cmdLoadPic_Click()

  CommonDialog1.InitDir = App.Path
   
  CommonDialog1.Flags = cdlOFNHideReadOnly
  CommonDialog1.Filter = "Picture Files (*.bmp;*.gif;*.jpg)|*.bmp;*.gif;*.jpg|All Files|*.*"
  CommonDialog1.ShowOpen
  Set myPuzzle1.MyPicture = LoadPicture(CommonDialog1.FileName)
  myPuzzle1.FileName = CommonDialog1.FileName
   
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
falahatAuthor Commented:
Dear   friends
There is another question related to this question:
How to store the new image resulted from dividing and randomizing the original picture, means I Need to store
the new image itself, not its sub images places?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.