PDA

View Full Version : Convert DOS commands to VBA code...



yowy777
07-20-2012, 01:07 PM
I need help and i don't know where to start... is for a Button click...
I need this commands to be VBA script and not a CMD commands.


if exist BGMOriginal goto :continue else goto :backup
:backup
md "BGMOriginal"
copy bgm\*.* BGMOriginal\
if exist BGMOriginal\music.mp3 goto :continue else goto :error
:continue
tasklist /FI "IMAGENAME eq Launcher.exe" /FO CSV > search.log
FOR /F %%A IN (search.log) DO IF %%~zA EQU 0 GOTO :Run2 else goto:Run
:Run2
copy bgmedit\*.* BGM\
:Run
copy BGMOriginal\*.* BGM\
start Launcher.exe
TIMEOUT 14 /nobreak
copy bgmedited\*.*" "BGM\
:error
echo: ERROR
exit

The reason i want it to be VBA and not CMD... is because on my computer works fine... but on my brother computer doesnt work the BAT file...
This is my code i use with the .bat

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ProgressBar1.Value = ProgressBar1.Minimum
Dim psi As New _
System.Diagnostics.ProcessStartInfo("edit.bat")
psi.RedirectStandardOutput = True
psi.UseShellExecute = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.CreateNoWindow = True
Dim myProcess As System.Diagnostics.Process
myProcess = System.Diagnostics.Process.Start(psi)
Dim myOutput As System.IO.StreamReader _
= myProcess.StandardOutput
myProcess.WaitForExit()
ProgressBar1.Value = ProgressBar1.Maximum
MsgBox("Process Finish")
End Sub
I know some codes... but i am a total noob at vba...
I currently use this to copy all files from 1 directory to another:

My.Computer.FileSystem.CopyDirectory("BGMOriginal", "BGM", True)
ProgressBar1.Value = ProgressBar1.Maximum
All i want is a code that:

1. Checks for BGMOriginal folder, if it's not there create a folder named BGMOriginal and copy all files from BGM to BGMOriginal. Then continue to step 2.
2. Checks for Launcher.exe if running then copy all files from BGMEdited to BGM, if its not running then Copy all files from BGMOriginal to BGM then start Launcher.exe wait for 15 seconds then copy all files from BGMEdited to BGM.

I have been trying for days ... But i am a totally n00b...

yowy777
07-20-2012, 02:09 PM
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim fso As New FileSystemObject
If fso.FolderExists("BGMOriginal") Then
If Not fso.FileExists("bgm001.ogg") Then
fso.CopyFile("BGM\*.*", "BGMOriginal", True)
End If
Else ' folder doesn't exist so create it then copy file there
fso.CreateFolder("BGMOriginal")
fso.CopyFile("BGM\*.*", "BGMOriginal", True)
End If
Dim ProcessARunning As Boolean
Dim AProcess As Process() = System.Diagnostics.Process.GetProcessesByName("_Launcher")
If AProcess.Count <> 0 Then
ProcessARunning = True
Else
My.Computer.FileSystem.CopyDirectory("BGMOriginal", "BGM", True)
End If
End Sub
End Class
I have that for now... but i get an error in filesystemobject... aso i need a lot more... from UP

Rehan125
12-12-2013, 09:56 PM
My.Computer.FileSystem.CopyDirectory("BGMOriginal", "BGM", True)
ProgressBar1.Value = ProgressBar1.Maximum