[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:
Dim dlgSellStocks As frmSellStocksModeless = New frmSellStocksModeless
dlgSellStocks.cbSell.Items() 'this gives me an error (obviously).
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.
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.
Re: loading into a modeless dialog question...
im not sure if i undrestand u guys' solutions...
This is my code:
VB Code:
If dlgBuyStocks.DialogResult = DialogResult.OK Then
If dlgBuyStocks.txtCompanyName.Text <> mstkPortfolio(cbStocks.SelectedIndex).Company Then
ReDim Preserve mstkPortfolio(intStockCount)
cbStocks.Items.Add(dlgBuyStocks.CompanyNameEnter)
intStockCount += 1
'----------------------------------------------------------------------'
'newly purchased stock’s information must be shown in the main program.'
'----------------------------------------------------------------------'
'intSharesToBuy = CInt(dlgBuyStocks.EnterShares)
'dblPurchasePrice = CDbl(dlgBuyStocks.PurchasePriceEnter)
'mstkPortfolio(cbStocks.SelectedIndex).Buy(intSharesToBuy, dblPurchasePrice, Today)
'DisplayStock()
Else
intSharesToBuy = CInt(dlgBuyStocks.EnterShares)
dblPurchasePrice = CDbl(dlgBuyStocks.PurchasePriceEnter)
mstkPortfolio(cbStocks.SelectedIndex).Buy(intSharesToBuy, dblPurchasePrice, Today)
DisplayStock()
End If
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:
Private Sub DisplayStock()
Dim dblPortfolioValue As Double
Dim dblPercentageWorth As Double
With mstkPortfolio(cbStocks.SelectedIndex)
txtPurchaseDate.Text = Format(.PurchaseDate, "Short Date")
txtShares.Text = CStr(.Shares)
txtPurchasePrice.Text = FormatCurrency(.PurchasePrice)
txtTotalValue.Text = FormatCurrency(.TotalValue)
dblPortfolioValue = CDbl(txtPortfolioValue.Text)
dblPercentageWorth = .TotalValue / dblPortfolioValue
txtPercentageWorth.Text = FormatPercent(dblPercentageWorth)
End With
End Sub
and in the line
VB Code:
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!!!
Re: loading into a modeless dialog question...
i still need help with this please!!!
Re: loading into a modeless dialog question...
isnt there ANYONE that can help me?
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.
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?
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:
ReDim Preserve myArray(myArray.Length)