futonguy Posted September 16, 2010 Posted September 16, 2010 I am a beginner using VS 2008. I am trying to use VB to create a window form whereby user will open a few files to run with an exe file.I have a python code which already converted to an exe-readable file. In order to run the exe file, i still need to fetch input arguments (in this case, some text files) to execute the exe program. Over at VS, i am creating a window form where there is an open button to allow user to search for the files (txt files) they wish to fetch - this will show in the textbox, and using the files they chose, user will click on the 'Execute' button to run the program. I managed to find the cmd code to run an exe file, however i am not sure how i can place my txt files to run together with my exe program.Can anyone able to help me ??Cheers
futonguy Posted September 16, 2010 Author Posted September 16, 2010 I am a beginner using VS 2008. I am trying to use VB to create a window form whereby user will open a few files to run with an exe file.I have a python code which already converted to an exe-readable file. In order to run the exe file, i still need to fetch input arguments (in this case, some text files) to execute the exe program. Over at VS, i am creating a window form where there is an open button to allow user to search for the files (txt files) they wish to fetch - this will show in the textbox, and using the files they chose, user will click on the 'Execute' button to run the program. I managed to find the cmd code to run an exe file, however i am not sure how i can place my txt files to run together with my exe program.Can anyone able to help me ??CheersI managed to find a script by doing some searches:Shell "C:\Path\MyExe.exe this_is_the_cmd_line"and apparently it's worked as commented by the user.As the parameter i am using might come from a different file location and it can be more than 1 file. How am i suppose to do sO?
IcemanND Posted September 16, 2010 Posted September 16, 2010 Use variables for the switches, you could use one for the executable also if needed.Note Syntax my not be exactly correct (too many languages in my head and I don't have VS installed at the moment)My_Prog = "C:\path\myexe.exe"...myParam=replace(ParamTextbox.text, chr(13), " ") ' replaces carriage returns with spacesShell My_prog myParam
futonguy Posted September 17, 2010 Author Posted September 17, 2010 hi,it doesnt seem to work. For example i have a textbox which will display the files location using OpenFileDialog1(open_click_button). Inside this textbox, it might display more than 1 file from a certain directory. After which, i would like to use this files from this directory to act as a parameter into an exe file. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strFileName As String OpenFD.InitialDirectory = "C:\" OpenFD.Title = "Open a Summary File" OpenFD.Filter = "Summary Files|*.summary" Dim DidWork As Integer = OpenFD.ShowDialog() If DidWork = DialogResult.Cancel Then Else strFileName = OpenFD.FileName TextBox1.AppendText(strFileName) TextBox1.AppendText(" ") End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim ChosenPlatform As String Dim MyProg As String 'Dim filename1 As String Dim myParam As String If RadioButton1.Checked = True Then ChosenPlatform = RadioButton1.Text MyProg = "C:\My Documents\Visual Studio 2008\Projects\Project1\summary\sum_trial1\sum_trial1\program1.exe" 'filename1 = "text.txt" myParam = Replace(TextBox1.Text, Chr(13), " ") ' replaces carriage returns with spaces System.Diagnostics.Process.Start(MyProg, myParam) TextBox1.Text = " " ElseIf RadioButton2.Checked = True Then ChosenPlatform = RadioButton2.Text ElseIf RadioButton3.Checked = True Then ChosenPlatform = RadioButton3.Text End If 'MsgBox("You select " & ChosenPlatform & " platform. Report will be saved in C:\MY DOCUMENT and current folder") End Sub
IcemanND Posted September 17, 2010 Posted September 17, 2010 If you popup a msgbox (or setup a watch and step through the program) after the myParam line do you get what you need to run it? if there are spaces in the parameters does the program require they be surrounded by quotes? myParam = Replace(TextBox1.Text, Chr(13), " ") ' replaces carriage returns with spaces System.Diagnostics.Process.Start(MyProg, myParam)
futonguy Posted September 20, 2010 Author Posted September 20, 2010 Yes, when i popup a msgbox, the location of the file chosen is correct.. However, I am wondering when i executed System.Diagnostics.Process.Start(MyProg, myParam), can the .exe be able to capture the parameter from "myParam" ?that is:under the MS-Dos command, i'll enterC:\Python26>test.exe file1.txt file2.txt file3.txtfrom above:if MyProg = test.exethen myParam = file1.txt file2.txt file3.txtBut when i run this script, myParam = C:/desktop/file1.txt ---> therefore when i started to execute the System.Diagnostics.Process.Start(MyProg, myParam) the script will be reading as test.exe C:/desktop/file1.txt C:/desktop/file2.txt C:/desktop/file3.txt ??
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now