none
Exception has been thrown by the target of an invocation (Small Basic) RRS feed

  • Question

  • Hello all! I have a big problem in Small Basic that is preventing me from getting any sort of work done on my program.

    I have been working on a small program that worked fine for days up until yesterday. Now, for some reason, whenever I play it I get this error message:

    Exception has been thrown by the target of an invocation (Small Basic)

    Alongside a bunch of System. statements. As far as I know, all my code makes sense and I see no problem. I am not using any sort of extensions.

    Here is my code in case you need it:

    'Final Assignment 1 by Brendan Neil-Gagnon
    
    'Some variables
    varEvent = "Enter"
    varMessage = Shapes.AddText("")
    varButton = Controls.AddButton("Confirm",0,128)
    Controls.ButtonClicked = OnButtonClick
    
    'Subroutine for clicking button
    Sub OnButtonClick
      varEvent = "Enter"
    EndSub
    
    'Create array for address/phone book
    Sub EnterPerson
      i = i+1
      Clear()
        
      'Get friend's name
      GraphicsWindow.DrawText(0,i*32,"Enter the name of friend "+i+":")
      varFriend[i] = Controls.GetTextBoxText(varTextBox[1])
        
      'Get friend's phone number
      GraphicsWindow.DrawText(0,i*48,"Enter his/her phone number: ")
      varPhoneNumber = Controls.GetTextBoxText(varTextBox[2])
      arrFriend[varFriend[i]]["Phone"] = varPhoneNumber
        
      'Get friend's email address
      GraphicsWindow.DrawText(0,i*64,"Enter your friend's email address: ")
      varEmail = Controls.GetTextBoxText(varTextBox[3])
      arrFriend[varFriend[i]]["Email"] = varEmail
        
      'Get time of entry
      varTime = Clock.Time
      arrFriend[varFriend[i]]["Time"] = varTime
    EndSub
    
    'Ask the user if the names and details are correct
    Sub Correct
      For i = 1 To 5 Step 1
        varWriting[1] = Shapes.AddText("Name: "+arrFriend[varFriend[i]]["Name"])
        Shapes.Move(varWriting[1],i*32,16)
        varWriting[2] = Shapes.AddText("Phone Number: "+arrFriend[varFriend[i]]["Phone"])
        Shapes.Move(varWriting[2],i*48,48)
        varWriting[3] = Shapes.AddText("Email Address: "+arrFriend[varFriend[i]]["Email"])
        Shapes.Move(varWriting[3],i*72,72)
      EndFor
      varAnswer = Text.ConvertToLowerCase(TextWindow.Read())
      If (varAnswer = "yes") Then
        TextWindow.WriteLine("Good!")
      ElseIf (varAnswer = "no") then
        EnterPerson()
      Else
        TextWindow.WriteLine("I don't understand!")
        EnterPerson()
      EndIf
      EndSub
      
    
    'Let the user see the record in the array
    GetFriend()
    
    'Allow user to type in a friend's name and see their record/edit a friend's record
    Sub GetFriend
      TextWindow.WriteLine("Would you like to Edit, View a friend's record, or Leave? (E/V/L)")
      varChoice = Text.ConvertToUpperCase(TextWindow.Read())
    
      'Viewing a friend's record
      If (varChoice = "V") then
        ViewFriend()
        
      'Editing a friend's record
      ElseIf (varChoice = "E") then
        EditFriend()
        
      'Leaving game
      elseif (varChoice = "L") then
        TextWindow.WriteLine("Thank you for visiting!")
        TextWindow.Pause()
        
      'If computer does not understand message
      Else
        TextWindow.WriteLine("I don't understand!")
        GetFriend()
      EndIf
    EndSub
    
    
    'The subroutine to get view a friend's record.
    Sub ViewFriend
      TextWindow.WriteLine("What friend: ")
      varFriendNew = Text.ConvertToLowerCase(TextWindow.Read())
      If (Array.ContainsIndex(arrFriend,varFriendNew)) Then
        TextWindow.WriteLine("Phone: "+arrFriend[varFriendNew]["Phone"])
        TextWindow.WriteLine("Email: "+arrFriend[varFriendNew]["Email"])
        TextWindow.WriteLine("Time of entry: "+varTime)
        GetFriend()
      Else
        TextWindow.WriteLine("I don't understand...")
        GetFriend()
      EndIf
    EndSub
      
    'The subroutine to edit a friend's record
    Sub EditFriend
      TextWindow.WriteLine("What friend: ")
      varFriendNew = Text.ConvertToLowerCase(TextWindow.Read())
      If (Array.ContainsIndex(arrFriend,varFriendNew)) then
        TextWindow.WriteLine("Their phone: ")
        varPhone = TextWindow.Read()
        arrFriend[varFriendNew]["Phone"] = varPhone
        TextWindow.WriteLine("Their email: ")
        varEmail = TextWindow.Read()
        arrFriend[varFriendNew]["Email"] = varEmail
        GetFriend()
      Else
        TextWindow.WriteLine("I don't understand...")
        GetFriend()
      EndIf
    EndSub 
      
    'Clear the text boxes
    Sub Clear
      For i = 0 To 3 Step 1
        Controls.SetTextBoxText(varTextBox[i],"")
      EndFor
    EndSub
      
    'When pressing the confirm button
    While ("True")
      If (varEvent = "Enter") Then
        EnterPerson()
        varEvent = 0
      EndIf
    EndWhile  
    
    Sub MakeBoxes
      For i = 0 To 3 Step 1
        varTextBox[i] = Controls.AddTextBox(0,i*32)
      EndFor
    EndSub
      

    Sorry if that's a lot of code :(

    This is a huge problem and I need a response to fix it urgently! Please help!

    Thank you for reading,

    Greenio3



    • Edited by Greenio3 Wednesday, November 6, 2013 11:47 PM
    Wednesday, November 6, 2013 11:45 PM

Answers

  • This line is throwing the exception:

    varMessage = Shapes.AddText("")

    Add GraphicsWindow.Show() to avoid the bug. Or even better, remove those Shapes & Control lines, since your program uses TextWindow only!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, November 7, 2013 12:41 AM
    Answerer

All replies

  • This line is throwing the exception:

    varMessage = Shapes.AddText("")

    Add GraphicsWindow.Show() to avoid the bug. Or even better, remove those Shapes & Control lines, since your program uses TextWindow only!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, November 7, 2013 12:41 AM
    Answerer
  • Yeah, for Shapes.AddText you need to show or set a GW property for it to work (except GW.Hide). Invoke a target.

    If you want to have a TW and a GW open you could put

    GraphicsWindow.Show()
    TextWindow.Show()

    at the start.

    In that order that'll put TW on top of GW. Then you can position them on the Desktop using TW.left/top etc.

    Thursday, November 7, 2013 4:40 AM
    Moderator
  • The above is a known bug for some GraphicsWindow Add operations, but the workaround works fine.
    Sunday, November 10, 2013 5:40 PM
    Moderator
  • Great and thanks!!  This solved a problem I was having too.
    • Proposed as answer by Rizdek Saturday, January 18, 2020 3:52 PM
    • Unproposed as answer by Rizdek Saturday, January 18, 2020 3:52 PM
    Saturday, January 18, 2020 3:51 PM