By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,493 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,493 IT Pros & Developers. It's quick & easy.

Object Reference not set an instance of an object

P: n/a
Hi All,
I am in .NET 2003

I have a form and a toolbar on the form.
When the user clicks on a button on the toolbar I call
the following Sub

I get a crash on the last line: tlbSearch.Buttons(0).Enabled = True
' Enable search

An unhandled exception of type "System.NullreferenceExecption" occured
etc.....
Object Reference not set to an instance of an object

How can this be?, near the stop of the Sub I execute:
tlbSearch.Buttons(0).Enabled = False ' Disable search
with no problem. What could have happended to the toolbar object?

I am new to objects, I come from a VB background.

Thanks in Advance,

Larry

'--------------------------------------------------------------------------------------

Public Sub DoTheSearch()

Dim intDX As Integer
Dim Structures As New clsStructures
Dim clsMiscProjMulti As New
MiscProjectMultiTable_Handler(Permissions.Connecti onString)
Dim SearchDataReader As SqlClient.SqlDataReader
Dim blnWhere As Boolean = False
Dim TheRetrievalType As RetrievalType
Dim NotFoundMsg As String

Dim strSelectString = "SELECT ProjectID,Reg,Fee,Title," & _
"MiscFeeTypeID," & _
"Fee, Quarter,
[Year],MiscProjectStatusID," & _

"StatusDate,Miscellaneous_Project.Account_ID,Final izedDate," & _
"ContactEmployeeID,ContactEmail," & _
"Unex_Employee.EmpFirstName + ' ' +
Unex_Employee.EmpLastName As EmpName," & _
"Account.Exp_Account + '-' +
Account.Cost_Center As ExpAcctCC " & _
"FROM Miscellaneous_Project " & _
"Left Outer Join Unex_Employee " & _
"On
Miscellaneous_Project.ContactEmployeeID = Unex_Employee.EmployeeID " & _
"Left Outer Join Account " & _
"On Miscellaneous_Project.Account_ID
= Account.Account_ID "
'----------

Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()

tlbSearch.Buttons(0).Enabled = False ' Disable (this is ok)
menuSearch.Enabled = False

tlbSearch.Buttons(1).Enabled = True ' Enable
stop
menuStop.Enabled = True

tlbSearch.Buttons(2).Enabled = False '
Disable print
menuPrint.Enabled = False

tlbSearch.Buttons(4).Enabled = False '
Disable the create new button.
menuCreateNew.Enabled = False '
Disable the create new menu item.

tlbSearch.Buttons(5).Enabled = False '
Disable Edit
menuEdit.Enabled = False
stsSearch.text = "Searching....."

' Clear the grid.

C1FGResults.RowSel = -1
C1FGResults.ColSel = -1

If C1FGResults.Rows.Count > 1 Then

For intDX = (C1FGResults.Rows.Count - 1) To 1 Step -1
C1FGResults().Rows.Remove(intDX)
Next

End If

'-----------------------------------------------

If Me.txtRegProjID.Text = vbNullString Then

' look for projects using the type, Status and Deparatment
' build the query string, using the parameters.

If c1cboFeeType.SelectedIndex > 0 Then
strSelectString = strSelectString & " Where
Miscellaneous_Project.MiscFeeTypeID = " &
Structures.GetComboValue(c1cboFeeType)
blnWhere = True
End If

'----------

If c1cboProjectStatus.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.MiscProjectStatusID = " &
Structures.GetComboValue(c1cboProjectStatus)
End If

'----------

If c1cboDept.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.Account_ID = " & Structures.GetComboValue(c1cboDept)

End If

'----------

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then

While SearchDataReader.Read() = True
Call AddARow(SearchDataReader)
End While
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
MsgBox("Unable to find any projects with the parameters
selected.", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException,
"", True)
End If

Else

' Did the user enter a project Id or a Reg number?

If IsNumeric(Mid(txtRegProjID.Text, 1, 1)) Then
strSelectString = strSelectString & " Where ProjectID = " &
Trim$(txtRegProjID.Text)
TheRetrievalType = RetrievalType.ProjectID
Else
' the user entered a reg number.
strSelectString = strSelectString & " Where Reg = '" &
Trim$(txtRegProjID.Text) & "'"
TheRetrievalType = RetrievalType.RegNumber
End If

' do the read.

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then
SearchDataReader.Read()
Call AddARow(SearchDataReader)
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()

If TheRetrievalType = RetrievalType.ProjectID Then
NotFoundMsg = "Project ID of : " & Trim$(txtRegProjID.Text)
Else
NotFoundMsg = "Reg Number of : " & Trim$(txtRegProjID.Text)
End If

