|
-
Nov 24th, 2003, 11:08 AM
#1
Thread Starter
Junior Member
loading and passing combobox
Hey all. I'm having problems determining how to do this.
I have a class that loads 42000+ items into a combobox that is used on multiple forms. I want to load this combobox during the time that the splash-screen is showing, and then just reference it from other forms.
My class code looks something like this:
Code:
Public Shared Function LoadZipCodes(ByRef cmbCombo As ComboBox)
Dim cmbZip As ComboBox
GenericCode(1, "Zip Code", cmbZip)
cmbCombo = cmbZip
Return cmbCombo
End Function
I know that it populates the combobox, and I'm pretty sure to put the call to that function in the splashscreen_load sub. What is the best way to pass it to another form, or should I make a global variable that can be used project-wide and just have my comboboxes ref that for the data? I want to try to eliminate processing time as much as possible between switching forms.
Your help is much appreciated.
-
Nov 24th, 2003, 11:11 AM
#2
Frenzied Member
I would do it as a global, since it is going to be accessed throughout the application.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Nov 25th, 2003, 05:08 AM
#3
Thread Starter
Junior Member
Ok, sorry to bother again, but I'm getting the error of:
"Object reference not set to an instance of an object"
when I do this. Also where should my call to the function to load the combo box be if I want it to run only once and run while the user can see the SplashScreen form?
here is my code:
Module
Code:
Public cmbZips As ComboBox
public sub Main()....
Splash Screen
Code:
Private Sub loadZipCodes()
Dim clsPrac As clsPractice
clsPrac.GenericCode(1, "Zip Code", cmbZips)
End Sub
clsPractice
Code:
Public Shared Sub GenericCode(ByVal intProcess As Integer, ByVal strProcess As String, ByRef cmbBox As ComboBox)
'intProcess 1 = Load Zip Code
'intProcess 2 = Load States
Dim objAdapter As OleDb.OleDbDataAdapter
Dim objTable As New DataTable
Dim objItem As ListItemNumeric
Dim strSQL As String
Dim strConn As String
Dim intLoop, records As Integer
Dim str1, str2, str3 As String
Select Case intProcess
Case 1 ' load zip codes
strSQL = "Select * from Zip, State where Zip.State = StateAbb"
str1 = "num"
str2 = "Zip"
Case 2 ' load states
strSQL = "Select StateID, StateAbb, StateName From State"
str1 = "StateID"
str2 = "StateName"
Case 3 'load tech
strSQL = "Select * from Tech, Inventory, Company where inv_tech_num = tech_num and tech_comp_num = company_num"
str1 = "Tech.num"
str2 = "tech_num"
Case Else
MessageBox.Show("There is some kind of error", "ERROR")
End Select
strConn = ConnectStringBuild()
Try
objAdapter = New OleDb.OleDbDataAdapter(strSQL, strConn)
objAdapter.Fill(objTable)
records = objTable.Rows.Count - 1
If records > 43000 Then records = 9
For intLoop = 0 To records
objItem = New ListItemNumeric
With objTable.Rows(intLoop)
objItem.ItemID = CInt(.Item(str1))
objItem.ItemValue = .Item(str2).ToString()
If intProcess = 1 Then
objItem.City = .Item("City").ToString()
objItem.State = .Item("StateName").ToString()
ElseIf intProcess = 3 Then
objItem.TechCompNum = .Item objItem.Email = .Item("tech_email").ToString
End If
End With
cmbBox.Items.Add(objItem)
Next
Dim x As Integer
x = CInt(objTable.Rows(1).Item(str1))
Catch objException As Exception
MessageBox.Show(objException.Message, strProcess)
End Try
End Sub
once again, your help is appreciated. and I'm unsure of how to instantiate the comboBox so I avoid getting that error. Thanks.
-
Nov 26th, 2003, 05:33 AM
#4
Hyperactive Member
declare it as Public Shared
and u can reference it easily from other forms
-
Nov 26th, 2003, 10:58 AM
#5
VB Code:
Public Class Practice
Public Enum LoadType
ZipCode
State
Tech
End Enum
'proper syntax to use:
'Practice.GenericCode(LoadType.State, ComboBox1)
Public Shared Sub GenericCode(ByVal loadTypes As LoadType, ByRef cmbBox As ComboBox)
Dim objAdapter As OleDb.OleDbDataAdapter
Dim objTable As New DataTable
Dim objItem As ListItemNumeric
Dim strSQL As String
Dim strConn As String
Dim intLoop, records As Integer
Dim str1, str2, str3 As String
Select Case loadTypes
Case LoadType.ZipCode
strSQL = "Select * from Zip, State where Zip.State = StateAbb"
str1 = "num"
str2 = "Zip"
Case LoadType.State
strSQL = "Select StateID, StateAbb, StateName From State"
str1 = "StateID"
str2 = "StateName"
Case LoadType.Tech
strSQL = "Select * from Tech, Inventory, Company where inv_tech_num = tech_num and tech_comp_num = company_num"
str1 = "Tech.num"
str2 = "tech_num"
Case Else
MessageBox.Show("There is some kind of error", "ERROR")
End Select
'Shared methods can't call instance methods so I hope this is another shared method
strConn = ConnectStringBuild()
Try
objAdapter = New OleDb.OleDbDataAdapter(strSQL, strConn)
objAdapter.Fill(objTable)
records = objTable.Rows.Count - 1
If records > 43000 Then records = 9
For intLoop = 0 To records
objItem = New ListItemNumeric
With objTable.Rows(intLoop)
objItem.ItemID = CInt(.Item(str1))
objItem.ItemValue = .Item(str2).ToString()
If loadTypes = LoadType.ZipCode Then
objItem.City = .Item("City").ToString()
objItem.State = .Item("StateName").ToString()
ElseIf LoadType.Tech Then
objItem.TechCompNum = .Item 'missing fieldname
objItem.Email = .Item("tech_email").ToString
End If
End With
cmbBox.Items.Add(objItem)
Next
Dim x As Integer = CType(objTable.Rows(1).Item(str1), Integer)
Catch objException As Exception
MessageBox.Show(objException.Message, loadTypes.ToString)
End Try
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|