blubzie Posted December 15, 2003 Posted December 15, 2003 Hi , this is my first week learning Vb.net and I am having trouble learning about creating instances but I guess that will improve with time. My problem is I'm adding items to a combo box from an array. This is done in a sub which is being called from the same form that I want to view the combobox. The problem is after going through the sub, the program jumps to a module and then jumps back to the form and shows the form, but the combobox is not displaying anything. I've search all over the net and on this site and learned about directcast and ownership but I don't know how to use them for my purpose. Here's my code: Public Sub LoadItems(ByVal strTitle As Array) Dim i As Long Dim openingscreen As New frmOpening_Screen() openingscreen.Owner = Me openingscreen.cmbTitle.Items.Clear() For i = 0 To UBound(strTitle, 2) openingscreen.cmbTitle.Items.Add(strTitle.GetValue(0, i)) Next i End Sub If you can tell me what the problem is and how to fix it ,that would be greatly appreciated. Quote
Administrators PlausiblyDamp Posted December 15, 2003 Administrators Posted December 15, 2003 How and where is this function being called? If it is being called from frmOpening_Screen then you will need to pass an instance of the form to this function rather than create a new instance within it. i.e. Public Sub LoadItems(ByVal strTitle As Array, ByVal frm as frmOpening_Screen) Dim i As Long frm.Owner = Me frm.cmbTitle.Items.Clear() For i = 0 To UBound(strTitle, 2) frm.cmbTitle.Items.Add(strTitle.GetValue(0, i)) Next i End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
blubzie Posted December 15, 2003 Author Posted December 15, 2003 I tried it with the new modification, so far no progress. The LoadItems is being called in the module. Here is the sub that is calling LoadItems. Public Sub Load_OpeningScreen() 'Initialize the list 'adoRecord is the recordset Class Dim adoTitle As New adoRecord() Dim adorecTitle As ADODB.Recordset Dim OpeningScreen As New frmOpening_Screen() Dim strTitle As Array adorecTitle = adoTitle.recordConnect("SELECT Title FROM tblBusSpecInfo") strTitle = adorecTitle.GetRows Call OpeningScreen.LoadItems(strTitle, OpeningScreen) end sub Here is the LoadItems function (with the new modification). This is called in the frmOpening_Screen: Public Function LoadItems(ByVal strTitle As Array, ByVal frm As frmOpening_Screen) Dim i As Long 'I had to get get of this line because it was causing a 'circular reference 'frm.Owner = Me frm.cmbTitle.Items.Clear() For i = 0 To UBound(strTitle, 2) frm.cmbTitle.Items.Add(strTitle.GetValue(0, i)) Next i End Function Quote
Administrators PlausiblyDamp Posted December 15, 2003 Administrators Posted December 15, 2003 try changing Call OpeningScreen.LoadItems(strTitle, OpeningScreen) to Call OpeningScreen.LoadItems(strTitle, Me) and removing the line Dim OpeningScreen As New frmOpening_Screen() Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
blubzie Posted December 15, 2003 Author Posted December 15, 2003 Unfortuanately, that won't work because "Me" can't be used inside the module and removing "Dim OpeningScreen as New frmOpeningscreen" will cause the call function "Call OpeningScreen.LoadItems(strTitle, Me)" to not work because it won't recognize OpeningScreen. I forgot to mention that the sub "Load_OpeningScreen" is in a module and is calling "LoadItems". "LoadItems" is in the "frmOpeningScreen" form. Thank you so much for trying to help me. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.