MsgBox("Unable to find a project with a " & NotFoundMsg,
MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If

Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException,
"", True)
End If

End If

'-------------------------------------------------------

Me.Cursor = System.Windows.Forms.Cursors.Default()

tlbSearch.Buttons(0).Enabled = True ' Enable (This crashes)
Mar 24 '06 #1
Share this Question
Share on Google+
6 Replies

P: n/a
vj
I would suggest you first put Option Explicit On, the .vb file and see if
you get any errors in the method, correct them and try.. If you still get
the error , we will take it from there

Vijay

"Larry" <bl***@Blifff.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi All,
I am in .NET 2003

I have a form and a toolbar on the form.
When the user clicks on a button on the toolbar I call
the following Sub

I get a crash on the last line: tlbSearch.Buttons(0).Enabled = True '
Enable search

An unhandled exception of type "System.NullreferenceExecption" occured
etc.....
Object Reference not set to an instance of an object

How can this be?, near the stop of the Sub I execute:
tlbSearch.Buttons(0).Enabled = False ' Disable search
with no problem. What could have happended to the toolbar object?

I am new to objects, I come from a VB background.

Thanks in Advance,

Larry

'--------------------------------------------------------------------------------------

Public Sub DoTheSearch()

Dim intDX As Integer
Dim Structures As New clsStructures
Dim clsMiscProjMulti As New
MiscProjectMultiTable_Handler(Permissions.Connecti onString)
Dim SearchDataReader As SqlClient.SqlDataReader
Dim blnWhere As Boolean = False
Dim TheRetrievalType As RetrievalType
Dim NotFoundMsg As String

Dim strSelectString = "SELECT ProjectID,Reg,Fee,Title," & _
"MiscFeeTypeID," & _
"Fee, Quarter,
[Year],MiscProjectStatusID," & _

"StatusDate,Miscellaneous_Project.Account_ID,Final izedDate," & _
"ContactEmployeeID,ContactEmail," & _
"Unex_Employee.EmpFirstName + ' ' +
Unex_Employee.EmpLastName As EmpName," & _
"Account.Exp_Account + '-' +
Account.Cost_Center As ExpAcctCC " & _
"FROM Miscellaneous_Project " & _
"Left Outer Join Unex_Employee " & _
"On
Miscellaneous_Project.ContactEmployeeID = Unex_Employee.EmployeeID " & _
"Left Outer Join Account " & _
"On Miscellaneous_Project.Account_ID =
Account.Account_ID "
'----------

Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()

tlbSearch.Buttons(0).Enabled = False ' Disable (this is ok)
menuSearch.Enabled = False

tlbSearch.Buttons(1).Enabled = True ' Enable
stop
menuStop.Enabled = True

tlbSearch.Buttons(2).Enabled = False ' Disable
print
menuPrint.Enabled = False

tlbSearch.Buttons(4).Enabled = False ' Disable
the create new button.
menuCreateNew.Enabled = False ' Disable
the create new menu item.

tlbSearch.Buttons(5).Enabled = False ' Disable
Edit
menuEdit.Enabled = False
stsSearch.text = "Searching....."

' Clear the grid.

C1FGResults.RowSel = -1
C1FGResults.ColSel = -1

If C1FGResults.Rows.Count > 1 Then

For intDX = (C1FGResults.Rows.Count - 1) To 1 Step -1
C1FGResults().Rows.Remove(intDX)
Next

End If

'-----------------------------------------------

If Me.txtRegProjID.Text = vbNullString Then

' look for projects using the type, Status and Deparatment
' build the query string, using the parameters.

If c1cboFeeType.SelectedIndex > 0 Then
strSelectString = strSelectString & " Where
Miscellaneous_Project.MiscFeeTypeID = " &
Structures.GetComboValue(c1cboFeeType)
blnWhere = True
End If

'----------

If c1cboProjectStatus.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.MiscProjectStatusID = " &
Structures.GetComboValue(c1cboProjectStatus)
End If

'----------

If c1cboDept.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.Account_ID = " &
Structures.GetComboValue(c1cboDept)

End If

'----------

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then

While SearchDataReader.Read() = True
Call AddARow(SearchDataReader)
End While
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
MsgBox("Unable to find any projects with the parameters
selected.", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException, "",
True)
End If

Else

' Did the user enter a project Id or a Reg number?

