Help with buttons

Discussion in 'Programming & Scripting' started by Lewie4, Feb 22, 2009 with 20 replies and 507 views.

  1. Lewie4

    Lewie4 Getting There

    Messages:
    1,303
    Ratings:
    91
    How would I make a button so when I click it, it would open a program?
    Where would I put this Program so if I sent it, it would open on the other persons computer?
    Thanks
    Lewie

     
  2. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Process.Start("insert path to file here")
    e.g. Process.Start("C:\Windows\notepad.exe")

    But if you want to run a program that is included with your program then you should put the separate program in a folder, inside the folder that your program is in. Then you would use
    Process.Start(Application.StartupPath & "\insert folder name here\insert program name here.exe")

    For example if your program is in C:\My Program, the program you want your program to run could be in C:\My Program\Included Program\Program.exe
    So you would use Process.Start(Application.StartupPath & "\Included Program\Program.exe")

    Application.StartupPath represents the path to your program, no matter where it is, in this instance it's C:\My Program, but no matter where it was as long as the Included Programs Folder is in there with it, it will work.
     
    • Like Like x 1
  3. OP
    Lewie4

    Lewie4 Getting There

    Messages:
    1,303
    Ratings:
    91
  4. Michael Allison

    Michael Allison Enthusiast

    Messages:
    232
    Ratings:
    13
    Try [Click here to view the link] with it if you'd like to find out if they have the program beforehand. Obviously only works on installed programs, not standalone versions.

    There are a lot of other pretty useful tutorials on Google that can aid you in finding the path of the program you need to run, etc. :tongue:
     
  5. Genetic Paradox

    Genetic Paradox Getting There

    Messages:
    422
    Ratings:
    60
    say i wanted to make this program delete a file or rename a file from the computer is there a command i can use in vb or would i have to include a .bat file in it's directory?

    And if i have to use the .bat file is there a way to compile it into my program?

    im working on a pc customizing/displayhacking program and i need this to complete it.
     
  6. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    You don't need to use a batch file to rename/delete files.

    System.IO.File.Delete("Path to file to delete")
    Code:
    System.IO.File.Delete("C:\Documents and Settings\blah.txt")
    and renaming files would be
    System.IO.File.Move("original path + filename", "same path (or different it's upto you) new file name")
    such as
    Code:
    System.IO.File.Move("C:\Documents and Settings\Blah.txt", "C:\Documents and Settings\Blah 2.txt")
     
    • Like Like x 1
  7. Genetic Paradox

    Genetic Paradox Getting There

    Messages:
    422
    Ratings:
    60
    ok and how would i make a button compile the actions of 5 checkboxes?
     
  8. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Easy/lazy way:
    Code:
    If CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True And CheckBox4.Checked = True And CheckBox5.Checked = True Then
    MessageBox.Show("yep, they're all checked")
    Else
    MessageBox.Show("nope, not all of them")
    End If
     
  9. Genetic Paradox

    Genetic Paradox Getting There

    Messages:
    422
    Ratings:
    60
    One last question, does this support wildcards (*)?
     
  10. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    You could use something along the lines of
    Code:
     Dim instances() As String = System.IO.Directory.GetFiles("C:\", "*.txt")
    If instances.Length > 0 Then
    Process.Start(instances(0))
    End If
    to search a directory for a file type (in my example it would be text files) and then it gets an array of all the text documents in C:\ and opens the first one (0)
     
  11. Genetic Paradox

    Genetic Paradox Getting There

    Messages:
    422
    Ratings:
    60
    how come it wont let me test System.IO commands in debug mode
     
  12. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    To be honest I have no idea, unless you typed something incorrectly.
     
  13. Genetic Paradox

    Genetic Paradox Getting There

    Messages:
    422
    Ratings:
    60
    It's not complete and idrc who uses my source so check it for me, please:
    Code:
    Public Class Menu
    
    Private Sub Execute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    If Option1.Checked = True Then
    System.IO.File.Delete("**********************")
    
    End If
    If Option2.Checked = True Then
    
    End If
    If Option3.Checked = True Then
    
    End If
    If Option4.Checked = True Then
    
    End If
    If Option5.Checked = True Then
    
    End If
    End Sub
    
    Private Sub About_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles About.Click
    MessageBox.Show("Version 1.0,Made by Rheejus", "About")
    End Sub
    
    Private Sub Option1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Option1.CheckedChanged
    
    End Sub
    End Class
    
     
  14. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Well you aren't gonna be able to delete a file that doesn't exist. Make sure that file is there, and if it's not then you know the cause of the problem.
     
  15. Genetic Paradox

    Genetic Paradox Getting There

    Messages:
    422
    Ratings:
    60
    and what exactly would that be?
     
  16. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    You're telling it to delete C:\Users\Daniel\Downloads\Natural_Environments.rar, if that file doesn't exist then it won't work.
     
  17. Genetic Paradox

    Genetic Paradox Getting There

    Messages:
    422
    Ratings:
    60
    the wierd thing is... it does exist.

    its my Oblivion PC mod. im looking at it right now and i checked the file path.

    this is some freaky shift.

    also i just added

    Code:
    Imports System.IO
    to the code.

    still is a fail
     
  18. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Does it give you an error message? If so, what does it say?
     
    • Like Like x 1
  19. Genetic Paradox

    Genetic Paradox Getting There

    Messages:
    422
    Ratings:
    60
    nevermind i got it working. (wow, im slow. i missed that i didnt write
    Code:
    Handles Execute.Click
    )

    Buuuut, are there any wildcard functions in VB? so i can select all of 1 file type
    i.e. "*.txt"
    or any functions similar that i can use with System.IO.File commands like move, delete, and create?
     
  20. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Try this, I think it's about what you're looking for.
    Code:
    Dim currentDirectory As New DirectoryInfo("C:\")
    For Each File As FileInfo In currentDirectory.GetFiles("*.txt")
    File.Delete()
    Next
     
    • Like Like x 1