Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 将变量发送到另一个子类:无法引用实例成员_.net_Vb.net_Class_Variables - Fatal编程技术网

.net 将变量发送到另一个子类:无法引用实例成员

.net 将变量发送到另一个子类:无法引用实例成员,.net,vb.net,class,variables,.net,Vb.net,Class,Variables,我有点被一个我一直想弄明白的问题难住了。这是我面临的问题。我有两个类:CustomerFind.vb和CreateInvoice.vb。用户单击搜索按钮打开另一个最上面的表单,当用户搜索该客户时,结果将显示在DataGridView中。然后,用户为客户选择该行,然后单击“确定”。我需要将customerID从(CustomerFind.vb)发送到-->(CreateInvoice.vb)。一旦我在CreateInvoice中有了该变量,我需要使用该变量传递到一个函数中,以获取该客户详细信息的表

我有点被一个我一直想弄明白的问题难住了。这是我面临的问题。我有两个类:CustomerFind.vb和CreateInvoice.vb。用户单击搜索按钮打开另一个最上面的表单,当用户搜索该客户时,结果将显示在DataGridView中。然后,用户为客户选择该行,然后单击“确定”。我需要将customerID从(CustomerFind.vb)发送到-->(CreateInvoice.vb)。一旦我在CreateInvoice中有了该变量,我需要使用该变量传递到一个函数中,以获取该客户详细信息的表。。。请看下面的内容,我已经

这将打开CustomerFind.vb表单

  Private Sub btnFindCustomer_Click(sender As System.Object, e As System.EventArgs) Handles btnFindCustomer.Click
    Dim findCustomer As New CustomerFind
    findCustomer.ShowDialog()
  End Sub
一旦用户选择了他们的客户,变量就会传递给另一个类

  Public Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
    Dim intCustomerID As Integer = dgvSearchResults.SelectedRows(0).Cells(0).Value

    CreateInvoice.CreateNewInvoice(intCustomerID)

  End Sub
这是CreateInvoice.vb中的子项,我也在传递变量

 Public Shared Sub CreateNewInvoice(ByVal intCustomerID As Integer)

    'Datatable to hold returned results'
    Dim oTable As DataTable
    'Get the data that we need for the customer'
    oTable = CustomerHelper.GetCustomer(intCustomerID)

    txtFirstName.Text = IIf(oTable.Rows(0).Item("First_Name") Is DBNull.Value, "NA", oTable.Rows(0).Item("First_Name")))
    txtLastName.Text = IIf(oTable.Rows(0).Item("Last_Name") Is DBNull.Value, "NA", oTable.Rows(0).Item("Last_Name"))
    txtCity.Text = IIf(oTable.Rows(0).Item("City") Is DBNull.Value, "NA", oTable.Rows(0).Item("City"))
    cboState.SelectedValue = IIf(oTable.Rows(0).Item("State") Is DBNull.Value, "NA", oTable.Rows(0).Item("State"))
    txtAddress.Text = IIf(oTable.Rows(0).Item("Address") Is DBNull.Value, "NA", oTable.Rows(0).Item("Address"))
    txtZipCode.Text = IIf(oTable.Rows(0).Item("Zip_Code") Is DBNull.Value, "NA", oTable.Rows(0).Item("Zip_Code"))
    txtEmail.Text = IIf(oTable.Rows(0).Item("Email") Is DBNull.Value, "NA", oTable.Rows(0).Item("email"))
    txtHomePhone.Text = IIf(oTable.Rows(0).Item("Home_Phone") Is DBNull.Value, "NA", oTable.Rows(0).Item("Home_Phone"))
    txtCellPhone.Text = IIf(oTable.Rows(0).Item("Cell_Phone") Is DBNull.Value, "NA", oTable.Rows(0).Item("Cell_Phone"))
    txtMiddleInitial.Text = IIf(oTable.Rows(0).Item("Middle_Initial") Is DBNull.Value, "NA", oTable.Rows(0).Item("Middle_Initial"))

End Sub
问题就在这里。所有文本字段都不能从共享方法中引用类的实例成员。。。我需要从返回的表中填充这些字段

我不确定我在这里错过了什么,也许我只是太累了


谢谢

我不理解您的期望,但我认为您可能需要这个(将CustomerId从CustomerFind.vb传递到CreateInvoice.vb)。为此,您可以使用以下方法:

在CustomerFind.vb中创建一个不可见的标签,并将CustomerId指定给该标签

  inlabel.Text=""+CustomerId 
在CreateInvoice.vb中

   Dim id as Integer
   id=CustomerFind.inlabel.text

现在您可以使用CustomerId了,我已经有一段时间没有做过任何表单开发了,但是您不想做一些类似于:

Public Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
    Dim intCustomerID As Integer = dgvSearchResults.SelectedRows(0).Cells(0).Value
    Dim invoiceDlg as New CreateInvoice

    ' new field in you invoice class
    invoiceDlg.CustomerID = intCustomerID
    ' set up text fields in your dialog init function instead of CreateNewInvoice()
    invoiceDlg.ShowDialog();
End Sub

CreateNewInvoice
是否必须共享?@chue x不,我已经尝试过了,但是当我删除共享时,我无法将变量发送到该子项…这将不起作用…抱歉。我尝试过这个,有趣的是我将变量传递给sub,然后它返回一个表,然后我尝试从表中设置textbox字段(没有错误),但textbox中没有显示任何内容?@MrCoDeXeR-我想我对invoice类的了解不够,无法提出任何其他建议。