If IsNumeric(Mid(txtRegProjID.Text, 1, 1)) Then
strSelectString = strSelectString & " Where ProjectID = " &
Trim$(txtRegProjID.Text)
TheRetrievalType = RetrievalType.ProjectID
Else
' the user entered a reg number.
strSelectString = strSelectString & " Where Reg = '" &
Trim$(txtRegProjID.Text) & "'"
TheRetrievalType = RetrievalType.RegNumber
End If

' do the read.

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then
SearchDataReader.Read()
Call AddARow(SearchDataReader)
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()

If TheRetrievalType = RetrievalType.ProjectID Then
NotFoundMsg = "Project ID of : " & Trim$(txtRegProjID.Text)
Else
NotFoundMsg = "Reg Number of : " & Trim$(txtRegProjID.Text)
End If

MsgBox("Unable to find a project with a " & NotFoundMsg,
MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If

Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException, "",
True)
End If

End If

'-------------------------------------------------------

Me.Cursor = System.Windows.Forms.Cursors.Default()

tlbSearch.Buttons(0).Enabled = True ' Enable (This crashes)

Mar 24 '06 #2

P: n/a
If VB 2003 has Option Strict, turn it on as well. Make the compiler do as
much of the work for you as it can.

Mike Ober.

"vj" <vi********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I would suggest you first put Option Explicit On, the .vb file and see if
you get any errors in the method, correct them and try.. If you still get
the error , we will take it from there

Vijay

"Larry" <bl***@Blifff.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi All,
I am in .NET 2003

I have a form and a toolbar on the form.
When the user clicks on a button on the toolbar I call
the following Sub

I get a crash on the last line: tlbSearch.Buttons(0).Enabled = True '
Enable search

An unhandled exception of type "System.NullreferenceExecption" occured
etc.....
Object Reference not set to an instance of an object

How can this be?, near the stop of the Sub I execute:
tlbSearch.Buttons(0).Enabled = False ' Disable search
with no problem. What could have happended to the toolbar object?

I am new to objects, I come from a VB background.

Thanks in Advance,

Larry

'---------------------------------------------------------------------------
-----------
Public Sub DoTheSearch()

Dim intDX As Integer
Dim Structures As New clsStructures
Dim clsMiscProjMulti As New
MiscProjectMultiTable_Handler(Permissions.Connecti onString)
Dim SearchDataReader As SqlClient.SqlDataReader
Dim blnWhere As Boolean = False
Dim TheRetrievalType As RetrievalType
Dim NotFoundMsg As String

Dim strSelectString = "SELECT ProjectID,Reg,Fee,Title," & _
"MiscFeeTypeID," & _
"Fee, Quarter,
[Year],MiscProjectStatusID," & _

"StatusDate,Miscellaneous_Project.Account_ID,Final izedDate," & _
"ContactEmployeeID,ContactEmail," & _
"Unex_Employee.EmpFirstName + ' ' +
Unex_Employee.EmpLastName As EmpName," & _
"Account.Exp_Account + '-' +
Account.Cost_Center As ExpAcctCC " & _
"FROM Miscellaneous_Project " & _
"Left Outer Join Unex_Employee " & _
"On
Miscellaneous_Project.ContactEmployeeID = Unex_Employee.EmployeeID " & _
"Left Outer Join Account " & _
"On Miscellaneous_Project.Account_ID =
Account.Account_ID "
'----------

Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()

tlbSearch.Buttons(0).Enabled = False ' Disable (this is ok)
menuSearch.Enabled = False

tlbSearch.Buttons(1).Enabled = True ' Enable
stop
menuStop.Enabled = True

tlbSearch.Buttons(2).Enabled = False ' Disable
print
menuPrint.Enabled = False

tlbSearch.Buttons(4).Enabled = False ' Disable
the create new button.
menuCreateNew.Enabled = False ' Disable
the create new menu item.

tlbSearch.Buttons(5).Enabled = False ' Disable
Edit
menuEdit.Enabled = False
stsSearch.text = "Searching....."

' Clear the grid.

C1FGResults.RowSel = -1
C1FGResults.ColSel = -1

If C1FGResults.Rows.Count > 1 Then

For intDX = (C1FGResults.Rows.Count - 1) To 1 Step -1
C1FGResults().Rows.Remove(intDX)
Next

End If

'-----------------------------------------------

If Me.txtRegProjID.Text = vbNullString Then

' look for projects using the type, Status and Deparatment
' build the query string, using the parameters.

If c1cboFeeType.SelectedIndex > 0 Then
strSelectString = strSelectString & " Where
Miscellaneous_Project.MiscFeeTypeID = " &
Structures.GetComboValue(c1cboFeeType)
blnWhere = True
End If

