Hello,
I need help saving data into an access 2007 database from a program created in vb 2008.
I am making a basic "game" that allows you to move a "robot" up,down,left, right and will save the movements/positions into an access 2007 database. I already have the basic movement created with buttons that will change the robot location (the movements are done though a separate class).
The main issue I have is creating the connection and saving the movements.
the access database is located here, no password and I have already added it as a datasource in vb 2008:
c:\hw3robot.accdb
and has Fields: direction (char(1), x (decimal), y (decimal), TimeStamp (datetime)
I have tried some examples for connectionstring.com and other places and I get a variety of different errors.
If anyone has a good place to start, i would appreciate it.
The code is pretty long already but here is a snippet for the up button (btnup):
If I can get it to save data into the above fields, I should just be able to edit it for the rest of the buttons.
Form 1 code:
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'centers robots
Dim centerx As Integer
centerx = (Panel1.Width - picRobotRed.Width) / 2
Dim centery As Integer
centery = (Panel1.Height - picRobotRed.Height) / 2
picRobotRed.Location = New Point(centerx, centery)
picRobotBlue.Location = New Point(centerx, centery + 20)
'Helps with focus/arrow keys
radGo1.Checked = True
radRobotRed.Checked = True
btnDown.Focus()
End Sub
Dim Robot As New Robot
Dim currentx As Integer
Dim currenty As Integer
Dim amountmove As Integer
Private Sub btnup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnup.Click
If radRobotRed.Checked = True Then
picRobotRed.Text = "5"
If radGo1.Checked = True Then
picRobotRed.Location = Robot.redup
ElseIf radGo10.Checked = True Then
picRobotRed.Location = Robot.redup10
End If
ElseIf radRobotBlue.Checked = True Then
picRobotBlue.Text = "5"
If radGo1.Checked = True Then
picRobotBlue.Location = Robot.blueup
ElseIf radGo10.Checked = True Then
picRobotBlue.Location = Robot.blueup10
End If
End If
currentx = picRobotRed.Location.X
currenty = picRobotRed.Location.Y
lblRedLocation.Text = currentx & "," & currenty
End Sub
Robot Class (for movement)
Public Function redup() As Point
Dim loc As Point
If Form1.picRobotRed.Location.Y - 1 < 0 Then
RaiseEvent RangeLimit()
loc = New Point(Form1.picRobotRed.Location.X, Form1.picRobotRed.Location.Y)
Else
loc = New Point(Form1.picRobotRed.Location.X, Form1.picRobotRed.Location.Y - 1)
Form1.picRobotRed.Location = loc
End If
Return loc
End Function
#End Region
Thanks,
Shawn