0

我有一个包含三个组合框的表单,分别称为 Ticker、Year 和 Period。我填写这些以将我的程序引导到我希望它查找的股票。在此示例中,我键入 GOOG, 2013, 1。这样我的程序就会查找 Google 2013 年第一季度的数据。但是当我尝试运行我的代码时收到此错误消息"An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll Additional information: Conversion from string "" to type 'Double' is not valid."

这是我的代码:

Dim dtmCurrentDateTime As System.DateTime = Now()
            Dim Current_Quarter As System.Int32 = DatePart(DateInterval.Quarter, dtmCurrentDateTime)

            If Current_Quarter = 1 Then
                If ComboBox_Period.ValueMember = 4 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 1st Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 3 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 2nd Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 2 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 3nd Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 1 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 4nd Quarterly Column")
                Else
                    MsgBox("Date out of range.  Please lookup and enter manually")
                End If
            ElseIf Current_Quarter = 2 Then
                If ComboBox_Period.ValueMember = 1 And ComboBox_Year.ValueMember = (Now.Year) Then
                    MsgBox("Scrape 1st Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 4 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 2nd Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 3 And ComboBox_Year.ValueMember = (Now.Year - ) Then
                    MsgBox("Scrape 3nd Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 2 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 4nd Quarterly Column")
                Else
                    MsgBox("Date out of range.  Please lookup and enter manually")
                End If
            ElseIf Current_Quarter = 3 Then
                If ComboBox_Period.ValueMember = 2 And ComboBox_Year.ValueMember = (Now.Year) Then
                    MsgBox("Scrape 1st Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 1 And ComboBox_Year.ValueMember = (Now.Year) Then
                    MsgBox("Scrape 2nd Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 4 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 3nd Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 3 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 4nd Quarterly Column")
                Else
                    MsgBox("Date out of range.  Please lookup and enter manually")
                End If
            ElseIf Current_Quarter = 4 Then
                If ComboBox_Period.ValueMember = 3 And ComboBox_Year.ValueMember = (Now.Year) Then
                    MsgBox("Scrape 1st Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 2 And ComboBox_Year.ValueMember = (Now.Year) Then
                    MsgBox("Scrape 2nd Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 1 And ComboBox_Year.ValueMember = (Now.Year) Then
                    MsgBox("Scrape 3nd Quarterly Column")
                ElseIf ComboBox_Period.ValueMember = 4 And ComboBox_Year.ValueMember = (Now.Year - 1) Then
                    MsgBox("Scrape 4nd Quarterly Column")
                Else
                    MsgBox("Date out of range.  Please lookup and enter manually")
                End If
            End If
4

1 回答 1

1

正如 MSDN 所说..

Public Property ValueMember As String

由于它由

ComboBox1.ValueMember = "ShortName" '---> example

你不能像这样比较价值 If ComboBox_Period.ValueMember = 1

于 2013-06-25T15:44:36.840 回答