lunaclover
Programmer
- Jun 22, 2005
- 54
Hi all - I'm having a problem with syntax, I think. I just made my first class (called MyList) and am trying to work with it. I learned on VB6 and even that was a while ago, but .. well anyway, classes are new to me, so I may have something wrong.
I created the class so that I could have two values in my combobox - the first is called 'desc' and the second is called 'value'. It looks like this when populating.
where CAT540 and BRAND are comboboxes. This works okay.
I am trying to use one of the fields (desc) as reference when telling it how to populate the next combobox, based off the selection in the previous combobox, like this.
where ID540 is the next combobox.
It gives me a
ERROR
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "" to type 'Integer' is not valid.
ERROR
Here's my class I made, if that helps explain why the error is being produced.
How am I supposed to reword this to make it work? I could just say
CAT540.text = "10-11 EER A/C"
but that would defeat the purpose of my multivalue combobox and my class and everything. It is erroring out because I am saying
CAT540.Items.Item(CAT540.SelectedText).Desc "blah"
Do I even have to use the description again, shouldn't it know? I don't get it.
Thanks in advance,
Luna
I created the class so that I could have two values in my combobox - the first is called 'desc' and the second is called 'value'. It looks like this when populating.
Code:
Dim sBrand As String = BRAND.Text
Select Case sBrand
Case "Elm"
With CAT540
.Items.Add(New MyList("10-11 EER A/C", "H"))
.Items.Add(New MyList("11+ EER A/C", "J"))
.Items.Add(New MyList("9-10 EER A/C", "M"))
where CAT540 and BRAND are comboboxes. This works okay.
I am trying to use one of the fields (desc) as reference when telling it how to populate the next combobox, based off the selection in the previous combobox, like this.
Code:
If BRAND.Text <> "" Then
If CAT540.Items.Item(CAT540.SelectedText).Desc = "11+ EER A/C" Then
ID540.Items.Add("J")
End If
where ID540 is the next combobox.
It gives me a
ERROR
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "" to type 'Integer' is not valid.
ERROR
Here's my class I made, if that helps explain why the error is being produced.
Code:
Public Class MyList
Private _sDesc As String
Private _sValue As String
' Default empty constructor.
Public Sub New()
_sDesc = ""
_sValue = ""
End Sub
Public Sub New(ByVal Desc As String, ByVal Value As String)
_sDesc = Desc
_sValue = Value
End Sub
Public ReadOnly Property Desc() As String
Get
Return _sDesc
End Get
End Property
' This is the property that holds the extra data.
Public ReadOnly Property Value() As String
Get
Return _sValue
End Get
End Property
' This is necessary because the ListBox and ComboBox rely
' on this method when determining the text to display.
Public Overrides Function ToString() As String
Return Desc
Return Value
End Function
End Class
How am I supposed to reword this to make it work? I could just say
CAT540.text = "10-11 EER A/C"
but that would defeat the purpose of my multivalue combobox and my class and everything. It is erroring out because I am saying
CAT540.Items.Item(CAT540.SelectedText).Desc "blah"
Do I even have to use the description again, shouldn't it know? I don't get it.
Thanks in advance,
Luna