Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not the same signature

Status
Not open for further replies.

kimprogrammer

Programmer
Sep 15, 2008
160
CA
Hello
I'm trying to teach myself VB.net 2005 and am having a problem with an error.

I'm trying to create a payroll timesheet. I want the user to select the payperiod from a combobox. The payperiod is part of a file and another field on is called PPLock which is a bit(boolean) field. If the user selects a payperiod that is locked I don't want them to proceed.

My problem is that I get the message PPLock is not defined, but when I put in (ByVal PPlock as Boolean) I recieve an error pointing at SelectedIndexChanged of Handles cboPPStart.SelectedIndexChanged saying they are not the same signature.

So I'm not sure what to do.

Here is my code


-------------------------------------
'
'selects payperiod start date
'
Private Sub cboPPStart_SelectedIndexChanged(ByVal PPlock As Boolean, ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPPStart.SelectedIndexChanged

Create_Panels_And_Contols()

'checks if payperiod has been locked
Debug.WriteLine(PPLock)
If PPLock = True Then
MsgBox("Payroll has been started. Please contact Payroll Department if you have any changes", vbOKOnly)
End If

'calculate and display the payperiod end date
Dim TempDate As Date = CType(cboPPStart.Text, Date)
TempDate = TempDate.AddDays(14)
lblPPEndDate.Text = TempDate.ToString("d")

End Sub

---------------------------------------
Private Sub Timesheet_Entry_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

Create_Panels_And_Contols()

'TODO: This line of code loads data into the 'HYLTDDataSet.CPY10100' table. You can move, or remove it, as needed.
Me.CPY10100TableAdapter.Fill(Me.HYLTDDataSet.CPY10100)
'TODO: This line of code loads data into the 'HYLTDDataSet.CPY10020' table. You can move, or remove it, as needed.
Me.CPY10020TableAdapter.Fill(Me.HYLTDDataSet.CPY10020)
'TODO: This line of code loads data into the 'HYLTDDataSet.CPY10050' table. You can move, or remove it, as needed.
Me.CPY10050TableAdapter.Fill(Me.HYLTDDataSet.CPY10050)
'TODO: This line of code loads data into the '_keyscan_payrollDataSet.PPStartDate' table. You can move, or remove it, as needed.
Me.PPStartDateTableAdapter.Fill(Me._keyscan_payrollDataSet.PPStartDate)



Dim PPStartDate As New _keyscan_payrollDataSet()

'open the Supervisor Table



Me.Refresh()
End Sub
----------------------------------------------


Thank you for your help

 
Here's the thing--cboPPStart_SelectedIndexChanged is an event handler for your combo box's SelectedIndexChanged event. The event is defined to have a parameter list of (ByVal sender As Object, ByVal e As System.EventArgs). Therefore, you can't just add another parameter and have it work that way.

If you create PPLock as a class level variable, you can access it from any method from within your class.
 
Thanks that makes sense - but I'm still having a problem with understanding how to move the data from the table adapter to that field. I'm new to OOP as well.
'initialize datafiles
Public PPStartDate As New DataSet()
Public PPlock As New Boolean
Would it be better to just put in the one variable or create a new data file in the class

I've tried both
--------------------
'initialize datafiles
Public PPStartDate As New DataSet()
Public PPlock As New Boolean
---------------------------------------
Do you update that field right after you fill the tableadapter?
------------------------------
Me.PPStartDateTableAdapter.Fill(Me._keyscan_payrollDataSet.PPStartDate)

PPStartDate = New _keyscan_payrollDataSet()
PPlock = ("PPLock")

 
Yes - I have a PPStartDateBindingSource set up under dataSource in the properties screen
 
Try something like this:

Code:
    Private Sub cboPPStart_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPPStart.SelectedIndexChanged

        Create_Panels_And_Contols()

        'checks if payperiod has been locked
        Dim drv As DataRowView = Ctype(cboPPStart.SelectedItem, DataRowView)
        Debug.WriteLine(drv.Item("PPLock"))
        If drv.Item("PPLock") = True Then 
            MsgBox("Payroll has been started. Please contact Payroll Department if you have any changes", vbOKOnly)
        End If

        'calculate and display the payperiod end date
        Dim TempDate As Date = CType(cboPPStart.Text, Date)
        TempDate = TempDate.AddDays(14)
        lblPPEndDate.Text = TempDate.ToString("d")

    End Sub
 
Thank you - that does what I want.
But I do have one small problem with the following statement

If drv.Item("PPlock") = "True" Then
MsgBox("Payroll has been started. Please contact Payroll Department if you have any changes", vbOKOnly)
End If

It tells me "option strict disallows operand - use the "is" operand. But if I change the = to is, I get : is requires operands that have reference types
 
Bit maps to boolean in .Net. Make sure you don't have the double quotes around the word True in your If statement. See if that helps.
 
I don't have quotes around the true. And I know it is boolean because the debug.writeline(drv.Item("PPlock"))
before the if statement returns true or false.
But the if statement specifically (drv.Item("PPlock")) gives the error saying "option strict on disallows operands of type object for operator '='. Use the 'is' operator to rest for object identity.

Here is the code:

Private Sub cboPPStart_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPPStart.SelectedIndexChanged


'checks if payperiod has been locked

Dim drv As DataRowView = CType(cboPPStart.SelectedItem, DataRowView)
Debug.WriteLine("pplock")
Debug.WriteLine(drv.Item("PPlock"))
If drv.Item("PPlock") = True Then
MsgBox("Payroll has been started. Please contact Payroll Department if you have any changes", vbOKOnly)
End If

'calculate and display the payperiod end date
Dim TempDate As Date = CType(cboPPStart.Text, Date)
TempDate = TempDate.AddDays(14)
lblPPEndDate.Text = TempDate.ToString("d")

End Sub
------------------------------------------------
 
Ohhh, I think I was a bit confused. Anyways, try casting the drv item:

Code:
Private Sub cboPPStart_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPPStart.SelectedIndexChanged


        'checks if payperiod has been locked

        Dim drv As DataRowView = CType(cboPPStart.SelectedItem, DataRowView)
        Debug.WriteLine("pplock")
        Debug.WriteLine(drv.Item("PPlock"))
        [b]If Convert.ToBoolean(drv.Item("PPlock")) = True Then[/b]
            MsgBox("Payroll has been started. Please contact Payroll Department if you have any changes", vbOKOnly)
        End If

        'calculate and display the payperiod end date
        Dim TempDate As Date = CType(cboPPStart.Text, Date)
        TempDate = TempDate.AddDays(14)
        lblPPEndDate.Text = TempDate.ToString("d")

    End Sub
 
Great thank you so much for all your help - I'll need to spend some time later understanding why that that convert was need but for now it has gotten me past this problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top