i have a form that pulls in data, crunches numbers, does things. it works perfectly.
the problem is the code is i can only access one market at a time and i want to
If I understand what you are after, you want something like this (first part is VERY similar to "Michael's" answer):
In the form:
Public MarketCOde As String ' whatever it is.
Public Sub New(mktCode As String)
' leave this line alone
InitializeComponent
MarketCOde = mktCode
End sub
Now anywhere the code in your form needs to know which market it is working on, it can reference MarketCode
.
To create a form to work with a new market:
Dim frmAsia As New FORMNAME("ASIA")
Since the form will REQUIRE a market code, we are passing it when we create the form. We arent cloning the form, but creating an instance
of it to work with different, but specific, markets. Now, keep reading because here is the bad news:
If all the code is embedded in the form, it will have to be refactored to reference MarketCode instead of the hardcoded references likely there now. Next, your app needs a new way to start since the mainform wont get that critical MktCode arg from VB.
The best thing is to add a market picker form, and make that the start up form in Project Properties. Add buttons to create each new market form you need:
' this is a new button on a new form to make Market Form instances.
Sub button1_click......
' USE THE ACTUAL FormName from your code!
Dim frmCentral as New FORMNAME("CENTRAL")
frmCentral.Show
End Sub
' each button makes a new market form,
Sub button2_click...... ' NOTE: Btn 2!
' the FormName from your code
Dim frmAsia as New FORMNAME("ASIA")
frmAsia.Show
End Sub
One button, one form instance name, one market
This is also the startup form to launch the first one. Be sure to set it as the startup form In Project Properties.
I suspect what you might be looking for is this...
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.Show()
End Sub
In this example, when Button1
is clicked, it creates a copy of Form1
and displays it. The button can be clicked multiple times to produce multiple copies of Form1
. The button can even be placed on Form1
itself.
It's up to you to create Properties on the MarketForm that you can set externally, so that each instance relates to a specific Market. I've used MarketName but you'll have to figure out what makes sense in your case.
Inside the code for MarketForm create something like this (you'll need to modify your existing code to use it instead of however you are currently picking a market)
Public Property MarketName As String
With object-oriented programming it is easy to create different instances of any object (Form in this case).
Dim myMarketForm1 As New MarketForm
myMarketForm1.MarketName = "Eastern"
myMarketForm1.Show()
Dim myMarketForm2 As New MarketForm
myMarketForm2.MarketName = "Central"
myMarketForm2.Show()
`... and so on