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

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"
            sfd.ShowDialog()

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

                cbobject.Add(mem)
               '---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)
                psf.Close()
            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"
            ofd.ShowDialog()
            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
                Try
                    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
              
            Else
                '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.,


Rgrds
Sam

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
.AddNew
!idd = txtUserID
!Name = txxName
!Surname = txtSurname
!Company = txtCompany
!address = txtAddress
!phone = txtphone
!email = txtMail
!Notes = txtNotes
.Update
MsgBox "the information saved with sucess.", vbInformation, "Save!"
End With

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.