Could I make two programs, but with one icon/startup so that when you click the icon, it runs both programs?

Thats my first question.

My other question is for something else, how can I make something delete files? Thanks.

Dani AI

Generated

Both of the routes mentioned in the thread are sensible; choose by what you control and how the two pieces must interact. ’s Sub Main approach (single entry point that coordinates startup) is good when you own both projects and can combine logic. ’s idea (have one app start the other) is ideal when the executables must remain separate. For a no-code shortcut you can use a tiny batch file like:

@echo off
start "" "C:\Path\FirstApp.exe"
start "" "C:\Path\SecondApp.exe"

Deleting files safely (answer to your second question)

  • Never delete without checking. Always confirm existence, clear read-only attributes, and catch exceptions for permissions or locks. Run destructive operations on a background thread so the UI stays responsive (see ’s timer/thread advice for keeping the UI alive).
  • Example VB.NET helper to delete a single file safely:
Private Sub SafeDeleteFile(path As String)
    If Not IO.File.Exists(path) Then Exit Sub
    Try
        Dim attrs As IO.FileAttributes = IO.File.GetAttributes(path)
        If (attrs And IO.FileAttributes.ReadOnly) = IO.FileAttributes.ReadOnly Then
            IO.File.SetAttributes(path, attrs And (Not IO.FileAttributes.ReadOnly))
        End If
        IO.File.Delete(path)
    Catch ex As UnauthorizedAccessException
        ' Permission issue - may need elevation or different folder
    Catch ex As IOException
        ' File locked or I/O error
    End Try
End Sub
  • Delete many files by enumerating: For Each f In IO.Directory.GetFiles(folder, "*.tmp") SafeDeleteFile(f) Next (use SearchOption.AllDirectories for recursion).
  • Want to send files to the Recycle Bin instead of permanent delete? Use the VB helper in Microsoft.VisualBasic.FileIO (My.Computer.FileSystem.DeleteFile / FileSystem.DeleteFile) with the RecycleOption.

Practical cautions

  • Avoid hard-coded paths; use Path.Combine. Test on a disposable folder first. If a file is locked, either close the locking handle, schedule deletion on reboot, or surface a clear error to the user. If the two programs must coordinate, consider waiting for the launched process or using simple IPC rather than firing both blind.

Recommended Answers

All 11 Replies

First Question:
Yes you can do that. You would need to use the sub main procedure. The sub main is usually used for things like a splash screen, but you could use it to start two seperate threads.

Second Question:
You would need to import file IO, but yes you can delete a file or files.

Chester

Can you describe the "sub-main procedure" to me? Sorry, I'm a noob.

Can you describe the "sub-main procedure" to me? Sorry, I'm a noob.

Right Click on your project and the click Add New Item
Click Module
Name your Module
Open the new Module
Between the Module Header and Footer, type Sub Main() and enter
Now enter your code.

On the Solution Explorer right click and click on your settings, under startup, click Sub Main.

Hope this helps.

Chester

Thanks, but one more thing..."Now enter your code" which code is that? Like the code that opens both of them or what? Thanks.

Thanks, but one more thing..."Now enter your code" which code is that? Like the code that opens both of them or what? Thanks.

Yes, it would be the code to launch each program. I actually think what he was trying to do is to have your project load two forms, instead of two exe's. You could just as easily have 1 of your exe's launch your other EXE on form load.

You could just as easily have 1 of your exe's launch your other EXE on form load.

So how would I do this method?

Since you are in VB.Net The System.Diagnostics namespace exposes a Process class:

Dim myProcess As Process = System.Diagnostics.Process.Start("c:\somepath\somefile.exe")

obviously, you will need to change "c:\somepath\somefile.exe" to the path of the program that you want to launch (in this case, your other program). That should effectively launch the exe. Now, just stick that in your form load... and whenever EXE 1 runs, it will launch EXE2 by default.

There are more ways than one to accomplish what you want....

Chester

Ya I thought I'd look at both of them and see what one I thought would be easier.

i'm currently working on a school project, which is making a game, in VB.Net. I was having trouble trying to find out how to code a countdown timer so when the timer stops the game is over. Could someone please help me?

There should be a timer control (looks like a stop watch, I think). Set it's interval to 1000 (which is 1 second (1000 milliseconds)). Now, every second this timer event will fire. In Your declaration section of the form (where you declare form wide variables) add a public variable to keep track of the time, call it: timevariable. In The Form Load Event of your form, set the variable to the max amount of time (the number you want to start at). Then, in the timer event (every second), add this:

if timevariable = 0 then
     msgbox "game over"
     exit sub
end if

timevariable = timevariable - 1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.