1. #1
    Titan Frozenbeef's Avatar
    Join Date
    Aug 2009
    Location
    Uk - England
    Posts
    11,203

    visual basic help?

    i'm creating a notes and crosses type game and i was just wondering if there was anyway for it to check if it's a draw... the rest of it works just the draw part :S

    i've tried the code below but it just does "conversion to type string to boolean is not valid"

    If btn_1.Text = "X" Or "O" And
    btn_2.Text = "X" Or "O" And
    btn_3.Text = "X" Or "O" And
    btn_4.Text = "X" Or "O" And
    btn_5.Text = "X" Or "O" And
    btn_6.Text = "X" Or "O" And
    btn_7.Text = "X" Or "O" And
    btn_8.Text = "X" Or "O" And
    btn_9.Text = "X" Or "O" Then
    MessageBox.Show("The Game is a draw !")
    counter = 0
    End If

    Any help would be great thx <3

  2. #2
    I am Murloc! Tiili's Avatar
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    5,404
    Are you using command buttons for it? o.o

    If so, shouldn't it be .caption instead of .text?
    Close your eyes and smile.
    [15:53] <PizzaSHARK> you have such a cute accent! ^_^

  3. #3
    The Lightbringer Istaril's Avatar
    Join Date
    Jun 2011
    Location
    Scotland. Freedom and So on.
    Posts
    3,250
    Which version of VB?
    Quote Originally Posted by Vizardlorde View Post
    Guns don't kill people deranged dogs and cooking ovens kill people.
    Quote Originally Posted by lockedout View Post
    We went to Iraq in search of WMD's but found none. I guess they dont have pressure cookers over there : (

  4. #4
    Herald of the Titans Maharishi's Avatar
    Join Date
    May 2010
    Location
    Boston, Mass
    Posts
    2,922
    I don't know Vbasic, but it would seem your use of "or" is odd in this context. I would assume you need to do
    Code:
    btn_2.Text = "X" Or  btn_2.Text = "O"
    As it is, it would seem your statement reads "if (text) = "X" is true or if "O" is true", your asking it if the letter "O" is a true statement (thus conversion from string to bool error)

    Again, I don't know vsbasic at all, so i may be wrong.

  5. #5
    Titan Frozenbeef's Avatar
    Join Date
    Aug 2009
    Location
    Uk - England
    Posts
    11,203
    it got further than it did last time but now it says its a draw after every turn :S

    ---------- Post added 2011-12-09 at 05:41 PM ----------

    Quote Originally Posted by Istaril View Post
    Which version of VB?
    2010..... 10 characters

  6. #6
    Herald of the Titans Maharishi's Avatar
    Join Date
    May 2010
    Location
    Boston, Mass
    Posts
    2,922
    Quote Originally Posted by Frozenbeef View Post
    it got further than it did last time but now it says its a draw after every turn :S
    I mean, i can't really diagnose it without seeing it. Feel free to post the pertinent parts in [code][/code] tags, and I (or someone else) will look at it.

  7. #7
    I am Murloc! Tiili's Avatar
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    5,404
    Quote Originally Posted by Frozenbeef View Post
    it got further than it did last time but now it says its a draw after every turn :S

    ---------- Post added 2011-12-09 at 05:41 PM ----------



    2010..... 10 characters
    Uh, isn't that vb.net?
    Close your eyes and smile.
    [15:53] <PizzaSHARK> you have such a cute accent! ^_^

  8. #8
    Herald of the Titans Maharishi's Avatar
    Join Date
    May 2010
    Location
    Boston, Mass
    Posts
    2,922
    Actually, it's probably just a problem from you stringing so many "and/or" statements together. It's ugly, and hard to parse (for me) logically.

    I'd just set up an integer counter that adds one every time a button is set, and have a "If button counter < 9 then do crap" as your check.

  9. #9
    Titan Frozenbeef's Avatar
    Join Date
    Aug 2009
    Location
    Uk - England
    Posts
    11,203
    K changed the lump of code to the following


    If counter = 9 Then
    MessageBox.Show("it is a draw")
    End If

    and it works :P

    thx very much <3

    ---------- Post added 2011-12-09 at 10:35 PM ----------

    Just another question...whats the difference between cdbl and cdec?

    i know they mean convert to double and convert to decimal....but whats the difference between the two? i thought double could store decimals?
    Last edited by Frozenbeef; 2011-12-09 at 10:35 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •