|
The only reason that would happen is if you send a null reference (Nothing in VB) to the method.
You are not initialising the hex variable to a string, so it's Nothing from the start, but eventhough that is not recommended (you get a compiler warning about it), it doesn't cause an exception.
Alos, you should use a StringBuilder to build a string. Using the &= operator in a loop scales very badly.
|
|
|
|
|
Can I make my combobox object only for read
|
|
|
|
|
What do yo mean by readonly? Is the user still able to open the list in combo but not able to select from that list?
|
|
|
|
|
I mean that don't write the text area in combobox but I understand how make that -Combobox-dropdownstyle make dropdownlist thanks
|
|
|
|
|
Yes exactly, that style is used to prevent the user to write to the text area.
|
|
|
|
|
Thank Mika in Your answers
|
|
|
|
|
Who of you VB.NET programmer is using linq and if you are could you share some things that you are using it for in the "real world".
Humble Programmer
|
|
|
|
|
|
Thanks for the reply, I know this may sound dumb but I am still unsure of how this can help me. We write software that uses a mySQL backend with stored procedures and some dynamically generated SQL. Can you give me a instance when it would be beneficial to use linq. The application just retrieves and displays info and lets the users update that info. One things that I thought sounded close to the explanation I have had of the use of linq, is to read a dataset in memory currently we are reading the xml file each time we need a setting for the app(I know that is very slow) this is a piece of code I did not write but have been wanting to find a better solution to for a while now. Another thought is it more efficient to read a large list of data in from the database and then search through with linq of write a huge ugly SQL statement to only get the rows I am needing.
Humble Programmer
|
|
|
|
|
I am creating a simple web browser in vb that I will be using to access a secured site. The browser works fine, but if I click on a link within the secured site the new window that pops up asks me to log in again, instead of automatically displaying the content. What do I need to do to tell the web browser control to pass my credintials on to any new windows that open?
|
|
|
|
|
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
|
|
|
|