473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Trigger public sub Test()

137 100+
Hello,
My mainform is a MdiParent.
On there i use for example 2 forms.
If both are on the mainform, i want that one of the forms checks if the other form is open and if this is the case he must send an update.
Sofar i have this in the first form:

Expand|Select|Wrap|Line Numbers
  1. 'If the form 'FinishRepair' is open, send update for the iriscode
  2.                     Dim frm As Form
  3.                     For Each frm In My.Application.OpenForms
  4.  
  5.                         If (frm.Name Is "FinishRepair") Then
  6.                             'Do something
  7.                          End If
  8.  
  9.                     Next
In my second form i have a sub:
Expand|Select|Wrap|Line Numbers
  1. Public Sub LoadIrisCode()
  2.  
  3.         Dim Query As String
  4.         Dim Table As New DataTable
  5.         Dim i As Integer
  6.         IrisID.Clear()
  7.  
  8.         Query = "SELECT * FROM iris_code ORDER BY code"
  9.  
  10.         Table = SelectQuery(Query)
  11.  
  12.         While i <> Table.Rows.Count
  13.  
  14.             IrisID.Add(Table.Rows(i).Item("id"))
  15.             CmbIrisCode.Items.Add(Table.Rows(i).Item("code"))
  16.             i = i + 1
  17.  
  18.         End While
  19.  
  20.         Table = Nothing
  21.  
  22.     End Sub
So in the first form, i want that the public sub is activated when he finds the form.
What is the best possible way? Add a public property or....?

Thanks,
Paul
Oct 31 '10 #1
2 2308
Joseph Martell
198 Expert 128KB
The LoadIrisCode method is already public, so there is nothing that you need to do to that method definition.

The problem is that My.Application.OpenForms() returns a FormCollection where each member is of type Form. If you want to be able to refer specifically to your LoadIrisCode method, then you need a reference of type FinishRepairForm, or whatever the class name is that you used with your second form. Then the LoadIrisCode would be accessible via that reference. Your LoadIrisCode method will never be available using a Form reference. You can accomplish this with a simple cast:

Expand|Select|Wrap|Line Numbers
  1. 'If the form 'FinishRepair' is open, send update for the iriscode
  2.                     Dim frm As Form
  3.                     For Each frm In My.Application.OpenForms
  4.  
  5.                         If (frm.Name Is "FinishRepair") Then
  6.                             Dim secondForm as FinishRepairForm = CType(frm, FinishRepairForm)    ' replace "FinishRepairForm" with the class name of your second form.
  7. secondForm.LoadIrisCode()  'this works because you are now using a reference to the specific type of your second form.
  8.                          End If
  9.  
  10.                     Next
  11.  
The above code works no matter what version of the .Net framework you are using. If you are using version 3.5 or later you could go with a different solution. Try exploring the following method:

Expand|Select|Wrap|Line Numbers
  1. My.Application.OpenForms().OfType(Of FinsishRepairForm)()

OfType is an extension method of the IEnumerable class and it returns members of a collection of the specified type.

Hope that helps.
Nov 1 '10 #2
djpaul
137 100+
Thanks Joseph!
It works now!

Greetz, Paul
Nov 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ChrisN | last post by:
Hello all, I have a quick question. I'm using a C# object to commit new rows to a database. In the database I have an INSERT Trigger watching values come in. If the record to be committed...
3
by: punkbot | last post by:
consider: public class test { public string az; public test() { az = new string; az = "0"; az = "1";} } This will serialize just fine but:
4
by: Peter Speybrouck | last post by:
I have a little problem with a webservice. I reproduced the problem in the following simplified example. I just create a new C# ASP.NET webservice and a c# console application. I added a new...
1
by: ata | last post by:
Please do not respond ! It 's only test for learning aims
5
by: Neil Steventon | last post by:
Hi, I am new to VB.net , well the objects concept anyway and was wondering if there were any good articles / turorials on when and why you would use certain declarations such as Private test...
1
by: test | last post by:
test please delete it
1
by: Vams | last post by:
Everyone, I need your help, I am trying to pass a parameter to a function that is to be called by a trigger. But, the correct function isn't being recognized and I am getting an error stating...
9
by: tomasio | last post by:
I just want to see, if i can read my own posts in this group. please ignore it.
0
by: Pilotflyhigh | last post by:
Hi, Please help. I have a class called Test public class Test { //This is my constructor public Test(string Code) { _code = Code; }
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.