'----------

If c1cboProjectStatus.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.MiscProjectStatusID = " &
Structures.GetComboValue(c1cboProjectStatus)
End If

'----------

If c1cboDept.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.Account_ID = " &
Structures.GetComboValue(c1cboDept)

End If

'----------

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then

While SearchDataReader.Read() = True
Call AddARow(SearchDataReader)
End While
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
MsgBox("Unable to find any projects with the parameters
selected.", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException, "",
True)
End If

Else

' Did the user enter a project Id or a Reg number?

If IsNumeric(Mid(txtRegProjID.Text, 1, 1)) Then
strSelectString = strSelectString & " Where ProjectID = " &
Trim$(txtRegProjID.Text)
TheRetrievalType = RetrievalType.ProjectID
Else
' the user entered a reg number.
strSelectString = strSelectString & " Where Reg = '" &
Trim$(txtRegProjID.Text) & "'"
TheRetrievalType = RetrievalType.RegNumber
End If

' do the read.

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then
SearchDataReader.Read()
Call AddARow(SearchDataReader)
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()

If TheRetrievalType = RetrievalType.ProjectID Then
NotFoundMsg = "Project ID of : " & Trim$(txtRegProjID.Text) Else
NotFoundMsg = "Reg Number of : " & Trim$(txtRegProjID.Text) End If

MsgBox("Unable to find a project with a " & NotFoundMsg,
MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If

Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException, "",
True)
End If

End If

'-------------------------------------------------------

Me.Cursor = System.Windows.Forms.Cursors.Default()

tlbSearch.Buttons(0).Enabled = True ' Enable (This crashes)



Mar 24 '06 #3

P: n/a
Thank You for your input,

I tried Option Strict On,
but I get many errors that I don't believe I can correct,
I am referring to a Component One Flex Grid control,
I get:
"Option Strict On prohibits operands of type object for operator%"
It seems that the Component One Flex Grid Control has a a property
or parameter that is object.

C1.FlexGridBase Item(ByVal Integer, byVal Integer) as object

Larry

Michael D. Ober wrote:
If VB 2003 has Option Strict, turn it on as well. Make the compiler do as
much of the work for you as it can.

Mike Ober.

"vj" <vi********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I would suggest you first put Option Explicit On, the .vb file and see if
you get any errors in the method, correct them and try.. If you still get
the error , we will take it from there

Vijay

"Larry" <bl***@Blifff.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi All,
I am in .NET 2003

I have a form and a toolbar on the form.
When the user clicks on a button on the toolbar I call
the following Sub

I get a crash on the last line: tlbSearch.Buttons(0).Enabled = True '
Enable search

An unhandled exception of type "System.NullreferenceExecption" occured
etc.....
Object Reference not set to an instance of an object

How can this be?, near the stop of the Sub I execute:
tlbSearch.Buttons(0).Enabled = False ' Disable search
with no problem. What could have happended to the toolbar object?

I am new to objects, I come from a VB background.

Thanks in Advance,

Larry

'---------------------------------------------------------------------------
----------- Public Sub DoTheSearch()

Dim intDX As Integer
Dim Structures As New clsStructures
Dim clsMiscProjMulti As New
MiscProjectMultiTable_Handler(Permissions.Connecti onString)
Dim SearchDataReader As SqlClient.SqlDataReader
Dim blnWhere As Boolean = False
Dim TheRetrievalType As RetrievalType
Dim NotFoundMsg As String

Dim strSelectString = "SELECT ProjectID,Reg,Fee,Title," & _
"MiscFeeTypeID," & _
"Fee, Quarter,
[Year],MiscProjectStatusID," & _

"StatusDate,Miscellaneous_Project.Account_ID,Final izedDate," & _
"ContactEmployeeID,ContactEmail," & _
"Unex_Employee.EmpFirstName + ' ' +
Unex_Employee.EmpLastName As EmpName," & _
"Account.Exp_Account + '-' +
Account.Cost_Center As ExpAcctCC " & _
"FROM Miscellaneous_Project " & _
"Left Outer Join Unex_Employee " & _
"On
Miscellaneous_Project.ContactEmployeeID = Unex_Employee.EmployeeID " & _
"Left Outer Join Account " & _
"On Miscellaneous_Project.Account_ID =
Account.Account_ID "
'----------

Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()

tlbSearch.Buttons(0).Enabled = False ' Disable (this is ok)
menuSearch.Enabled = False

tlbSearch.Buttons(1).Enabled = True ' Enable
stop
menuStop.Enabled = True

