doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
Go Back  Xtreme Visual Basic Talk > > > doing pretty good so far... {place buttons randomly}


Reply
 
Thread Tools Display Modes
  #1  
Old 09-19-2004, 08:16 PM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default doing pretty good so far... {place buttons randomly}


I've created a spelling game for my little girl and I was wondering how to have the buttons randomly placed on the window within a certain constraint. I have the buttons across the bottom, I'd like to have them "jumbled" each time she opens it and also with each word she has to spell.

TIA,
A.
Reply With Quote
  #2  
Old 09-20-2004, 10:31 AM
Iceplug's Avatar
Iceplugdoing pretty good so far... {place buttons randomly} Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

If you know the size of the buttons, then you can generate a random number for both the Left and Top properties of the buttons.

Since the button has a width, the available range of values for the button's left so that it will be totally visible is 0 To Me.ClientSize.Width - Thebutton.Width
So, with the random number generator, you'd do this.

'Ri is the System.Random that you are using to create random numbers.
Thebutton.Left = Ri.Next(Me.ClientSize.Width - Thebutton.Width)

For the Top, replace all widths with heights.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 09-20-2004, 07:34 PM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

Quote:
Originally Posted by Iceplug
If you know the size of the buttons, then you can generate a random number for both the Left and Top properties of the buttons.

Since the button has a width, the available range of values for the button's left so that it will be totally visible is 0 To Me.ClientSize.Width - Thebutton.Width
So, with the random number generator, you'd do this.

'Ri is the System.Random that you are using to create random numbers.
Thebutton.Left = Ri.Next(Me.ClientSize.Width - Thebutton.Width)

For the Top, replace all widths with heights.
Thanks for pointing me in the right direction Ice. But, if all 3 buttons "top lefts" start at 16,24 - 136,24 - 256,24. Would it be easier for me to create a variable that has 16, 136, and 256 as the #'s that allow me to "jumble" the buttons? I think maybe that's what you were trying to tell me had I given you enough information on my first post.

Thanks again...I'll look forward to your answer,
A.
Reply With Quote
  #4  
Old 09-20-2004, 08:59 PM
Iceplug's Avatar
Iceplugdoing pretty good so far... {place buttons randomly} Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

The slope of the ".Top" three values that you have presented is 120 (meaning that you add 120 to get to the next in the list).
The first .Top value is 16, so you can generate their Top values like this:

YourButton.Top = 120 * Ri.Next(3) + 16

And you can see when Ri returns 0, Top is 16, when Ri returns 1, Top is 136, and when Ri is 2, Top is 256 .
Don't forget to set the YourButton.Left to 24.

Another method of doing this is to use Select Cases

Dim X As Integer = Ri.Next(3)
Select Case X
Case 0
YourButton.Top = 16
YourButton.Left = 24

This way doesn't require you to define an equation for the locations, but can get time-consuming when you get too many values to coordinate the left and top by.

Just like a Detour on the Amazing Race, you have two options, each with their pros and cons .
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 09-21-2004, 08:20 AM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

Quote:
Originally Posted by Iceplug

YourButton.Top = 120 * Ri.Next(3) + 16

I like the formulaic (is that a word? ) one. But I have another dumb question, this formula would go in the "Windows Form Designer" code?

A.
Reply With Quote
  #6  
Old 09-21-2004, 11:21 AM
Iceplug's Avatar
Iceplugdoing pretty good so far... {place buttons randomly} Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

That would go in the Form_Load event. The only things that go in the Windows Form Designer block are stuff that you want to appear when you are editing the form in the designer (you should almost never have to change anything in it).

You'd also have to instantiate the random number generator Ri and you cannot do that in WFD (Windows Form Designer, not Weapons of Fast Destruction ).

P.S. Formulaic is a word.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #7  
Old 09-22-2004, 07:23 PM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

Quote:
Originally Posted by Iceplug
That would go in the Form_Load event. The only things that go in the Windows Form Designer block are stuff that you want to appear when you are editing the form in the designer (you should almost never have to change anything in it).

You'd also have to instantiate the random number generator Ri and you cannot do that in WFD (Windows Form Designer, not Weapons of Fast Destruction ).

P.S. Formulaic is a word.

thanks Ice...I'll jump on it as soon as I can, got distracted by a little something called "work" Who invented it anyway? LOL Anyhow, I'll try to jump back on it ASAP, of course at this rate my little girl will be in High School before I get this going....
A.
Reply With Quote
  #8  
Old 09-22-2004, 10:51 PM
Iceplug's Avatar
Iceplugdoing pretty good so far... {place buttons randomly} Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

lol You'll get it done before then.
Do you have any other things to put in the program?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #9  
Old 09-22-2004, 11:06 PM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

Quote:
Originally Posted by Iceplug
lol You'll get it done before then.
Do you have any other things to put in the program?

