User7291
User7291

Reputation: 1115

Label not defined Error

i have this code i'm using a goto option i'm always getting that the label nextrecord is not defined .. what shall i do ? am i missing something? can you please tell me when shall i do :) thank you in advance ! that's the code i'm writing ..

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

Upvotes: 0

Views: 556

Answers (2)

am i missing something?

I think so. A) You cannot GOTO a point in a different procedure and B) its a bad idea to GOTO a location inside another loop (if it is even legal). C) It also appears that you are using a timer as a loop control means and D) the location of the NEXTRECORD label seems to indicate you are trying to GOTO/CALL/jump into a loop inside an event procedure.

Change sendSched() to a function with returns True/False depending on whether to send or not (very similar to Douglas' answer).

Then gut start_check_CheckedChanged to a new procedure with that code in it, such as:

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

Now, you can call it from the event procedure AND/OR call it from the Timer_Tick event as needed and eliminate the GOTO and the send global/module flag variable.

It looks like you might have been trying to use GOTO to avoid re-processing things in start_check_CheckedChanged (even though something is being cleared every time it is processed with subTables.Rows.Clear). First though, you are iterating all the rows in the event when you might be able to examine the event args (sender and e) to know precisely which thing to process (provided it is a legitimate event and not something you are firing in code.)

You might also be to examine .timesend to determine if that packet (or whatever they are) has been sent. Something like:

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

Alternatively, since it looks like content is something you devised, you could add a Sent flag you set after sending each item, and use If content.Sent = False Then... to skip over the ones already sent.

HTH

Upvotes: 1

Douglas Barbin
Douglas Barbin

Reputation: 3615

This should be totally rewritten. It isn't quite clear what you are trying to do here, but try this:

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

Upvotes: 0

Related Questions