locked
Tic Tac Toe help RRS feed

  • Question

  • I have made a tic tac toe board and when i go to debug the application i get a "NullReferenceException was unhandled".
    this happens diring this part of the code: 
    Dim x As Integer = Val(index.Chars(0))
    and i was wondering if anyone knew how to fix this.
    thanks
    Wednesday, June 3, 2009 8:51 PM

Answers

  • you cant use the text bcos you dont want the player see the value
    kaymaf 
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    • Marked as answer by muskoka17 Wednesday, June 3, 2009 10:03 PM
    Wednesday, June 3, 2009 9:56 PM
  • but it is not assigning the value to tag anywhere

    either he has to assign the value .tag not to .text
    • Marked as answer by muskoka17 Wednesday, June 3, 2009 10:03 PM
    Wednesday, June 3, 2009 9:59 PM
  • That was the problem, it needed to be .Tag, not .Text.
    THANKS SO MUCH EVERYONE
    • Marked as answer by muskoka17 Wednesday, June 3, 2009 10:03 PM
    Wednesday, June 3, 2009 10:00 PM

All replies

  • Most likely, the problem is with index. Is it a string? Is it empty?


    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Wednesday, June 3, 2009 9:01 PM
  •   'store moves in chrTTT
                Dim index As String
                index = btnSquareClicked.Tag
                Dim x As Integer = Val(index.Chars(0))
                Dim y As Integer = Val(index.Chars(2))
                Call StoreMove(x, y, player, chrTTT)
    i think the string is empty, but i attached the code so you could see.
    thanks
    Wednesday, June 3, 2009 9:07 PM
  • Are you putting values into the .Tag property somewhere?

    You can do this in the designer (in the Properties window) or in the code somewhere.
    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Wednesday, June 3, 2009 9:26 PM
  • how would i do this?
    would i click on the btn00, lets say, then go to the properties window and find the .Tag property and add a value? or what?
    Wednesday, June 3, 2009 9:31 PM
  • yes property of btnSquareClicked

    if run time then use btnSquareClicked.tag = "MyTag"

    or in design time
    Wednesday, June 3, 2009 9:33 PM
  • but i dont have a btnsquareclicked button. i only have 9 buttons,
    00,01,02
    10,11,12
    20,21,22
    they are labelled as btn00, btn01, etc.
    how should i make this btnsquarclicked?
    Wednesday, June 3, 2009 9:36 PM
  • then why you are assigning value of btnSquareClicked to index

    in your code you wrote

    'store moves in chrTTT
    Dim index As String
    index = btnSquareClicked.Tag
    Dim x As Integer = Val(index.Chars(0))
    Dim y As Integer = Val(index.Chars(2))
    Call StoreMove(x, y, player, chrTTT)
    why you have index = btnSquareClicked.tag

    if you want to use other button then give the name of that button. for example btn00

    'make sure btn00.tag has some value in design time

    dim index as string
    index = btn00.tag



    Wednesday, June 3, 2009 9:39 PM
  • you double post the same question http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/cbf988aa-e356-46c9-9508-5c6402b281cc

    Dim x As Integer = Val(index.Chars(0))

    if your tag  is btn00
    now, your Val(index.Chars(0)) = 'b' and b is char  (character) and you cannot assign it to integer

    You may change it
     Dim x As Integer = Val(index.Chars(3)) 'this will give  you 0
     Dim y As Integer = Val(index.Chars(4)) 'this will give you 0
     Now x,y=(0,0)

    kaymaf



    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Wednesday, June 3, 2009 9:41 PM
  • this code if from a book that helps teach you VB, and it uses that name, and on the interface there is only 9 buttons. this is why i am confused and i dont understand VB that well at all
    Wednesday, June 3, 2009 9:44 PM
  • i think you need to use btnSquareclicked.text rather btnSquareclicked.tag
    Wednesday, June 3, 2009 9:49 PM
  • you cant use the text bcos you dont want the player see the value
    kaymaf 
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    • Marked as answer by muskoka17 Wednesday, June 3, 2009 10:03 PM
    Wednesday, June 3, 2009 9:56 PM
  • but it is not assigning the value to tag anywhere

    either he has to assign the value .tag not to .text
    • Marked as answer by muskoka17 Wednesday, June 3, 2009 10:03 PM
    Wednesday, June 3, 2009 9:59 PM
  • That was the problem, it needed to be .Tag, not .Text.
    THANKS SO MUCH EVERYONE
    • Marked as answer by muskoka17 Wednesday, June 3, 2009 10:03 PM
    Wednesday, June 3, 2009 10:00 PM
  • yeah....good for you.. njoy


    Wednesday, June 3, 2009 10:02 PM