4 Replies - 1828 Views - Last Post: 16 December 2012 - 01:09 PM Rate Topic: -----

#1 mitchstokes225  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-November 09

Random Button Clicking Game Issues, Code help needed.

Posted 16 December 2012 - 11:01 AM

For my final project I am trying to do a random click game where you have 16 cards laid out on the screen. You click on your guess. Once you click you get a message if you won or where the winning card was. But I just can't get it to work. My cards when I run the program don't even display the card faces. Attached is the layout of the program.


I can't get this command stuff to work. I just can't get it.
Here is my code.

Public Class Form1

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        MsgBox("The point of this game is to Guess which card is the winner.  The winning card is randomly chosen by the computer.")
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim n As Integer
        Dim Command1 As Integer
    For n = 0 To 15
        Command1(n).Caption = ""
    Next
        Randomize(n)
    n = Int(Rnd * 16)
    If Index = n Then
        Command1(n).Caption = "Prize"
    Else : Command1(n).Caption = "The Prize is here!"
    End If

    End Sub
End Class

Attached image(s)

  • Attached Image

This post has been edited by mitchstokes225: 16 December 2012 - 11:02 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Random Button Clicking Game Issues, Code help needed.

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Random Button Clicking Game Issues, Code help needed.

Posted 16 December 2012 - 11:26 AM

View Postmitchstokes225, on 16 December 2012 - 12:01 PM, said:

For my final project I am trying to do a random click game where you have 16 cards laid out on the screen. You click on your guess. Once you click you get a message if you won or where the winning card was. But I just can't get it to work. My cards when I run the program don't even display the card faces. Attached is the layout of the program.


I can't get this command stuff to work. I just can't get it.


"I can't get it" doesn't cut it for a question - ESPECIALLY for homework and your final project to boot.

We're not writing your final project for you. And we're not blindly debugging it for you. Or rearchitecting your entire design. If you have a specific question then ask it.


mitchstokes225: What this shows us is that you aren't familiar with breakpoints and how to debug your own code.


tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated DEC 2012
Spoiler




My normal reply would have been

Quote

"I don't know where to start" - This usually means you should go back to your instructor and admit you are this lost. Don't bluff your way through this course thinking that by chapter 10 it will all suddenly snap into place and become clear. It won't. Unlike history class where chapter 1 might be 17th century England and chapter 2 might be World War II, giving you a fresh start - Coding builds upon the lessons of the previous chapter. You have to use lesson 1 material to succeed in lesson 2. Chapter 10 builds upon and uses material from chapter 9. If you let your pride get in the way you will be too lost to recover and have wasted thousands of dollars in tuition.


But it's too late for that - This is your final project. We can't teach you everything you've failed to pick up in the course.

If you've made it through the entire year to this point and NONE of what you've written works and you're just totally lost and 'don't get it', then you might reconsider if this is the right career path for you - or if maybe you just need to repeat the course, pay closer attention, work harder, get in the instructor's face when you are lost, go through a few "Learn VB.NET in 30 days" books before you restart the course... etc.
Was This Post Helpful? 0
  • +
  • -

#3 mitchstokes225  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-November 09

Re: Random Button Clicking Game Issues, Code help needed.

Posted 16 December 2012 - 11:38 AM

I was able to get my cards to show. It was the way I had the code for the button click. I Fixed that.

I'm now working this angle. I just need to know if I'm moving in the right direction. I've been through a lot of tutorials trying to get this to work, but like most things the help is vague at best.

 Private Sub Command1_Click(ByVal Index As Integer)
        Randomize()
        Dim button() As Control = {Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9, Button10, Button11, Button12, Button13, Button14, Button15, Button16}
        Dim n As Integer
        Dim Command1 As 
        For n = 0 To 15
            Command1(n).Caption = ""
        Next
        n = Int(Rnd() * 16)
        If Index = n Then
            Command1(n).Caption = "Prize"
        Else : Command1(n).Caption = "The Prize is here!"
        End If
    End Sub



The only issue now, is that I get an error with Command1 not being declared. I'm don't know what to declare it as.

As for a career path, I have no desire to write code for a living. I am actually a Quality Assurance Analyst, and think that getting my degree in Computer Science Technology will be a benefit. Unfortunately for me and probably all of you that I look to for a little help,(not a lecture) on the direction that I might be taking in my code, they don't offer a degree in Quality Assurance.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Random Button Clicking Game Issues, Code help needed.

Posted 16 December 2012 - 12:33 PM

Quote

06
       For n = 0 To 15


Get out of this bad habit of hard-coding values that you can easily get dynamically.

Since you have this

Quote

03       Dim button() As Control

you can just reference Control.Length to get the size of hte array.

You should also avoid using reserved names like Control as variable names. It will bite you in the arse. myButtonArray would tell you more and have less chance of a conflict.

Quote

The only issue now, is that I get an error with Command1 not being declared. I'm don't know what to declare it as.

Then what exactly were you thinking it was when you wrote this code? *DID* you write this code?

Reusing names is killing you. Command1 is already a GUI control (button?)

Quote

01
Private Sub Command1_Click

Then you are also treating it like an array
11           Command1(n)


I think you really need to just STOP. Re-think all of this. use some decent names that don't confuse yourself. More planning BEFORE typing.
Was This Post Helpful? 0
  • +
  • -

#5 mitchstokes225  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-November 09

Re: Random Button Clicking Game Issues, Code help needed.

Posted 16 December 2012 - 01:09 PM

Well in my research it looked like using a command button control would be the answer on how to click on any of the buttons on the screen and have it check against if it was the randomly set button or not. But I can't find a good walk through on how to do command button controls, (or something I can understand at least). So that was the thinking behind a command.

I'm going to step away for a bit, then come back and try to rethink it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1