Pass parameter to window.show

Is there a way to pass a parameter to a window.show call?

More specifically, I have a General Ledger table and a Fixed Asset table. Each fixed asset has a general ledger account. On the form that manages the General Ledger, I want to put a button next to the account number if it is for a fixed asset. Clicking the button will display the related detail for the record in the Fixed Asset table but for convenience I would like to just open the regular window/form I have for Fixed Assets and pass it the account number to open with.

in past similar situations, I set up a global variable with the value and in the open even of the call window I would examine this variable. This just seems a little “clunky” and thought maybe there’s a better way.

What’s the best way to do this?

thanks,
Bill

I do not understand what you are trying to do, fully.

All I can say is you cannot pass parameters through window.show. But you could make a class that inherits from the window class. And put your own method in there for showing the window. If I am right, you are trying to avoid using this method?? Please explain what you are finding “clunky”.

Make a subclass of Window and create a constructor with a parameter (something like: rowId As Int64).

you could make a special show method, myShow, and have that take the necessary parameters to populate the window’s fields, then at the end of the method you call the real show method. Something like:

Function myshow(accountNumber as integer)
//fill fields here with accountNumber
self.show
end function

I really appreciate everyone’s help, but I think using the global variables as I am currently doing fits better than creating a new class. I was just hoping there was a more “elegant” way to get there - elegant meaning less coding.

Oliver, what I am doing is using an existing window that maintains Fixed Asset records to open up with a specific record. Just trying to double dip and use as little coding as possible.

Thanks again everyone,
bill

When you only have a very small project then an additional class won’t make a difference. If you have a large project then doing communication via globals is a “bad idea” (™). But it’s your call…

[quote=52902:@Jason King]you could make a special show method, myShow, and have that take the necessary parameters to populate the window’s fields, then at the end of the method you call the real show method. Something like:

Function myshow(accountNumber as integer) //fill fields here with accountNumber self.show end function [/quote]
This is the best way.

Create this function in the fixed assets window. In the gl window don’t call window.show but call window.myshow(12345) where 12345 is the account number to use.

It is simple, doesn’t need a new class or subclass and elegant as it allows as many parameters as you want to incorporate.

Ok, that sounds good.

Thanks guys.

I am bit confused on the implementation of this - can anyone lend nudge me in the right direction?

On the calling window I am trying to pop up the new window when the user makes a choice in a listbox. I am also trying to pass the content of the cell as a parameter to the new window. The first column of the listbox contains workorder numbers and when the user selects a row I want to pass that wonumber to the WinSpot window and open up WinSpot

Sending Window

If Me.ListIndex >= 0 Then //WinSpot.myWinSpot("140028228") WinSpot.myWinSpot(Me.Cell(Me.ListIndex, 0)) //Winspot.show Else lblWo.Text = "" //lblWo.Text = "Nothing selected" End If

on the window I am opening I created this method - basically I want to populate the LblWo text field on the WinSpot window and then open the window.

Receiving Window

myWinSpot (wonumber as string) LblWo.text=wonumber self.show

[quote=130877:@Joseph Proehl]I am bit confused on the implementation of this - can anyone lend nudge me in the right direction?

On the calling window I am trying to pop up the new window when the user makes a choice in a listbox. I am also trying to pass the content of the cell as a parameter to the new window. The first column of the listbox contains workorder numbers and when the user selects a row I want to pass that wonumber to the WinSpot window and open up WinSpot

Sending Window

If Me.ListIndex >= 0 Then //WinSpot.myWinSpot("140028228") WinSpot.myWinSpot(Me.Cell(Me.ListIndex, 0)) //Winspot.show Else lblWo.Text = "" //lblWo.Text = "Nothing selected" End If

on the window I am opening I created this method - basically I want to populate the LblWo text field on the WinSpot window and then open the window.

Receiving Window

myWinSpot (wonumber as string) LblWo.text=wonumber self.show [/quote]

You could create a public method on the window you want to call named myShow which takes one or more parameters.

Sub myShow(s as string) label1.text = s me.show End Sub

The window you call must be with implicit instance true, then you can go :

TheWindow.myShow("Hello World")

and upon show the label will be filled with the message.

My myShow method is flagged as public. I seem to not be getting on how to code the the value in the list box to turn into the variable on the receiving page

I am getting [quote]You must use the value returned by this function error WinSpot.myWinSpot(Me.Cell(Me.ListIndex, 0)) [/quote]

Using your example I would want the parameter s to be equal to the value returned by WinSpot.myWinSpot(Me.Cell(Me.ListIndex, 0))

myWinSpot must be returning something. Either set the return type to blank or use the value you’re returning.

[quote=130882:@Joseph Proehl]My myShow method is flagged as public. I seem to not be getting on how to code the the value in the list box to turn into the variable on the receiving page

I am getting

Using your example I would want the parameter s to be equal to the value returned by WinSpot.myWinSpot(Me.Cell(Me.ListIndex, 0))[/quote]

If what you want to do is to pass the content of a cell in the listbox, you would go

WinSpot.myShow(Listbox1.Cell(Listbox1.Listindex,0))

Just a note…

Another way to do this is to add properties to the window and pass the information for those properties in the constructor when you instance the window.

  • When you create the window, click Implicit Instance off in the Inspector. We’ll call it WinSpecial.
  • Add a property to the window (it can be private if you like) called accountNumber. We’ll call it an int64 for consistency.
  • Create a new Method for the window and choose Constructor from the drop down list of names.
  • You will notice that the following will appear:

// Calling the overridden superclass constructor. Super.Constructor
Make sure you put your code above those lines as this is what opens the window up.

  • Add an argument to the Constructor something like paccountNum As int64 = 0.
  • In the code of the Constructor, before the Super.Constructor, enter the code:

accountNumber = paccountNum

  • When you’re ready to show that window, you’ll have to instance it like this:

Dim wSpec As New WinSpecial(Listbox1.Cell(Listbox1.Listindex,0))

  • If you don’t send an argument when you instance a new WinSpecial, the accountNumber will be zero, and you will know not to show any particular account.

I haven’t tested this code, so let me know if there’s a glitch.

[quote=52902:@Jason King]you could make a special show method, myShow, and have that take the necessary parameters to populate the window’s fields, then at the end of the method you call the real show method. Something like:

Function myshow(accountNumber as integer) //fill fields here with accountNumber self.show end function [/quote]

I’ve been looking into the best way to pass parameters to a new window / webpage also, and came upon this and other threads on the subject. The most common consensus seems to be either to do it as Jason suggests above, or to use a Constructor method.

Presumably in the “target” window, the “myShow” method would need to have a Public scope in order for the “calling” window to be able to get at it?

If that’s correct, is there a reason that it would be better to do this rather than creating Public-scoped Properties in the “target” window, and then setting them directly from the “calling” window prior to doing a TargetWindow.Show?

If you need things to be set as soon as possible (before open events etc) the constructor is the best route to go
Otherwise publicly scope properties will get set AFTER the constructor & open events and you need some way to tell that window to update itself again AFTER you set those properties (or make them computed properties and update the display when you set each one)

Interesting, thanks Norman. I don’t think the timing is critical for what I’m building at the moment, but I can see it could be in some situations. Definitely one to squirrel away in the back of my mind.

Why just don’t overload the normal Show function with your parameters?

Override the Show (without parameters) method, make it Private and let it call super.Show.
Then overload it with your version which will call self.Show when needed.