473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help?

First off - I'm new at this so I'm sorry up front if I ask - dumb Q's

I'm trying to learn VB 6
Trying to put together a hangman game.
I'm working with a textbox, command button. and some labels as well as a few variables.

Private Sub Form_Load()
Dim Correct As Boolean
Dim x% 'use as counter
Dim SecretWord(8, 2)
'load secret word as an array
SecretWord(1, 1) = "L"
SecretWord(2, 1) = "E"
SecretWord(3, 1) = "A"
SecretWord(4, 1) = "R"
SecretWord(5, 1) = "N"
SecretWord(6, 1) = "K"
SecretWord(7, 1) = "E"
SecretWord(8, 1) = "Y"


For x% = 1 To 8
SecretWord(x, 2) = "*"
Label1.Caption = Label1.Caption & SecretWord(x, 2)
Next
End Sub

Private Sub Command1_Click()
Dim x%
Static Guesses As Integer
Dim SecretWord(8, 2)
Dim Correct As Boolean
Correct = False

Text1.SetFocus
Text1.SelLength = Len(Text1.Text)

For x = 1 To 8
If Text1.Text = SecretWord(x, 1) Then
SecretWord(x, 2) = SecretWord(x, 1)
Correct = True
End If
Next
If Correct = False Then
Guesses = Guesses + 1
Label2.Caption = Guesses
End If
End Sub
I can't get The correct guesses in the TextBox to appear in the (x,2) of my array
and I can't set focus to my Text1.Text
I'm trying to use a multdemensional array
Thanks, Jim
Jan 3 '07 #1
2 988
willakawill
1,646 1GB
First off - I'm new at this so I'm sorry up front if I ask - dumb Q's

I'm trying to learn VB 6
Trying to put together a hangman game.
I'm working with a textbox, command button. and some labels as well as a few variables.

Private Sub Form_Load()
Dim Correct As Boolean
Dim x% 'use as counter
Dim SecretWord(8, 2)
'load secret word as an array
SecretWord(1, 1) = "L"
SecretWord(2, 1) = "E"
SecretWord(3, 1) = "A"
SecretWord(4, 1) = "R"
SecretWord(5, 1) = "N"
SecretWord(6, 1) = "K"
SecretWord(7, 1) = "E"
SecretWord(8, 1) = "Y"


For x% = 1 To 8
SecretWord(x, 2) = "*"
Label1.Caption = Label1.Caption & SecretWord(x, 2)
Next
End Sub

Private Sub Command1_Click()
Dim x%
Static Guesses As Integer
Dim SecretWord(8, 2)
Dim Correct As Boolean
Correct = False

Text1.SetFocus
Text1.SelLength = Len(Text1.Text)

For x = 1 To 8
If Text1.Text = SecretWord(x, 1) Then
SecretWord(x, 2) = SecretWord(x, 1)
Correct = True
End If
Next
If Correct = False Then
Guesses = Guesses + 1
Label2.Caption = Guesses
End If
End Sub
I can't get The correct guesses in the TextBox to appear in the (x,2) of my array
and I can't set focus to my Text1.Text
I'm trying to use a multdemensional array
Thanks, Jim
Hi Jim
First of all the secretword array in form load only has scope in that sub. Once you reach the end of the sub it disappears. If you are going to use it throughout the game you will need to declare it outside a sub at the top of your code like this:

Expand|Select|Wrap|Line Numbers
  1. Public SecretWord(7)(1) As String
In vb declarations of arrays the number represents the upper bound or the highest index number that you can use. The first index is 0 so putting 7 gives you 8 elements. you can now reference this array anywhere in your code.

Good luck
Jan 3 '07 #2
Killer42
8,435 Expert 8TB
Just a couple of things to keep in mind.
  • I think willakawill has got the VB syntax mixed up with C or Java. :) If the (7)(1) syntax won't compile try using a comma, as you've done elsewhere.
  • You can't create a public variable (or array) like this in a form. If you want it available to everything in the project, use the Public declaration but put it in a module. If you just want it available within the form, declare it at the top of the form and use Private rather than Public.
  • As for the "0/1 to 7/8" thing, be aware that this is largely a matter of personal preference. It defaults to 0 as the base, but if you prefer you can use the Option Base statement to say that arrays should begin at 1. Personally, I prefer to specify both upper and lower bounds. For example Public SecretWord(1 To 8, 1 To 2) As String
Jan 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.