|
Make sure the target of the link is set correctly. Probably needs to be _self.
|
|
|
|
|
Hi,
I am trying to access a Windows Xbox 360 from within VB.net 2008, I can find plenty of examples using C sharp (and the controller works fine) but nothing using VB.
Could anyone please show me how to capture any reading from an Xbox 360 controller and display it in say a label. I should be able to do the rest my self.
I do not want to write games as yet, I want to control ordiary windows form applications with xbox 360 controller in addition to KB, Mouse and Joystick. So hopefully won't need XNA.
Thanks,
Steve
|
|
|
|
|
Exactly the same way you do it in C#. Just use an online code conversion utility to help you convert the code.
|
|
|
|
|
What a good suggestion, I didn't know they existed. I used-
http://www.developerfusion.com/tools/convert/csharp-to-vb/
and came up with this
Imports Microsoft.Xna.Framework.Input
'references
'goto project-add references
'add all xna from .net tab
'go to project - properties -references tag
'under imported namespace check
'Microsoft.xna
'Microsoft.XnaFramework
'Microsoft.XnaFramework.Content
'Microsoft.XnaFramework.GameServices
'useful site for code conversion C to vb
'http://www.developerfusion.com/tools/convert/csharp-to-vb/
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim currentState As GamePadState = GamePad.GetState(PlayerIndex.One)
If currentState.IsConnected Then
If currentState.Buttons.A = ButtonState.Pressed Then
Label2.Text = "pressed"
Else
Label2.Text = "Released"
End If
Label1.Text = currentState.ThumbSticks.Left.X.ToString()
Else
MessageBox.Show("Controller is not connected")
Timer1.Enabled = False
End If
End Sub
End Class
Hope this helps someone.
Steve
|
|
|
|
|
(I know you wrote this a long time ago.)
I can't get your code to work for some reason. The labels don't change when I hit buttons on the controller.
|
|
|
|
|
Hi,
Have you followed all instructions in green
ie.
Imports Microsoft.Xna.Framework.Input
'references
'goto project-add references
'add all xna from .net tab
'go to project - properties -references tag
'under imported namespace check
'Microsoft.xna
'Microsoft.XnaFramework
'Microsoft.XnaFramework.Content
'Microsoft.XnaFramework.GameServices
Are you getting any error ,essages?
Does it compile OK?
If all of above is ok is timer enabled, if not it won't do anything.
Steve
|
|
|
|
|
My timer wasn't enabled so it wasn't even running. Silly error.
Thanks for the quick response.
|
|
|
|
|
I am having a very strange problem. I have datagrids to view DB entries. The code I have included shows the initialization of the grid and the deletion sub. The first one works fine, so I copied the code and altered it slightly to work for a different form, but it shouldn't have made any difference. When I try to use the second one (Class TimeOff) it gives me:
An unhandled exception has occurred in your application......
....
Column 'DI' does not belong to table TimeOff.
All of the mapping names correspond correctly with the DB.
I am at wit's end!
Am willing to send entire files if I didn't post enough. Please help:
The one that does work...
Imports System.Data.OleDb
Imports System.Configuration
Public Class EmployeeView
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Const SELECT_STRING As String = "SELECT * FROM tblEmployees ORDER BY FirstName, LastName, Title, Region, WorkPhone"
Private Const CONNECT_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=data.mdb "
Private manipulatedrow As Integer
' The DataSet that holds the data.
Public Shared m_DataSet As DataSet
Public myCaller As Calendar
#Region "Employee View Form Load"
Private Sub EmployeeView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim data_adapter As OleDbDataAdapter
Dim oledbcommand As OleDbCommand
' Create the SqlDataAdapter.
data_adapter = New OleDbDataAdapter(SELECT_STRING, CONNECT_STRING)
' Map Table to Employees.
data_adapter.TableMappings.Add("Table", "Employees")
' Fill the DataSet.
m_DataSet = New DataSet
data_adapter.Fill(m_DataSet)
'Create a Grid Table Style. Map it to the "Employees" Table.
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "Employees"
aGridTableStyle.AlternatingBackColor = Color.LightYellow
'
' Create GridColumnStyle objects for the grid columns
'
Dim col_ID As New DataGridTextBoxColumn
Dim col_FirstName As New DataGridTextBoxColumn
Dim col_LastName As New DataGridTextBoxColumn
Dim col_Title As New DataGridTextBoxColumn
Dim col_Region As New DataGridTextBoxColumn
Dim col_WorkPhone As New DataGridTextBoxColumn
Dim col_HomePhone As New DataGridTextBoxColumn
With col_ID
.MappingName = "ID"
.HeaderText = "ID"
.Width = 0
End With
With col_FirstName
.MappingName = "FirstName"
.HeaderText = "First Name"
.Width = 75
End With
With col_LastName
.MappingName = "LastName"
.HeaderText = "Last Name"
.Width = 75
.NullText = ""
End With
With col_Title
.MappingName = "Title"
.HeaderText = "Title"
.Width = 100
End With
With col_Region
.MappingName = "Region"
.HeaderText = "Region"
.Width = 46
End With
With col_WorkPhone
.MappingName = "WorkPhone"
.HeaderText = "Work Phone"
.Width = 75
End With
With col_HomePhone
.MappingName = "HomePhone"
.HeaderText = "Home Phone"
.Width = 0
End With
'Add the styles to the table
With aGridTableStyle.GridColumnStyles
.Add(col_ID)
.Add(col_FirstName)
.Add(col_LastName)
.Add(col_Title)
.Add(col_Region)
.Add(col_WorkPhone)
.Add(col_HomePhone)
End With
'Add the GridColumnStyles to the aGridTableStyle.
DataGrid1.TableStyles.Add(aGridTableStyle)
'Bind the DataGrid control to the Employees DataTable.
DataGrid1.SetDataBinding(m_DataSet, "Employees")
DataGrid1.Refresh()
Dim c As DataGridTextBoxColumn
For Each c In Me.DataGrid1.TableStyles(0).GridColumnStyles
c.TextBox.ContextMenu = ContextMenu1
Next
End Sub
#End Region
Private Sub ctxDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ctxDelete.Click, btnDelete.Click
Dim choice As MsgBoxResult
choice = MsgBox("Are you sure you want to delete " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 1) & " " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) & " from the database?", MsgBoxStyle.YesNo, "Delete Employee?")
If choice = MsgBoxResult.Yes Then
Dim data_adapter As OleDbDataAdapter
Dim oledbcommand As OleDbCommand
Dim oledbconnection As OleDbConnection
Dim strSQL As String
oledbconnection = New OleDbConnection(CONNECT_STRING)
oledbcommand = New OleDbCommand
oledbcommand.Connection = oledbconnection
oledbcommand.Connection.Open()
strSQL = "Delete from tblEmployees where ID = " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 0)
oledbcommand.CommandText = strSQL
Try
oledbcommand.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox(ex.Message)
End Try
oledbcommand.Connection.Close()
data_adapter = New OleDbDataAdapter(SELECT_STRING, CONNECT_STRING)
' Map Table to Employees.
data_adapter.TableMappings.Add("Table", "Employees")
' Fill the DataSet.
m_DataSet = New DataSet
data_adapter.Fill(m_DataSet)
' Bind the DataGrid control to the Employees DataTable.
DataGrid1.SetDataBinding(m_DataSet, "Employees")
End If
DataGrid1.Refresh()
End Sub
End Class
...and the one that doesn't. Any ideas?
Imports System.Data.OleDb
Imports System.Configuration
Public Class TimeOff
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Const SELECT_STRING As String = "SELECT * FROM tblTimeOff ORDER BY TOEmployee, Start"
Private Const CONNECT_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=data.mdb"
Public myCaller As Calendar
Public Shared TO_DataSet As DataSet
Private Sub TimeOff_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim data_adapter2 As OleDbDataAdapter
Dim oledbcommand2 As OleDbCommand
' Create the SqlDataAdapter.
data_adapter2 = New OleDbDataAdapter(SELECT_STRING, CONNECT_STRING)
' Map Table to Employees.
data_adapter2.TableMappings.Add("Table", "TimeOff")
' Fill the DataSet.
TO_DataSet = New DataSet
data_adapter2.Fill(TO_DataSet)
'Create a Grid Table Style. Map it to the "Employees" Table.
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "TimeOff"
'
' Create GridColumnStyle objects for the grid columns
'
Dim col_DI As New DataGridTextBoxColumn
Dim col_Employee As New DataGridTextBoxColumn
Dim col_StartDate As New DataGridTextBoxColumn
Dim col_EndDate As New DataGridTextBoxColumn
With col_DI
.MappingName = "DI"
.HeaderText = "ID"
.Width = 20
End With
With col_Employee
.MappingName = "TOEmployee"
.HeaderText = "Employee"
.Width = 100
.Alignment = HorizontalAlignment.Center
End With
With col_StartDate
.MappingName = "Start"
.HeaderText = "Start Date"
.Width = 80
.Alignment = HorizontalAlignment.Center
End With
With col_EndDate
.MappingName = "End"
.HeaderText = "End Date"
.Width = 80
.Alignment = HorizontalAlignment.Center
End With
'Add the styles to the table
With aGridTableStyle.GridColumnStyles
.Add(col_DI) '0
.Add(col_Employee) '1
.Add(col_StartDate) '2
.Add(col_EndDate) '3
End With
'Add the GridColumnStyles to the aGridTableStyle.
DataGrid1.TableStyles.Add(aGridTableStyle)
'Bind the DataGrid control to the Employees DataTable.
Try
DataGrid1.SetDataBinding(TO_DataSet, "TimeOff")
Catch ex As Exception
MsgBox(ex)
End Try
DataGrid1.Refresh()
Dim c As DataGridTextBoxColumn
For Each c In Me.DataGrid1.TableStyles(0).GridColumnStyles
c.TextBox.ContextMenu = ContextMenu1
Next
End Sub
Private Sub mnuDelEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDelEntry.Click
Dim choice As MsgBoxResult
Try
choice = MsgBox("Are you sure you want to delete " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 1) & ": " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) & "-" & DataGrid1.Item(DataGrid1.CurrentRowIndex, 3) & " from the database?", MsgBoxStyle.YesNo, "Delete Employee?")
If choice = MsgBoxResult.Yes Then
Dim data_adapter2 As OleDbDataAdapter
Dim oledbcommand2 As OleDbCommand
Dim oledbconnection As OleDbConnection
Dim strSQL As String
oledbconnection = New OleDbConnection(CONNECT_STRING)
oledbcommand2 = New OleDbCommand
oledbcommand2.Connection = oledbconnection
oledbcommand2.Connection.Open()
strSQL = "DELETE FROM tblTimeOff WHERE DI = " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 0)
oledbcommand2.CommandText = strSQL
Try
oledbcommand2.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox(ex.Message)
End Try
oledbcommand2.Connection.Close()
data_adapter2 = New OleDbDataAdapter(SELECT_STRING, CONNECT_STRING)
' Map Table to Employees.
data_adapter2.TableMappings.Add("Table", "TimeOff")
' Fill the DataSet.
TO_DataSet = New DataSet
data_adapter2.Fill(TO_DataSet)
' Bind the DataGrid control to the Employees DataTable.
DataGrid1.SetDataBinding(TO_DataSet, "TimeOff")
End If
DataGrid1.Refresh()
Catch bigEx As Exception
MsgBox("There is no data to delete.", MsgBoxStyle.Exclamation, "No Data")
End Try
End Sub
End Class
|
|
|
|
|
Since you are selecting from diff tables, are you sure that column exists in the table from the 2nd select?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Positive. I can get every column to display. The error occurs on the line near the end in the delete sub:
DataGrid1.SetDataBinding(TO_DataSet, "TableMapTimeOff")
It takes the data out of the database, and removes it from the grid, but throws the exception every time.
|
|
|
|
|
I have a doubt regarding MS Access Database. I have two MS database with password protected. Now I want to join one inner join (example table a from first database, table b from second database) with the table how can i do it. When I was trying it's telling that not a valid password.
Problem both database are password protected. How I over come from the issue. Kindly do the favor.
|
|
|
|
|
You can access tables from another MS-Access databasae by using Linked Tables.
Go to the File Menu, Get External data, Link Tables. Once you have linked the "remote" tables you can use them in your query builder just like any other table. This should not be a problem if the database has a password or not.
|
|
|
|
|
Hello,
In VB.NET,
How to get the Owner / Creator of a document/file ?
I am doing a tool for my company which scan all the files with specified type (.doc, .xls,etc...) and store all information in a SQLite database.
I want to search the files with criteria as keywords, modification date, creation date, OWNER of the file.
How to ?
Best regards
|
|
|
|
|
Try this
Dim ofile As New System.IO.FileInfo("D:\sam.txt")
If ofile.Exists = True Then
Label1.Text = "Create Time: " & ofile.CreationTime & vbNewLine
Label1.Text = Label1.Text & "Length: " & ofile.Length.ToString + " bytes" & vbNewLine
Label1.Text = Label1.Text & "Last Access Date: " & ofile.LastAccessTime & vbNewLine
Label1.Text = Label1.Text & "Read only: " & ofile.IsReadOnly & vbNewLine
Label1.Text = Label1.Text & "Last Write Date: " & ofile.LastWriteTime & vbNewLine
Else
Label1.Text = "File Not Found"
End If
|
|
|
|
|
Thanks,
but the AIM of the question is about the OWNER (security point of view) which has created or modified the file....
Best regards
|
|
|
|
|
Use ManagementBaseObject class. This can help you to get the owner details.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
Hello All,
I use VB .Net forms and i have a requirement as follows.
In a form, a click of a button should be automated through windows schduler and one more button would be placed in the form for other activities.
Basically, in a single exe we would be performing two activiites, one as a daily routine through windows scheduler (one button) and other is a manual process (Button that would be visible to the end users)
Hope i am not confusing
Let me know how to take this forward.
Thanks.
|
|
|
|
|
I doubt windows scheduler can click any button at all. Why not write it as a console app and use command line parameters?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
The Scheduler cannot click buttons. Your code has to be rewritten to accept command line parameters, which the Schedular CAN use, to tell your app what to do.
Also, don't put actual work methods in the button Click handlers. Move that code to other methods that can be called from your command line handler or from the Click handlers or from just about anywhere else you're going to need to cal that code from.
|
|
|
|
|
Ditto to Dave. When the app is starting up, check the command line args that are being sent in. Parse the args and then run the appropriate methods.
This is easy to test. Go to the project --> debug tab. Enter your args in the command line args textbox.
Cheers.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Downloads\user.mdb")
Dim cmd As OleDb.OleDbCommand
Private Sub LogOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LogOn.Click
Dim sql As String
sql = "SELECT Username,Password FROM user WHERE Username='" & TextBox1.Text & "' AND Password='" & TextBox2.Text & "'"
cmd = New OleDb.OleDbCommand(sql, con)
con.Open()
Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader
Try
Catch ex As InvalidOperationException
MsgBox(ex.Message)
End Try
Try
If dr.Read = False Then
MessageBox.Show("Logon failed...")
Else
MessageBox.Show("Logon successfully...")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
End Sub
End Class
this is my code
i get an error msg stating OleDb Exception was unhandled and syntax error in FROM clause
can sombody fix this issue??
thanks
|
|
|
|
|
vijay2482 wrote: sql = "SELECT Username,Password FROM user WHERE Username='" & TextBox1.Text & "' AND Password='" & TextBox2.Text & "'"
vijay2482 wrote: syntax error in FROM clause
Use a stored procedure
I are troll
|
|
|
|
|
i have an MS Access Database table,which i have connected with the VB.net proj
Troubleshooting Exceptions: System.Data.OleDb.OleDbException
An OleDbException exception is generated when a warning or error is returned by an OLE DB data source.
Associated Tips
Verify that you are connecting with valid credentials.
Make sure that the credentials you are supplying are valid. For more information, see OleDbErrorCollection.
Verify that the server name is correct and that the server is running.
Make sure that you are using the correct server name, and that the server can be reached. For more information, see OleDbErrorCollection.
Remarks
This exception is thrown whenever the .NET Framework Data Provider for OLE DB encounters an error generated by the server.
If the severity of the error is too great, the server may close the OleDbConnection. However, the user can reopen the connection and continue.
this is the online help.i am not able to find whats wrong with my code
im not aware of stored procedures...
can u help me out in this coding?
|
|
|
|
|
That's a warning from the integrated security, probably an error in the connectionString. Try this one:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Downloads\user.mdb;User Id=admin;Password=;
vijay2482 wrote: Verify that you are connecting with valid credentials.
It is referring to the credentials in your connection, the one used to connect to the database. You can't perform a "SELECT FROM USER" until you have a database-connection. And you'll need a user-name and a password to do that
The supplied connectionstring feats. the default username and password for MS-Access. From there-on you can implement your own security-system.
I are troll
|
|
|
|
|
I expect your select statement is incorrect, probably with all the embedded quotes. Use either a stored procedure or a parameterised query, or if you must leave yourself open to sql injection attack then print the select statement out and see where its wrong.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|