tlbSearch.Buttons(2).Enabled = False ' Disable
print
menuPrint.Enabled = False

tlbSearch.Buttons(4).Enabled = False ' Disable
the create new button.
menuCreateNew.Enabled = False ' Disable
the create new menu item.

tlbSearch.Buttons(5).Enabled = False ' Disable
Edit
menuEdit.Enabled = False
stsSearch.text = "Searching....."

' Clear the grid.

C1FGResults.RowSel = -1
C1FGResults.ColSel = -1

If C1FGResults.Rows.Count > 1 Then

For intDX = (C1FGResults.Rows.Count - 1) To 1 Step -1
C1FGResults().Rows.Remove(intDX)
Next

End If

'-----------------------------------------------

If Me.txtRegProjID.Text = vbNullString Then

' look for projects using the type, Status and Deparatment
' build the query string, using the parameters.

If c1cboFeeType.SelectedIndex > 0 Then
strSelectString = strSelectString & " Where
Miscellaneous_Project.MiscFeeTypeID = " &
Structures.GetComboValue(c1cboFeeType)
blnWhere = True
End If

'----------

If c1cboProjectStatus.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.MiscProjectStatusID = " &
Structures.GetComboValue(c1cboProjectStatus)
End If

'----------

If c1cboDept.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.Account_ID = " &
Structures.GetComboValue(c1cboDept)

End If

'----------

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then

While SearchDataReader.Read() = True
Call AddARow(SearchDataReader)
End While
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
MsgBox("Unable to find any projects with the parameters
selected.", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException, "",
True)
End If

Else

' Did the user enter a project Id or a Reg number?

If IsNumeric(Mid(txtRegProjID.Text, 1, 1)) Then
strSelectString = strSelectString & " Where ProjectID = " &
Trim$(txtRegProjID.Text)
TheRetrievalType = RetrievalType.ProjectID
Else
' the user entered a reg number.
strSelectString = strSelectString & " Where Reg = '" &
Trim$(txtRegProjID.Text) & "'"
TheRetrievalType = RetrievalType.RegNumber
End If

' do the read.

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then
SearchDataReader.Read()
Call AddARow(SearchDataReader)
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()

If TheRetrievalType = RetrievalType.ProjectID Then
NotFoundMsg = "Project ID of : " & Trim$(txtRegProjID.Text) Else
NotFoundMsg = "Reg Number of : " & Trim$(txtRegProjID.Text) End If

MsgBox("Unable to find a project with a " & NotFoundMsg,
MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If

Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException, "",
True)
End If

End If

'-------------------------------------------------------

Me.Cursor = System.Windows.Forms.Cursors.Default()

tlbSearch.Buttons(0).Enabled = True ' Enable (This crashes)



Mar 24 '06 #4

P: n/a
'Option Strict On' may seem like it is causing problems at the moment. I have
lost a lot of time due to unintended type conversions that VB.NET did without
me knowing. Because of that, I always switch it on.

In this case, the return value is an object. If you know it is in fact a text
that can be converted to an integer, use ctype(<expression>,Integer) to
explicitely perform the conversion.

But really, use 'Option Strict On'!!!

Accidentally, have I told you I think you should use 'Option Strict On'?

Renze.

In article <eJ**************@TK2MSFTNGP11.phx.gbl>, Larry <bl***@Blifff.com>
wrote:
Thank You for your input,

I tried Option Strict On,
but I get many errors that I don't believe I can correct,
I am referring to a Component One Flex Grid control,
I get:
"Option Strict On prohibits operands of type object for operator%"
It seems that the Component One Flex Grid Control has a a property
or parameter that is object.

C1.FlexGridBase Item(ByVal Integer, byVal Integer) as object

Larry

Mar 24 '06 #5

P: n/a
Larry,

Are you sure that you have typed that correct?

Cor

"Larry" <bl***@Blifff.com> schreef in bericht
news:eJ**************@TK2MSFTNGP11.phx.gbl...
Thank You for your input,

I tried Option Strict On,
but I get many errors that I don't believe I can correct,
I am referring to a Component One Flex Grid control,
I get:
"Option Strict On prohibits operands of type object for operator%"
It seems that the Component One Flex Grid Control has a a property
or parameter that is object.

C1.FlexGridBase Item(ByVal Integer, byVal Integer) as object

Larry

Michael D. Ober wrote:
If VB 2003 has Option Strict, turn it on as well. Make the compiler do
as
much of the work for you as it can.

Mike Ober.

