Use Copies of Forms

后端 未结 3 1471
无人及你
无人及你 2021-01-14 01:41

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

3条回答
  •  不要未来只要你来
    2021-01-14 02:19

    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.

提交回复
热议问题