help please i am creating a game and i would like to record the score and name ounce the player is game over.. you can also view the records

5 Years
Discussion Span
Last Post by Lipe Shtogu

Hi ProGee

The following code uses serialization...with this technique u can save any serialized objects of a class holds ur game data.

Imports System.IO
Imports System.Collections.Specialized
Imports System.Runtime.Serialization.Formatters.Binary

<Serialize> _
Public class Example   '--Your class holds game data
' Your Datas
End class

Dim mem As New List(Of Example) '-- Name of the object storing information about ' user also about game setting etc

' For saving use the following

Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveToolStripMenuItem.Click, SaveToolStripButton.Click

            Dim sfd = New SaveFileDialog
            sfd.DefaultExt = ".cbf" '--You can change the format type 
            sfd.Filter = "Pro Gee's (Your) Object Files (*.cbf)|*.cbf"

            If sfd.FileName <> "" Then
                Dim cbobject As New List(Of Object)

               '---You can add whatever obeject you want but the retrieval also has
               'to follow the same sequence

                Dim psf As Stream = File.Create(sfd.FileName)
                Dim serializer As New BinaryFormatter
                serializer.Serialize(psf, cbobject)
            End If
        End If

' For opening the same use the following

Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
            Dim ofd = New OpenFileDialog()
            ofd.DefaultExt = ".cbf"
            ofd.Filter = "Pro Gee's (Your) Object Files (*.cbf)|*.cbf"
            If File.Exists(ofd.FileName) Then
                Dim cbobject As New List(Of Object)
                Dim gsf As Stream = File.OpenRead(ofd.FileName)
                Dim deserializer As New BinaryFormatter
                    cbobject = CType(deserializer.Deserialize(gsf), Object)
                Catch ex As Exception
                    MessageBox.Show("Unable to Open !!!", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    Exit Sub
                End Try
                Dim instance1 As List(Of Example) = cbobject(0)
                mem = instance1

               '--If u have more objects call the second object as follows
               ' Dim instance2 As Integer = cbobject(1)
               ' ends = instance2
                'MessageBox.Show("File does not exist!")
            End If
        End If
    End Sub

The main keyword is <Serialize>....
Display the result using your own strategy ...

Using this technique u can have your own file extension....also saving the
records itself not enough, u can use the same to save the game settings etc.,


Edited by ~s.o.s~: Added code tags, learn to use them.


First of all you need a mododule (connection between Vb and ms acess)
then this code is for the save button

Call DB 'The Database
With ar
.Open "Select *From tblUsers", strConek, adOpenStatic, adLockOptimistic
!idd = txtUserID
!Name = txxName
!Surname = txtSurname
!Company = txtCompany
!address = txtAddress
!phone = txtphone
!email = txtMail
!Notes = txtNotes
MsgBox "the information saved with sucess.", vbInformation, "Save!"
End With

End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.