Results 1 to 12 of 12

Thread: Program that adds buttons

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Program that adds buttons

    This is my first post and I havn't been doing VB long at all it is my first program language too.

    I am in the process of creating a program which will open external applications by clicking a button, using this command, Shell "c:\test.exe", vbNormalFocus.

    I was wondering if there was a way that when users run this program they could add their own programs of choice? and if so how.

    Thanks lea0001




    Have been learning visual basic for about 3 Days now, Plz be patient with me lol..

  2. #2
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    266

    Re: Program that adds buttons

    welcome
    wat actually u want ... breif a lil more ... do u want to open different exe files with click of a single button then u need to take a list box in which there is a list of exe files user would select one and click button to run it.

    2nd approach is u have number of buttons on form each of it assigned an exe file and when click on it exe would execute.

  3. #3
    Lively Member
    Join Date
    Dec 2005
    Posts
    124

    Re: Program that adds buttons

    If you wanted them, to have 100% freedom what you could do is have a text box which they can type the path name into, then in the command button you would have

    VB Code:
    1. Shell text1.text, vbNormalFocus

    that would allow the user 100% freedom.

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Program that adds buttons

    I know how to link buttons to .EXEs but i want people to be able to add their own buttons or links shall we call them (which will open files) whithout having to edit in Vb, doing it all simply in my program is this possible?




    Have been learning visual basic for about 3 Days now, Plz be patient with me lol..

  5. #5
    Lively Member
    Join Date
    Dec 2005
    Posts
    124

    Re: Program that adds buttons

    I see.

    Well this is how i would do it. Have a form with say 5 buttons that will open exe files, then add one more button and a text box.

    VB Code:
    1. Option Explicit
    2.    Dim Item1 as String
    3.    Dim Item2 as String
    4.    Dim Item3 as String
    5.    Dim Item4 as String
    6.    Dim Item5 as String
    7.  
    8. Private Sub command1_Click
    9.    Dim index as long
    10.    If Mid(Item1, 1, 1) = " " then
    11.        Item1 = Text1.text
    12.        Command2.caption = "Press to run " & Item1
    13.    Elseif Mid(Item2, 1, 1) = " " then
    14.        Item2 = Text1.text
    15.        Command3.caption = "Press to run " & Item2
    16.    ElseIf Mid(Item3, 1, 1) = " " then
    17.        Item3 = Text1.text
    18.        Command4.caption = "Press to run " & Item3
    19.    Elseif Mid(Item4, 1, 1) = " " then
    20.        Item4 = Text1.text
    21.        Command5.caption = "Press to run " & Item4
    22.    Elseif Mid(Item5, 1, 1) = " " then
    23.        Item5 = Text1.text
    24.        Command6.caption = "Press to run " & Item5
    25.    Else
    26.      MsgBox("You have used up all the buttons, please close the program and start again")
    27.    End if
    28. End sub
    29.  
    30. Private Sub command2_Click
    31.    Shell item1, vbNormalFocus
    32. End Sub
    33.  
    34. Private Sub command3_Click
    35.    Shell item2, vbNormalFocus
    36. End Sub
    37.  
    38. Private Sub command4_Click
    39.    Shell item3, vbNormalFocus
    40. End Sub
    41.  
    42. Private Sub command5_Click
    43.    Shell item4, vbNormalFocus
    44. End Sub
    45.  
    46. Private Sub command6_Click
    47.    Shell item5, vbNormalFocus
    48. End Sub

    Hope that helps.

    (please note i didn't run this is vb, i just typed it into the reply box, thier may be a few spelling errors but they wont be hard to fix)

  6. #6
    Lively Member
    Join Date
    Apr 2006
    Location
    Planet Earth
    Posts
    64

    Re: Program that adds buttons

    try this:

    VB Code:
    1. Private Sub Command1_Click()
    2. CommonDialog1.ShowOpen
    3. Text1.Text = CommonDialog1.FileName
    4.  
    5. On Error GoTo err
    6.  
    7.  
    8. Shell (Text1.Text)
    9.  
    10. err:
    11. Exit Sub
    12. End Sub

    to run this codes:

    add 1 CommonDialog control, 1 textbox and 1 button on ur form

    then browse for the exe of the desired program
    Last edited by wildsurf; May 1st, 2006 at 06:00 AM.
    I'm Still learning!
    satisfied/not satisfied, PLEASE TAKE SOME TIME TO rate me accordingly.
    Ur opinions helps me to be better!


    Appreciation Triggers Another Good Deeds.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Program that adds buttons

    Thanks alot guys, ill try these scripts out




    Have been learning visual basic for about 3 Days now, Plz be patient with me lol..

  8. #8
    Lively Member
    Join Date
    Dec 2005
    Posts
    124

    Re: Program that adds buttons

    If they do work rember to click Thred Tools >> Mark as Resolved

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Program that adds buttons

    Thx Ichhar it works but how could i configure the script so it could add more than just one button?

    Oh and how could i save the settingS?
    Last edited by lea0001; May 1st, 2006 at 06:33 AM.




    Have been learning visual basic for about 3 Days now, Plz be patient with me lol..

  10. #10
    Lively Member
    Join Date
    Dec 2005
    Posts
    124

    Re: Program that adds buttons

    That code does add up to 5 buttons. In fact to would work better if you made a contorl array on the buttons, but that may be to much at the moment.

    Save files can be very confuseing to a person new to visual basic. I'm not the best one to ask about it as I'm not to sure about it myself, its proberly best to start a new thead asking how to save and read from text files. Show the code I gave you and ask people how to save all the items in a text field and open them again.

  11. #11
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Program that adds buttons

    Why not make a combo box and a go button. Then they can select whichever option they want, or they can add new ones (combo1.additem etc)

  12. #12
    Lively Member
    Join Date
    Dec 2005
    Posts
    124

    Re: Program that adds buttons

    Andy G, good idea. lea0001 if i were you I'd do that, its a much better idea.

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