"vj" <vi********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I would suggest you first put Option Explicit On, the .vb file and see
if
you get any errors in the method, correct them and try.. If you still
get
the error , we will take it from there

Vijay

"Larry" <bl***@Blifff.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi All,
I am in .NET 2003

I have a form and a toolbar on the form.
When the user clicks on a button on the toolbar I call
the following Sub

I get a crash on the last line: tlbSearch.Buttons(0).Enabled = True '
Enable search

An unhandled exception of type "System.NullreferenceExecption" occured
etc.....
Object Reference not set to an instance of an object

How can this be?, near the stop of the Sub I execute:
tlbSearch.Buttons(0).Enabled = False ' Disable search
with no problem. What could have happended to the toolbar object?

I am new to objects, I come from a VB background.

Thanks in Advance,

Larry

'---------------------------------------------------------------------------
-----------
Public Sub DoTheSearch()

Dim intDX As Integer
Dim Structures As New clsStructures
Dim clsMiscProjMulti As New
MiscProjectMultiTable_Handler(Permissions.Connecti onString)
Dim SearchDataReader As SqlClient.SqlDataReader
Dim blnWhere As Boolean = False
Dim TheRetrievalType As RetrievalType
Dim NotFoundMsg As String

Dim strSelectString = "SELECT ProjectID,Reg,Fee,Title," & _
"MiscFeeTypeID," & _
"Fee, Quarter,
[Year],MiscProjectStatusID," & _

"StatusDate,Miscellaneous_Project.Account_ID,Final izedDate," & _
"ContactEmployeeID,ContactEmail," & _
"Unex_Employee.EmpFirstName + ' ' +
Unex_Employee.EmpLastName As EmpName," & _
"Account.Exp_Account + '-' +
Account.Cost_Center As ExpAcctCC " & _
"FROM Miscellaneous_Project " & _
"Left Outer Join Unex_Employee " & _
"On
Miscellaneous_Project.ContactEmployeeID = Unex_Employee.EmployeeID " &
_
"Left Outer Join Account " & _
"On Miscellaneous_Project.Account_ID
=
Account.Account_ID "
'----------

Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()

tlbSearch.Buttons(0).Enabled = False ' Disable (this is ok)
menuSearch.Enabled = False

tlbSearch.Buttons(1).Enabled = True ' Enable
stop
menuStop.Enabled = True

tlbSearch.Buttons(2).Enabled = False '
Disable
print
menuPrint.Enabled = False

tlbSearch.Buttons(4).Enabled = False '
Disable
the create new button.
menuCreateNew.Enabled = False '
Disable
the create new menu item.

tlbSearch.Buttons(5).Enabled = False '
Disable
Edit
menuEdit.Enabled = False
stsSearch.text = "Searching....."

' Clear the grid.

C1FGResults.RowSel = -1
C1FGResults.ColSel = -1

If C1FGResults.Rows.Count > 1 Then

For intDX = (C1FGResults.Rows.Count - 1) To 1 Step -1
C1FGResults().Rows.Remove(intDX)
Next

End If

'-----------------------------------------------

If Me.txtRegProjID.Text = vbNullString Then

' look for projects using the type, Status and Deparatment
' build the query string, using the parameters.

If c1cboFeeType.SelectedIndex > 0 Then
strSelectString = strSelectString & " Where
Miscellaneous_Project.MiscFeeTypeID = " &
Structures.GetComboValue(c1cboFeeType)
blnWhere = True
End If

'----------

If c1cboProjectStatus.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.MiscProjectStatusID = " &
Structures.GetComboValue(c1cboProjectStatus)
End If

'----------

If c1cboDept.SelectedIndex > 0 Then

If blnWhere = False Then
strSelectString = strSelectString & " Where "
blnWhere = True
Else
strSelectString = strSelectString & " And "
End If

strSelectString = strSelectString &
"Miscellaneous_Project.Account_ID = " &
Structures.GetComboValue(c1cboDept)

End If

'----------

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then

While SearchDataReader.Read() = True
Call AddARow(SearchDataReader)
End While
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
MsgBox("Unable to find any projects with the parameters
selected.", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException,
"",
True)
End If

Else

' Did the user enter a project Id or a Reg number?

If IsNumeric(Mid(txtRegProjID.Text, 1, 1)) Then
strSelectString = strSelectString & " Where ProjectID = " &
Trim$(txtRegProjID.Text)
TheRetrievalType = RetrievalType.ProjectID
Else
' the user entered a reg number.
strSelectString = strSelectString & " Where Reg = '" &
Trim$(txtRegProjID.Text) & "'"
TheRetrievalType = RetrievalType.RegNumber
End If

