Reputation: 843
I'm trying to store an form object into a variable, but it not succeed:
This code doesn't work:
Dim invoice_form As billing_new_invoice
'Get last remote Row
Dim last_row As Integer = CType(main.ActiveMdiChild, invoice_form).invoiceitems_new_invoice.Rows.Count - 1
Dim count_row As Integer = CType(main.ActiveMdiChild, invoice_form).invoiceitems_new_invoice.Rows.Count()
This code works:
Dim invoice_form As billing_new_invoice
'Get last remote Row
Dim last_row As Integer = CType(main.ActiveMdiChild, billing_new_invoice).invoiceitems_new_invoice.Rows.Count - 1
Dim count_row As Integer = CType(main.ActiveMdiChild, billing_new_invoice).invoiceitems_new_invoice.Rows.Count()
I need to store the form instance in the variable (invoice_form), that could be used in multiple lines of code, but it says (Type 'invoice_form' is not defined.) Anyone have idea to solve this ?
Upvotes: 2
Views: 1573
Reputation: 17845
CType is for type conversion, not variable assignment. What you want to do is assign the variable to the form first, then use that variable:
Dim invoice_form As billing_new_invoice = CType(main.ActiveMdiChild, billing_new_invoice)
Dim last_row As Integer = invoice_form.invoiceitems_new_invoice.Rows.Count - 1
Upvotes: 2
Reputation: 81610
Not very clear what the issue is. I think you are looking for something like this:
If TypeOf Me.ActiveMdiChild Is billing_new_invoice Then
Dim invoice_Form As billing_new_invoice = Me.ActiveMdiChild
Dim last_row As Integer = invoice_form.invoiceitems_new_invoice.Rows.Count - 1
Dim count_row As Integer = invoice_form.invoiceitems_new_invoice.Rows.Count()
//'etc
End If
The problem with the code that isn't working is that it is trying to cast it into a variable, not a type. invoice_form
is a variable, billing_new_invoice
is a type.
Upvotes: 2