Reading data of an other window

Hi all,

I’m stuck with something that is probably simple to do…

I have created a method that read all the controls of the window in order to add data to my database. This is working great so far. Now I have more windows so it makes sense to make a global method to do this instead of having the same method in each window.

But this is where the but is… I can’t figure out how to have this global method to read the controls of the specific window that called the method. (For example, "window1.textfield.Text ", though window1 need to be pointing to any window that call the method) I can imagine that I need to pass the window information as a parameter, but I don’t see how to do that… any input on this please?


use SELF

in WIndow1 where it calls your global “myMethod”… say myMethod(self)

and myMethod is defined as FUNCTION myMethod(win as Window)
and within myMethod use “win” to refer back to the window that called it

Thanks Dave for your answer. I think I don’t understand something about ‘defined as Function’. How is that different that simply adding a Method with a parameter?

same thing… sorry… I’ve been working in another language alot lately, and it uses “FUNC” for both Functions and methods :slight_smile:

SUB myMethod(win as Window)
.... do stuff with

Alright, so I tried that and it works fine with the window property (like win.Title) but I got it wrong with the controls on that windows.
When looking at win.TextField1.Text it gives me the following error "Type “Window” has no member named “TextField1”. Any idea?

I think you need to access controls thru the “controls array”… I don’t recall the exact syntax, but its not straight forward…

Dim c As Control
For i As Integer = 0 To Self.ControlCount-1
  c = window.Control(i)
  If c IsA TextField Then
    if"TextField1" then 
   ..... do something
  End If

“control” is a property of the window… and textfield1 is a member of control… so its one level down from the actual window itself

Awesome, it works! Thank you so much Dave :slight_smile: