Command button help

Discussion in 'Programming General' started by hockeykid09, Jan 31, 2008.

Command button help
  1. Unread #1 - Jan 31, 2008 at 6:59 PM
  2. hockeykid09
    Joined:
    Mar 16, 2007
    Posts:
    1,162
    Referrals:
    0
    Sythe Gold:
    0

    hockeykid09 Guru
    Banned

    Command button help

    I'm making a rs client and I have command buttons for the worlds.
    I am setting all the world links for my buttons but i want to know if
    there is a faster way. Is it possible to do something like...

    Command1-80_Click() ??? (1-80) is command buttons 1-80

    I want to do this instead of

    Command1_Click()
    Command2_Click()
    Command3_Click() Ect...

    Heres what I have so far...only 3 done i need 145 thats why I want to know if this it is possible.

    Private Sub Command81_Click()
    WebBrowser1.Navigate "http://" & GetPrefix(Command81.Caption) & ".runescape.com/l1,p0,j1"
    End Sub

    Private Sub Command82_Click()
    WebBrowser1.Navigate "http://" & GetPrefix(Command82.Caption) & ".runescape.com/l1,p0,j1"
    End Sub

    Private Sub Command83_Click()
    WebBrowser1.Navigate "http://" & GetPrefix(Command83.Caption) & ".runescape.com/l1,p0,j1"
    End Sub
     
  3. Unread #2 - Jan 31, 2008 at 7:15 PM
  4. Terrankiller
    Joined:
    May 7, 2005
    Posts:
    1,286
    Referrals:
    1
    Sythe Gold:
    1

    Terrankiller Ex-Administrator
    Retired Administrator Visual Basic Programmers

  5. Unread #3 - Jan 31, 2008 at 7:23 PM
  6. hockeykid09
    Joined:
    Mar 16, 2007
    Posts:
    1,162
    Referrals:
    0
    Sythe Gold:
    0

    hockeykid09 Guru
    Banned

    Command button help

    I already have all my command buttons made.
    How do I make an array of buttons?

    Sorry just started =p
     
  7. Unread #4 - Jan 31, 2008 at 9:20 PM
  8. Stuart
    Joined:
    May 5, 2005
    Posts:
    1,580
    Referrals:
    2
    Sythe Gold:
    10

    Stuart Guru
    Banned

    Command button help

    The first thing you need to do is make 1 button which will be the main button.

    You MUST change its index value to 0

    Now I called my button "buttons" and this is how to make it generate any number of controls you want.

    Code:
    Private Sub buttons_Click(Index As Integer)
    WebBrowser1.Navigate "http://" & GetPrefix(Index + 1) & ".runescape.com/l1,p0,j1"
    End Sub
    
    Private Sub Form_Load()
    Dim num As Integer
    Dim y As Integer
    Dim x As Integer
    Dim maxx As Integer
    y = 5
    x = 0
    maxx = 2
    For num = 1 To 79
        Load buttons(num)
        If x = maxx Then
            x = 0
            y = y + 5
        Else
            x = x + 1
        End If
        buttons(num).Move x * 120, y * 3, 100, 5
        buttons(num).Visible = True
        buttons(num).Caption = "World " & num + 1
    Next num
    End Sub
    
     
  9. Unread #5 - Feb 1, 2008 at 1:05 AM
  10. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Command button help

    Ok, if you have the buttons already made. you will have to do this:
    click on a button and scroll down to the "Index" property and but a number there, do this for every button that will be used for a world number.

    Once you've done that change the name of the button to something like "cmdWorld", do that for every button. Every world button HAS to have the same name.

    Then you have to much a function something like this.
    Code:
    private sub SwitchWorld(intWorld as integer)
        webbrowser1.navigate
    end sub
    then you would add this to your world button's click event.
    Code:
    private sub cmdWorld_Click(Index as integer)
        switchworld cint(val(cmdworld(index).caption))
    end sub[code]
    
    That will only work if you're caption says the world number if it says something like "World 2" it won't work.
    
    EDIT:
    lol
    i was in the middle of typing this when i got a call from a company that just hired me, so i had to leave to fill out paperwork, came back 4 hours later and stuart beat me to it :(
    *shakes fist*
     
  11. Unread #6 - Feb 1, 2008 at 7:25 AM
  12. hockeykid09
    Joined:
    Mar 16, 2007
    Posts:
    1,162
    Referrals:
    0
    Sythe Gold:
    0

    hockeykid09 Guru
    Banned

    Command button help

    Alright stuart, I get the first little part but what's this do?

    Private Sub Form_Load()
    Dim num As Integer
    Dim y As Integer
    Dim x As Integer
    Dim maxx As Integer
    y = 5
    x = 0
    maxx = 2
    For num = 1 To 79
    Load buttons(num)
    If x = maxx Then
    x = 0
    y = y + 5
    Else
    x = x + 1
    End If
    buttons(num).Move x * 120, y * 3, 100, 5
    buttons(num).Visible = True
    buttons(num).Caption = "World " & num + 1
    Next num
    End Sub

    Is all that needed or can I just use

    Private Sub buttons_Click(Index As Integer)
    WebBrowser1.Navigate "http://" & GetPrefix(Index + 1) & ".runescape.com/l1,p0,j1"
    End Sub
     
  13. Unread #7 - Feb 1, 2008 at 9:05 AM
  14. Stuart
    Joined:
    May 5, 2005
    Posts:
    1,580
    Referrals:
    2
    Sythe Gold:
    10

    Stuart Guru
    Banned

    Command button help

    What that part does is sort the buttons into rows and columns. You have to set your forms scalemode to pixel those.

    It will look like this:

    World 1 | World 2 | World 3
    World 4 | World 5 | World 6
    World 7 | World 8 | World 9

    ECT
     
  15. Unread #8 - Feb 1, 2008 at 9:14 AM
  16. hockeykid09
    Joined:
    Mar 16, 2007
    Posts:
    1,162
    Referrals:
    0
    Sythe Gold:
    0

    hockeykid09 Guru
    Banned

    Command button help

    I already have all my buttons made, i just finished setting all the names to
    "world" so now i have an array of 158 buttons. They are already in rows
    so do i still need that second part?
     
  17. Unread #9 - Feb 1, 2008 at 9:18 AM
  18. hockeykid09
    Joined:
    Mar 16, 2007
    Posts:
    1,162
    Referrals:
    0
    Sythe Gold:
    0

    hockeykid09 Guru
    Banned

    Command button help

    [​IMG]

    And then when I go to make my tabs for free and mems what would the buttons be called?

    Private Sub_Free_Click()
    world(0).visible = true

    and do all of them?

    EDIT: Thanks guys got it all working =]
     
  19. Unread #10 - Feb 1, 2008 at 10:10 AM
  20. Stuart
    Joined:
    May 5, 2005
    Posts:
    1,580
    Referrals:
    2
    Sythe Gold:
    10

    Stuart Guru
    Banned

    Command button help

    Oh then no you dont :)

    Edit:

    Do you have a function that says if the world is members or free?
     
  21. Unread #11 - Feb 1, 2008 at 12:18 PM
  22. hockeykid09
    Joined:
    Mar 16, 2007
    Posts:
    1,162
    Referrals:
    0
    Sythe Gold:
    0

    hockeykid09 Guru
    Banned

    Command button help

    No I have those 2 command buttons for members and free
     
  23. Unread #12 - Feb 1, 2008 at 12:26 PM
  24. Stuart
    Joined:
    May 5, 2005
    Posts:
    1,580
    Referrals:
    2
    Sythe Gold:
    10

    Stuart Guru
    Banned

    Command button help

    Ok well your using the 2 big buttons to change between free and members so this would have nothing to do with it...

    You should use 2 frames those, throw your free and members buttons into different frames and just flick between the frames with the 2 buttons.
     
< Need help with beginner project | Download Microsoft Visual Studio 2008 Express >

Users viewing this thread
1 guest


 
 
Adblock breaks this site