Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' Visual Basic Programming 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' Visual Basic Programming 24-Hour Trainer by Rod Stephens; ISBN: 978-0-470-94335-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' Visual Basic Programming 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 23rd, 2011, 12:15 AM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: Tennessee
Posts: 46
Thanks: 27
Thanked 0 Times in 0 Posts
Thumbs down Ex 2-1 TicTacToe

I finished the first example and then added a button to clear all the large labels. This isn't working because of my 'clear' line. Any suggestions or will I learn all about this later?? It also didn't work without the extra " marks.

code
Private Sub btnNewGame_Click(sender As System.Object, e As System.EventArgs) Handles btnNewGame.Click
' clear all lblTaken
For x = 0 To 2
For y = 0 To 2
"lblTaken"xy".text" = ""
Next y
Next x

End Sub
/code
Reply With Quote
  #2 (permalink)  
Old May 23rd, 2011, 09:02 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Unfortunately you can't use a string to name a control in this way.

Code:
"lblTaken"xy".text" = ""
There are several ways you can approach this. The easiest but least satisfying is to just clear them individually:

Code:
lblTaken00.Text = ""
lblTaken01.Text = ""
lblTaken02.Text = ""
...
Probably if you are going to turn this into a more realistic program, you would want to make an array holding the labels. Then you can loop through the array to clear them out. Arrays are described in Lesson 16, although I don't think that lesson revisits the Tic-Tac-Toe program.

The program would declare the array outside of any method:

Code:
Private Labels As Label(,)
When it starts, the program would initialize the array something like this:

Code:
Labels = New Label(,) _
{ _
    {lblTaken00, lblTaken01, lblTaken02}, _
    {lblTaken10, lblTaken11, lblTaken12}, _
    {lblTaken20, lblTaken21, lblTaken22} _
}
Later you can loop through the array like this:

Code:
For r As Integer = 0 To 2
    For c As Integer = 0 To 2
        Labels(r, c).Text = ""
    Next c
Next r
This is all getting pretty far ahead of the Tic-Tac-Toe program in Lesson 2 but perhaps later you can revisit this and see if you can make it work.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
zavodney (May 23rd, 2011)
  #3 (permalink)  
Old May 23rd, 2011, 02:57 PM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: Tennessee
Posts: 46
Thanks: 27
Thanked 0 Times in 0 Posts
Thumbs up Thank you.

OK, thank you. I can wait until later. Clearing each label individually was an option, but it wasn't a satisfying way to do it. Thank you.

Keith
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 05:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.