标签未定义错误

时间:2013-09-12 14:27:44

标签: vb.net vb.net-2010

我有这个代码我正在使用goto选项 我总是得到标签nextrecord没有定义..我该怎么办?我错过了什么吗?你能告诉我我该怎么办:)提前谢谢你! 这就是我正在编写的代码..

Private Sub Timer_Tick(sender As System.Object, e As System.EventArgs) Handles Timer.Tick
    Try
        Timer.Interval = 5000
        sendSched()
        If send = True Then
            GoTo NEXTRECORD
        End If
    Catch
    End Try
End Sub 

Private Sub sendSched()
    subTable.Rows.Clear()
    subTable = selectSubscriber(content.mt, content.clID)
    subCount = subTable.Rows.Count()
    If content.timeSend = DateTime.Now.ToString("hh:mm") Then
        Timer.Enabled = False
        UpdateListBoxRec2("Sending content: " & content.contentSend & " to :")
        For Each subRow As DataRow In subTable.Rows
            content.moSend = subRow("sim_mo")
            UpdateListBoxRec2(content.moSend)
            MsgBox(content.contentSend)
        Next
        send = True
    Else
        Timer.Enabled = True
        Timer.Interval = 5000
    End If
End Sub

Private Sub start_check_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles start_check.CheckedChanged
  For Each contentRow As DataRow In contentTable.Rows
            content.mt = contentRow("cnt_mt")
            content.clID = contentRow("cnt_cl_id")
            content.contentSend = contentRow("cnt_content")
            content.id = contentRow("cnt_id")
            content.timeSend = contentRow("cnt_time_to_send")
            UpdateListBoxRec("Content to send at: " & content.timeSend)
            Timer.Enabled = True
            Timer.Interval = 0
NEXTRECORD:
   Next
End Sub

2 个答案:

答案 0 :(得分:1)

  我错过了什么吗?

我是这么认为的。 A)你不能在一个不同的程序中转移一个点,而B)在另一个循环中GOTO一个位置是一个坏主意(如果它甚至是合法的)。 C)出现您正在使用计时器作为循环控制装置和D)NEXTRECORD标签的位置似乎表明您正在尝试GOTO / CALL /跳转到事件内的循环过程

将sendSched()更改为返回True / False的函数,具体取决于是否发送(非常类似于Douglas的回答)。

然后gut start_check_CheckedChanged到其中包含该代码的新程序,例如:

Private Sub AddContent
   For Each contentRow As DataRow In contentTable.Rows
    ...
    ...
   Next
End Sub

现在,您可以从事件过程调用它和/或根据需要从Timer_Tick事件中调用它,并消除GOTO和发送全局/模块标志变量。

看起来像您可能一直在尝试使用GOTO来避免在start_check_CheckedChanged中重新处理事情(即使每次使用{{1}处理某事时都会清除某些内容})。首先,当您可以检查事件参数(subTables.Rows.Clearsender)时,您正在迭代事件中的所有行,以准确了解要处理的事物(假设它是合法事件并且不是你在代码中解雇的东西。)

您可能还要检查.timesend以确定是否已发送该数据包(或其他任何数据包)。类似的东西:

e

或者,由于看起来For Each contentRow As DataRow In contentTable.Rows If content.timesend <> String.Empty Then ' or <> DateTime.Now.MinValue.ToString ... ' process or send it ... End If Next 是您设计的内容,您可以在发送每个项目后添加一个content标记,并使用Sent跳过已发送的标记

HTH

答案 1 :(得分:0)

这应该完全改写。你在这里尝试做什么还不是很清楚,但试试这个:

If Not send  Then
  For Each contentRow As DataRow In contentTable.Rows
            content.mt = contentRow("cnt_mt")
            content.clID = contentRow("cnt_cl_id")
            content.contentSend = contentRow("cnt_content")
            content.id = contentRow("cnt_id")
            content.timeSend = contentRow("cnt_time_to_send")
            UpdateListBoxRec("Content to send at: " & content.timeSend)
            Timer.Enabled = True
            Timer.Interval = 0
   Next
End If
相关问题