• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using netError

If everything works as it is supposed to, the text in the BookList field will be replaced with text downloaded from the Internet—but what if something goes wrong? A well-written program will check for all possible errors and deal with each possibility. For network operations such as getNetText, you can use the netError function to check the operation results.

Double-click cast member 19 to open the Script window. Revise the CheckConnectionStatus handler as shown here in bold:

global gOperationID             --Declare a global variable to hold the operation ID.

on CheckConnectionStatus        --This handler is called from the exitFrame handler
                                --in frame 17.
  if the timer > 480 then UpdateStatusLine("Waiting…")
                                --When more then 480 ticks have elapsed since the
                                --Order Now button was clicked, update the Status field
                                --with this message.
  if gOperationID <> -1 then    --If a download operation is in progress,
     if netDone(gOperationID) = TRUE then
                                --and if the operation has completed then
        put netError(gOperationID)
							--Display error results in the Message window.
        UpdateStatusLine("Displaying this month's book list…")
                                --change the status message to indicate that the book list
                                --is being displayed.
        member ("BookList").text = netTextResult( )
                                --Put the downloaded text into the BookList field.
        startTimer              --Reset the timer.
        set gOperationID = -1   --Reset the operation ID to indicate that there is
                                --no current network operation.
     end if
  end if
  go to the frame


The netError function returns 0 (zero) if there are no errors; otherwise, it returns a number for the particular error. Putting the error number in the Message window is educational, but in a real application, you should test the value returned and respond to any errors as appropriate. If the Internet address is incorrect, for example, you might display a dialog box to let the user enter a different Internet address. The Lingo Dictionary provides a list of possible error numbers returned by netError. If your program generates errors, you can check there to determine where the problem lies.

Close the Script window and save your work.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint