I need help with my hangman program.... i am trying to make this load using control arrays at run time... can someone please tell me if the file i have attached uses control arrays that load at runtime? and if it doesnt can you please tell me what i have to do to make it have control arrays at runtime...
the sooner the better...thank you.
Last edited by coder500; Dec 7th, 2005 at 08:07 PM.
can someone please tell me if the file i have attached uses control arrays that load at runtime?
No. The form doesn't uses control array at runtime.
Originally Posted by coder500
what i have to do to make it have control arrays at runtime...
The easiest method may be, 1. Add a control during designtime. 2. From Properties window, change it's Index = 0. This will make it the first element of the control array. 3. Now from code you can add new elements using the Load statement. (see the code below) 4. Please read the documentation of Load, UBound, LBound, Count, Item methods/properties from MSDN.
--------------------
The following code places a new Textbox (control array element) at random places on the form
VB Code:
'Place this code in a form and add a CommandButton and a TextBox
'Change the TextBox's Index to 0
Private Sub Command1_Click()
Load Text1(Text1.UBound + 1) 'Loads new control array element
With Text1(Text1.UBound)
.Left = CInt((Me.Width + 1) * Rnd) 'Set a random Left
.Top = CInt((Me.Height + 1) * Rnd) 'Set a random Top
.BackColor = QBColor(CInt((15 * Rnd))) 'Random background color
Text1(Text1.UBound).Left = CInt((Me.Width + 1) * Rnd) 'Set a random Left
Text1(Text1.UBound).Top = CInt((Me.Height + 1) * Rnd) 'Set a random Top
Text1(Text1.UBound).BackColor = QBColor(CInt((15 * Rnd))) 'Random background color
Text1(Text1.UBound).Visible = True 'Do not forget this
End Sub
Realy ugly. isn't it ?
To do the same thing using For loop, you'll need to have a counter and loop until that counter reaches it's limit. All your array-element-adding code will be inside For loop.
With statements make my code very readable and all. But awhile back, I also did a performance test on it, and it executes a little slower using With's than without using them.
bruce your code is a step in the right direction but it is not putting the right number of boxes for instance... i put in the word coder and it only added one box...
bruce your code is a step in the right direction but it is not putting the right number of boxes for instance... i put in the word coder and it only added one box...
No probs,
Determine the length of the word (using Len()) and use that amount to generate the number of additional TextBox's...
No offense, but I think you may want to start with something a little easier (than hangman), as this will become more complicated. You must have a solid grounding first
However, if you must persist; you never mentioned that the number of TextBox's was
related to the input word. Is that the case? Better yet provide a detailaled prase
of what you want to acheive.
thanks for that... now i need to know how to make the txtguess field to work... and show the guesses in a pic box as well as make the correct guesses show up in the correct txtbox that was created by the code above
thanks for that... now i need to know how to make the txtguess field to work... and show the guesses in a pic box as well as make the correct guesses show up in the correct txtbox that was created by the code above
Hehe, now its time for some effort on your part
Give it a go, and if you get stuck just ask.
put your idea of how it should work on paper (flow diagram) and then try it with code.
bruce thanks for all your help... i just dropped you a pm... it may be easier if we discuss this on MSN...if you have msn please pm me your address so we can talk... thanks
PM received. Don't have MSN here unfortunatly. However...... do a search on this Forum for HangMan as there a few examples, that may give you some ideas/methods etc.
Just outa curiosity, if you are doing this for school, why would you guys be given a task that is beyond the current competency level (not singling you out mind you).
bruce...we are on chapter 7 of the book... and this is not beond the current competency level... the problem is... I dont understand this stuff easily and as a result I am not about to do the assignments without getting help.. but my friend who usually helps me has been really busy lately with college and work so i can not get his help on this one... anyways.. i will look at some other threads.. and see what i comeup with...
ill post in a little while with my ideas... thanks again for all your help
that version you posted wont run on my pc cause i have macros disabled...but... i think this thread will help me...
i know that i need to have counters for the wrong guesses and the correct guesses... as well as have that word stored... now i just need to figure out how to make the stuff print in the location i mentioned...if correct... the guess should show up in a picDisplay and the correct location in the txt fields... if incorrect then it should show up in a picDisplay and show the next body part of the man being hung...
give me 30 or so minutes to try to code this... and then ill post again..
bruce... thanks again for all your amazing help... I was able to get that code working... and then my friend was able to find time to help me finish the rest of the stuff up.. thank you again for your time..