WELL.... since you asked...I really want to make this data dynamic...I'm still a newbie but trust me, I really want to learn this.... I think I'd have to make a Class right? & put the data, I'm guessing here, in a "Select, Case" arrangement and as each instance is renewed it looks thru the Select, Case (I hope that's right) and displays the data in a way "the user" (heehee...yea, I'm tooting my own horn there ) will have a different set of words to do....of course they're all going to be 3 (maybe a few 4) letter words for now.

oh yea, that "instantiate" thing....can I ask? is it going to be something along the lines of:
Dim Ri as Short

I'm really trying to learn here...so all your help is unquestionably great...and I will be a good student....
A.
Reply With Quote
  #10  
Old 09-22-2004, 11:09 PM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

oh yea...I'm sorry I just couldn't wait to do this, but I added a toolbar (with freakin icons!!) and a mainMenu....

A.
Reply With Quote
  #11  
Old 09-23-2004, 12:05 AM
Iceplug's Avatar
Iceplugdoing pretty good so far... {place buttons randomly} Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

The declaration for Ri:
Dim Ri As Random

and then
Ri = New Random

So, what data do you want to make dynamic? The word that you are loading?
You can possibly make an array and fill it with three letter words,
then use Ri to pick a random word from this array.

From there, you can get the letters of the word by using .SubString (0 for the first letter, 1 for the second, and 2 for the third... of course the length would be 1).

Quote:
Originally Posted by mj0lnr
oh yea...I'm sorry I just couldn't wait to do this, but I added a toolbar (with freakin icons!!) and a mainMenu....

A.
LOL.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #12  
Old 09-23-2004, 12:12 AM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

all right, I'm close....this is what I have so far, but it doesn't show all three buttons....only one at a time...

Code:
    Private Sub Jumble()
        Dim Ri As Random = New Random()

        Button1.Top = 120 * Ri.Next(3) + 16
        Button1.Left = 24
        Button1.Text = "D"
        Button2.Top = 120 * Ri.Next(3) + 16
        Button2.Left = 24
        Button2.Text = "O"
        Button3.Top = 120 * Ri.Next(3) + 16
        Button3.Left = 24
        Button3.Text = "G"
    End Sub
I tried it bunch of different ways, but no dice (a 3 sided die would be nice here) Anyhow, please impart your wisdom....& I'm looking forward to your answer on creating a class. I think I could use your Select,Case ri.next = x
hmmm...just thought of something, I know it's boring, but why not just use the same #'s for my .top slope? Button1.top will always be 256 and button2.top will always be 16 and button3.top will always be 16...or is there an easy solution? too much coffee this late at night!!!!

A.
Reply With Quote
  #13  
Old 09-23-2004, 12:19 AM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

Quote:
Originally Posted by Iceplug
So, what data do you want to make dynamic? The word that you are loading?
You can possibly make an array and fill it with three letter words,
then use Ri to pick a random word from this array.

From there, you can get the letters of the word by using .SubString (0 for the first letter, 1 for the second, and 2 for the third... of course the length would be 1).
oh really? now that's sounds saucy! an array! I think I get the concepts of arrays...so, that's just a matter of time to figure out, but that .Substring... sorry, you lost me....I think I understand what you're trying to say...

A.
Reply With Quote
  #14  
Old 09-23-2004, 12:30 AM
Iceplug's Avatar
Iceplugdoing pretty good so far... {place buttons randomly} Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Let's go back to the buttons.
You need to stop Ri.Next from returning the same number (if it generates 1 for each turn, the buttons will all be on top of each other).

In order to do that, you'd have to do something like this (like card pulling).
(Just like a Detour on Amazing Race, again)

Follow the comments:
Code:
'We create an arraylist to put the numbers that we are going to use in. Dim AL As ArrayList = New ArrayList(3) Dim X As Integer 'This will hold the index of the number 'that we have selected from the arraylist. AL.Add(0) AL.Add(1) AL.Add(2) 'Add these numbers to the arraylist. 'And then: X = Ri.Next(AL.Count) 'Draw a "card" from the arraylist. Button1.Top = 120 * Convert.ToInt32(AL.Item(X)) + 16 'Apply the number. AL.RemoveAt(X) 'Remove the number at this index from the array. 'Continue for Buttons2 and 3. '0 1 2 - if Ri returned 0, you would get the element #0 (first), which happens to be 0 also. '0 is removed, leaving you with 1 2. 'If Ri returns 1 this second time (it cannot return two 'because AL.Count is 2 at this time), it gets element #1 (second), which happens 'to be 2. 'Ri will have to give you 0 for the last time, which will be the last number in the 'arraylist (1).

Or, you can use a full-on combinational index random number thingy (this one is good for small quantities of random numbers... in this case 3 is the number of random numbers you are generating.)
Follow the comments:
Code:
Dim X As Integer = Ri.Next(6) 'This is x! (x factorial), the product of all numbers 'equal and less than the x number. Select Case X 'And then, you have to determine the sets. Case 0 'Button 1: 2, Button 2: 1, Button 3: 0 - buttons in reverse order. Button1.Top = 256 'I have just replaced Ri.Next(3) here with 2 and solved. Button1.Left = 24 Button1.Text = "D" Button2.Top = 136 '120 * 1 + 16 Button2.Left = 24 Button2.Text = "O" Button3.Top = 16 '120 * 0 + 16 Button3.Left = 24 Button3.Text = "G" 'For Cases 1 to 5, you would pick a different combination of these values, namely: 0-1-2, 0-2-1, 1-0-2, 1-2-0, 2-0-1, and I just did 2-1-0 here.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #15  
Old 09-23-2004, 11:50 AM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

Quote:
Originally Posted by Iceplug
Code:
Dim X As Integer = Ri.Next(6) 'This is x! (x factorial), the product of all numbers 'equal and less than the x number. Select Case X 'And then, you have to determine the sets. Case 0 'Button 1: 2, Button 2: 1, Button 3: 0 - buttons in reverse order. Button1.Top = 256 'I have just replaced Ri.Next(3) here with 2 and solved. Button1.Left = 24 Button1.Text = "D" Button2.Top = 136 '120 * 1 + 16 Button2.Left = 24 Button2.Text = "O" Button3.Top = 16 '120 * 0 + 16 Button3.Left = 24 Button3.Text = "G" 'For Cases 1 to 5, you would pick a different combination of these values, namely: 0-1-2, 0-2-1, 1-0-2, 1-2-0, 2-0-1, and I just did 2-1-0 here.
I think I'll stick with the Select,Case....and that was a boost I needed...thanks Ice.....but I do have some more questions....when I created the toolbar and menuitem....a couple of things came to light, namely how do I resize my toolbar with icons so that it's "kindergarten" legible? I want "big chief" buttons. And, I have to ask, on my menuitem (which I'm taking out, cuz I decided if she can't read, how is she going to know what "File,New" does?). But, on "File,New" what is the syntax for that? it's not Call Form1_Load is it? I thought it would be cool like Me.Reload. Anyway, I can't wait to finish this thing and post it here somewhere to be dissected by you guys. I hope you don't mind, but I'm going to pilfer your code above....

Adios,
A.
Reply With Quote
  #16  
Old 09-23-2004, 01:13 PM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

alright Ice...it works! BUT, I think I am going to have to use that array. Reason, I say that is because on just this word, D-O-G. D exists in 4 different spots, Button1.Text, Button1.Click, Label1.Text, and my If, Then statement that checks to see if Label1.Text is a D. Along with O, and G. Hooboy! How much did I say that card game cost again? I'd really like to figure this out on my own, so don't post how to do it until I'm about to give up in frustration....
I'll ask questions once I get started to tell if I'm doing things correctly or not....

A.
Reply With Quote
  #17  
Old 09-24-2004, 10:38 AM
Iceplug's Avatar
Iceplugdoing pretty good so far... {place buttons randomly} Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Pilfer away. That's the whole idea.
To do a new form, you simply do this:
Me.Hide
Dim F As yourform = New yourform
F.ShowDialog()
hide the current form and show a new instance of it.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #18  
Old 09-24-2004, 12:43 PM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

ok, this is what I have so far....I just haven't had time at the house to sit in front of my PC and try to make it work.....

I'm going to use the Ri.Next to call a random word out of my array
use some kind of text manipulation that breaks it into characters rather than a single word....define those characters as variables, use those variables in all the places they need to go. (Button1.click, label1.text, button1.text...) once the word is solved, call on that sub to do it all over again.....

am I on the right track?
A.
Reply With Quote
  #19  
Old 09-25-2004, 11:21 AM
Iceplug's Avatar
Iceplugdoing pretty good so far... {place buttons randomly} Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

That sounds pretty good.
Once again, you can use .SubString() to extract single characters from the word.

Dim H As String = "Tar"
MessageBox.Show(H.Substring(0, 1)) 'Shows T
MessageBox.Show(H.Substring(1, 1)) 'Shows a
MessageBox.Show(H.Substring(2, 1)) 'Shows r
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #20  
Old 09-27-2004, 12:45 PM
mj0lnr mj0lnr is offline
Newcomer
 
Join Date: Sep 2004
Location: San Antonio, TX
Posts: 22
Default

ya know Ice, the more I type, the more my head hurts...
Ok, I've swallowed my pride, can you get me started? Puh-lease??? I would love to learn from this experience, so anything you can post as far as things to get me started would immensely be appreciated....

A.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly} doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
 
doing pretty good so far... {place buttons randomly}
doing pretty good so far... {place buttons randomly}
 
-->