Results 1 to 8 of 8

Thread: help with random

  1. #1

    Thread Starter
    Hyperactive Member scsa20's Avatar
    Join Date
    Apr 2001
    Location
    Mars
    Posts
    456

    help with random

    Can someone tell me how I can make a button move to random spots on the form??


    p|-|34|2 /\/\3 f0|2 | $p34k 1337
    My TSS quote of the day: "If your haveing a bad day, just press the restart button."

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Code:
    Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim x1 As Long, y1 As Long
        x1 = Int(Rnd * (Width - Command1.Width))
        y1 = Int(Rnd * (Height - Command1.Height))
        Command1.Move x1, y1
    End Sub

  3. #3
    Junior Member
    Join Date
    Aug 2001
    Location
    Boston, MA
    Posts
    20

    here's an example

    I'm not sure if this is what you're looking for, but this function will randomly relocate a command button somewhere on a form:

    Private Sub moveButton(cntlButton As Control)

    Dim newX As Long
    Dim newY As Long

    Randomize

    newX = Int((Me.Width - cntlButton.Width - 150) * Rnd + 15)
    newY = Int((Me.Height - cntlButton.Height - 420) * Rnd + 15)

    cntlButton.Move newX, newY

    End Sub

    Private Sub Command1_Click()

    Call moveButton(Command1)

    End Sub

  4. #4

    Thread Starter
    Hyperactive Member scsa20's Avatar
    Join Date
    Apr 2001
    Location
    Mars
    Posts
    456

    Re: here's an example

    Originally posted by mstuehler
    I'm not sure if this is what you're looking for, but this function will randomly relocate a command button somewhere on a form:

    Private Sub moveButton(cntlButton As Control)

    Dim newX As Long
    Dim newY As Long

    Randomize

    newX = Int((Me.Width - cntlButton.Width - 150) * Rnd + 15)
    newY = Int((Me.Height - cntlButton.Height - 420) * Rnd + 15)

    cntlButton.Move newX, newY

    End Sub

    Private Sub Command1_Click()

    Call moveButton(Command1)

    End Sub
    can you *edited*clean*edited* that up alittle and tell me what that all do??

    btw...I want it to keep going to random spots non stop
    Last edited by scsa20; Sep 20th, 2001 at 12:19 AM.


    p|-|34|2 /\/\3 f0|2 | $p34k 1337
    My TSS quote of the day: "If your haveing a bad day, just press the restart button."

  5. #5

    Thread Starter
    Hyperactive Member scsa20's Avatar
    Join Date
    Apr 2001
    Location
    Mars
    Posts
    456
    Originally posted by Nucleus
    Code:
    Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim x1 As Long, y1 As Long
        x1 = Int(Rnd * (Width - Command1.Width))
        y1 = Int(Rnd * (Height - Command1.Height))
        Command1.Move x1, y1
    End Sub
    that code work, but how can I be able to make it not be able to use Tab to get over the button??


    p|-|34|2 /\/\3 f0|2 | $p34k 1337
    My TSS quote of the day: "If your haveing a bad day, just press the restart button."

  6. #6
    Junior Member
    Join Date
    Aug 2001
    Location
    Boston, MA
    Posts
    20
    If you use Nucleus' code (which is always a good idea), you can add the following to prevent the user from using [tab] to get to the button:

    Private Sub Command1_GotFocus()

    [some other object].SetFocus

    End Sub

    In other words, if the button you don't want the user to get is Command1, you can deflect the focus to another object (for example, Command2) using Command2.SetFocus in the GotFocus event of Command1.

    Hope this helps.

    Cheers!

  7. #7

    Thread Starter
    Hyperactive Member scsa20's Avatar
    Join Date
    Apr 2001
    Location
    Mars
    Posts
    456
    Originally posted by mstuehler
    If you use Nucleus' code (which is always a good idea), you can add the following to prevent the user from using [tab] to get to the button:

    Private Sub Command1_GotFocus()

    [some other object].SetFocus

    End Sub

    In other words, if the button you don't want the user to get is Command1, you can deflect the focus to another object (for example, Command2) using Command2.SetFocus in the GotFocus event of Command1.

    Hope this helps.

    Cheers!
    It works!!! thank you.


    p|-|34|2 /\/\3 f0|2 | $p34k 1337
    My TSS quote of the day: "If your haveing a bad day, just press the restart button."

  8. #8
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    that code work, but how can I be able to make it not be able to use Tab to get over the button??
    Set the TabStop property for the button to False.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width