Results 1 to 9 of 9

Thread: [RESOLVED] loading into a modeless dialog question...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    98

    Resolved [RESOLVED] loading into a modeless dialog question...

    My main program has a combo box loaded with an array of names.
    I have created a modeless dialog box and i want the same array maintained by my main program to be loaded into the combo box in my modeless dialog.
    can anyone help me with the syntax?
    Thanks!
    i have this:
    VB Code:
    1. Dim dlgSellStocks As frmSellStocksModeless = New frmSellStocksModeless
    2.  
    3.         dlgSellStocks.cbSell.Items() 'this gives me an error (obviously).

  2. #2
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: loading into a modeless dialog question...

    I would create a property in the parent form for the array. In the Form_Load event of the modeless form, I would call this property and pull in the array. Then you can apply it to the combobox like you did on the parent form.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: loading into a modeless dialog question...

    If you always want this dialogue to get this array then I'd suggest making the only public constructor take it as an argument. That way it's impossible to create an instance of this form without providing it the data it needs.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    98

    Re: loading into a modeless dialog question...

    im not sure if i undrestand u guys' solutions...
    This is my code:
    VB Code:
    1. If dlgBuyStocks.DialogResult = DialogResult.OK Then
    2.             If dlgBuyStocks.txtCompanyName.Text <> mstkPortfolio(cbStocks.SelectedIndex).Company Then
    3.  
    4.                 ReDim Preserve mstkPortfolio(intStockCount)
    5.  
    6.                 cbStocks.Items.Add(dlgBuyStocks.CompanyNameEnter)
    7.  
    8.                 intStockCount += 1
    9.  
    10.                 '----------------------------------------------------------------------'
    11.                 'newly purchased stock’s information must be shown in the main program.'
    12.                 '----------------------------------------------------------------------'
    13.                 'intSharesToBuy = CInt(dlgBuyStocks.EnterShares)
    14.                 'dblPurchasePrice = CDbl(dlgBuyStocks.PurchasePriceEnter)
    15.                 'mstkPortfolio(cbStocks.SelectedIndex).Buy(intSharesToBuy, dblPurchasePrice, Today)
    16.                 'DisplayStock()
    17.             Else
    18.                 intSharesToBuy = CInt(dlgBuyStocks.EnterShares)
    19.                 dblPurchasePrice = CDbl(dlgBuyStocks.PurchasePriceEnter)
    20.                 mstkPortfolio(cbStocks.SelectedIndex).Buy(intSharesToBuy, dblPurchasePrice, Today)
    21.                 DisplayStock()
    22.             End If
    23.         End If
    and what i have to do is to add the new name (typed by the user in the modal dialogue) into the exisiting array i have in the main program. then, i should be able to show all the info of the new name when i select the new name in the main programs' combo box.
    right now what is happening is that the name typed by the user is added into the main program's combo box, however, when i select that new name, it goes into another part of my code:
    VB Code:
    1. Private Sub DisplayStock()
    2.         Dim dblPortfolioValue As Double
    3.         Dim dblPercentageWorth As Double
    4.  
    5.         With mstkPortfolio(cbStocks.SelectedIndex)
    6.             txtPurchaseDate.Text = Format(.PurchaseDate, "Short Date")
    7.             txtShares.Text = CStr(.Shares)
    8.             txtPurchasePrice.Text = FormatCurrency(.PurchasePrice)
    9.             txtTotalValue.Text = FormatCurrency(.TotalValue)
    10.  
    11.             dblPortfolioValue = CDbl(txtPortfolioValue.Text)
    12.             dblPercentageWorth = .TotalValue / dblPortfolioValue
    13.             txtPercentageWorth.Text = FormatPercent(dblPercentageWorth)
    14.         End With
    15.     End Sub
    and in the line
    VB Code:
    1. With mstkPortfolio(cbStocks.SelectedIndex)
    , it gives me an error saying "Index was outside the bounds of the array."
    hmm..let me know if this is not clear..
    thanks for your help!!!
    Last edited by saliwalido; Feb 17th, 2006 at 06:41 PM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    98

    Re: loading into a modeless dialog question...

    i still need help with this please!!!
    Last edited by saliwalido; Feb 18th, 2006 at 01:26 AM.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    98

    Re: loading into a modeless dialog question...

    isnt there ANYONE that can help me?

  7. #7
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: loading into a modeless dialog question...

    It seems like your code should work for adding the items to the array. I would set a break point on the line you are getting the error on and determine how many items are in the array and then also so how many items are in the combobox. Since it seems that this combobox drives your array, then these two values should match.

    Let us know where that leaves you.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    98

    Re: loading into a modeless dialog question...

    after the line ReDim Preserve mstkPortfolio(intStockCount) is executed, the array items change from 3 to 1....shouldnt it change to 4? (since I am adding a new item to the array?) ....c this is where i am having troubles (atleast thats what i think)
    any more help?

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: loading into a modeless dialog question...

    The array length is changed to whatever you change it to. If the Length is 1 after your call to ReDim then you've specified 0 as the upper bound. If you want to increase the Length of an array by one using ReDim you would use this:
    VB Code:
    1. ReDim Preserve myArray(myArray.Length)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width