' do the read.

If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
SearchDataReader) = True Then

' No errors, did we find any records?

If SearchDataReader.HasRows = True Then
SearchDataReader.Read()
Call AddARow(SearchDataReader)
Else
Me.Cursor = System.Windows.Forms.Cursors.Default()

If TheRetrievalType = RetrievalType.ProjectID Then
NotFoundMsg = "Project ID of : " &

Trim$(txtRegProjID.Text)
Else
NotFoundMsg = "Reg Number of : " &

Trim$(txtRegProjID.Text)
End If

MsgBox("Unable to find a project with a " & NotFoundMsg,
MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
End If

Else
Me.Cursor = System.Windows.Forms.Cursors.Default()
Dim err As New errorHandler(clsMiscProjMulti.lastException,
"",
True)
End If

End If

'-------------------------------------------------------

Me.Cursor = System.Windows.Forms.Cursors.Default()

tlbSearch.Buttons(0).Enabled = True ' Enable (This crashes)



Mar 25 '06 #6

P: n/a
Thank You for your help.
I found out what it was, I was calling a proc
that did something that caused the form to be unloaded (closed)
and that caused the toolbar buttons collection to not exist.

Thanks again,
Larry

Cor Ligthert [MVP] wrote:
Larry,

Are you sure that you have typed that correct?

Cor

"Larry" <bl***@Blifff.com> schreef in bericht
news:eJ**************@TK2MSFTNGP11.phx.gbl...
Thank You for your input,

I tried Option Strict On,
but I get many errors that I don't believe I can correct,
I am referring to a Component One Flex Grid control,
I get:
"Option Strict On prohibits operands of type object for operator%"
It seems that the Component One Flex Grid Control has a a property
or parameter that is object.

C1.FlexGridBase Item(ByVal Integer, byVal Integer) as object

Larry

Michael D. Ober wrote:
If VB 2003 has Option Strict, turn it on as well. Make the compiler do
as
much of the work for you as it can.

Mike Ober.

"vj" <vi********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I would suggest you first put Option Explicit On, the .vb file and see
if
you get any errors in the method, correct them and try.. If you still
get
the error , we will take it from there

Vijay

"Larry" <bl***@Blifff.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am in .NET 2003
>
> I have a form and a toolbar on the form.
> When the user clicks on a button on the toolbar I call
> the following Sub
>
> I get a crash on the last line: tlbSearch.Buttons(0).Enabled = True '
> Enable search
>
> An unhandled exception of type "System.NullreferenceExecption" occured
> etc.....
> Object Reference not set to an instance of an object
>
> How can this be?, near the stop of the Sub I execute:
> tlbSearch.Buttons(0).Enabled = False ' Disable search
> with no problem. What could have happended to the toolbar object?
>
> I am new to objects, I come from a VB background.
>
> Thanks in Advance,
>
> Larry
>
>
'---------------------------------------------------------------------------
-----------
> Public Sub DoTheSearch()
>
> Dim intDX As Integer
> Dim Structures As New clsStructures
> Dim clsMiscProjMulti As New
> MiscProjectMultiTable_Handler(Permissions.Connecti onString)
> Dim SearchDataReader As SqlClient.SqlDataReader
> Dim blnWhere As Boolean = False
> Dim TheRetrievalType As RetrievalType
> Dim NotFoundMsg As String
>
> Dim strSelectString = "SELECT ProjectID,Reg,Fee,Title," & _
> "MiscFeeTypeID," & _
> "Fee, Quarter,
> [Year],MiscProjectStatusID," & _
>
> "StatusDate,Miscellaneous_Project.Account_ID,Final izedDate," & _
> "ContactEmployeeID,ContactEmail," & _
> "Unex_Employee.EmpFirstName + ' ' +
> Unex_Employee.EmpLastName As EmpName," & _
> "Account.Exp_Account + '-' +
> Account.Cost_Center As ExpAcctCC " & _
> "FROM Miscellaneous_Project " & _
> "Left Outer Join Unex_Employee " & _
> "On
> Miscellaneous_Project.ContactEmployeeID = Unex_Employee.EmployeeID " &
> _
> "Left Outer Join Account " & _
> "On Miscellaneous_Project.Account_ID
> =
> Account.Account_ID "
> '----------
>
> Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()
>
> tlbSearch.Buttons(0).Enabled = False ' Disable (this is ok)
> menuSearch.Enabled = False
>
> tlbSearch.Buttons(1).Enabled = True ' Enable
> stop
> menuStop.Enabled = True
>
> tlbSearch.Buttons(2).Enabled = False '
> Disable
> print
> menuPrint.Enabled = False
>
> tlbSearch.Buttons(4).Enabled = False '
> Disable
> the create new button.
> menuCreateNew.Enabled = False '
> Disable
> the create new menu item.
>
> tlbSearch.Buttons(5).Enabled = False '
> Disable
> Edit
> menuEdit.Enabled = False
> stsSearch.text = "Searching....."
>
> ' Clear the grid.
>
> C1FGResults.RowSel = -1
> C1FGResults.ColSel = -1
>
> If C1FGResults.Rows.Count > 1 Then
>
> For intDX = (C1FGResults.Rows.Count - 1) To 1 Step -1
> C1FGResults().Rows.Remove(intDX)
> Next
>
> End If
>
> '-----------------------------------------------
>
> If Me.txtRegProjID.Text = vbNullString Then
>
> ' look for projects using the type, Status and Deparatment
> ' build the query string, using the parameters.
>
> If c1cboFeeType.SelectedIndex > 0 Then
> strSelectString = strSelectString & " Where
> Miscellaneous_Project.MiscFeeTypeID = " &
> Structures.GetComboValue(c1cboFeeType)
> blnWhere = True
> End If
>
> '----------
>
> If c1cboProjectStatus.SelectedIndex > 0 Then
>
> If blnWhere = False Then
> strSelectString = strSelectString & " Where "
> blnWhere = True
> Else
> strSelectString = strSelectString & " And "
> End If
>
> strSelectString = strSelectString &
> "Miscellaneous_Project.MiscProjectStatusID = " &
> Structures.GetComboValue(c1cboProjectStatus)
> End If
>
> '----------
>
> If c1cboDept.SelectedIndex > 0 Then
>
> If blnWhere = False Then
> strSelectString = strSelectString & " Where "
> blnWhere = True
> Else
> strSelectString = strSelectString & " And "
> End If
>
> strSelectString = strSelectString &
> "Miscellaneous_Project.Account_ID = " &
> Structures.GetComboValue(c1cboDept)
>
> End If
>
> '----------
>
> If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
> SearchDataReader) = True Then
>
> ' No errors, did we find any records?
>
> If SearchDataReader.HasRows = True Then
>
> While SearchDataReader.Read() = True
> Call AddARow(SearchDataReader)
> End While
> Else
> Me.Cursor = System.Windows.Forms.Cursors.Default()
> MsgBox("Unable to find any projects with the parameters
> selected.", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
> End If
> Else
> Me.Cursor = System.Windows.Forms.Cursors.Default()
> Dim err As New errorHandler(clsMiscProjMulti.lastException,
> "",
> True)
> End If
>
> Else
>
> ' Did the user enter a project Id or a Reg number?
>
> If IsNumeric(Mid(txtRegProjID.Text, 1, 1)) Then
> strSelectString = strSelectString & " Where ProjectID = " &
> Trim$(txtRegProjID.Text)
> TheRetrievalType = RetrievalType.ProjectID
> Else
> ' the user entered a reg number.
> strSelectString = strSelectString & " Where Reg = '" &
> Trim$(txtRegProjID.Text) & "'"
> TheRetrievalType = RetrievalType.RegNumber
> End If
>
> ' do the read.
>
> If clsMiscProjMulti.dbSelect_DataReader(strSelectStri ng,
> SearchDataReader) = True Then
>
> ' No errors, did we find any records?
>
> If SearchDataReader.HasRows = True Then
> SearchDataReader.Read()
> Call AddARow(SearchDataReader)
> Else
> Me.Cursor = System.Windows.Forms.Cursors.Default()
>
> If TheRetrievalType = RetrievalType.ProjectID Then
> NotFoundMsg = "Project ID of : " &
Trim$(txtRegProjID.Text)
> Else
> NotFoundMsg = "Reg Number of : " &
Trim$(txtRegProjID.Text)
> End If
>
> MsgBox("Unable to find a project with a " & NotFoundMsg,
> MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "Not Found.")
> End If
>
> Else
> Me.Cursor = System.Windows.Forms.Cursors.Default()
> Dim err As New errorHandler(clsMiscProjMulti.lastException,
> "",
> True)
> End If
>
> End If
>
> '-------------------------------------------------------
>
> Me.Cursor = System.Windows.Forms.Cursors.Default()
>
> tlbSearch.Buttons(0).Enabled = True ' Enable (This crashes)

Mar 27 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.