Link to home
Start Free TrialLog in
Avatar of hobster
hobster

asked on

Can you pass parameters to a vb program???

Is it possible to pass parameters to a vb program from DOS? Like, can you do the following:

program test1.psd newtest.psd

where program is the exe, test1.psd is the original file, and newtest.psd is the new file created by the program.

Also, is it possible to create a vb program that does not have a GUI?

P.S. Sorry about the lack of points. I've used them all up.
Avatar of abhinavm
abhinavm

yes you can pass parameters to vb programs. you can use Global variable 'Command' which contains the command line parameters passed to your program.
  Answer of second question is also yes, you can have VB program without GUI. write your code in standard modlue and make Sub Main as startuo in project properties. You have to write a procedure main which will be called first when you run the app. from main you can call other functions
Avatar of hobster

ASKER

Your second answer is correct.

Can you provide more details for the first answer? Below is some simple code that opens an Excel file and saves it to a different name. How would I change the code so I can do the following from the command prompt:

program test.xls newtest.xls

Thank you.

Option Explicit

Sub Main()
   Run
End Sub

Private Sub Run()
   
   Dim xlApp As Object
   Dim spreadsheet As Object  
   
   Set xlApp = CreateObject("excel.Application")
   Set spreadsheet = CreateObject("Excel.Sheet")
   
   spreadsheet.Application.Visible = True
   
   Set spreadsheet = xlApp.OpenAs("N:\temp\ole\test.xls")
   spreadsheet.SaveAs "N:\temp\ole\newtest.xls"
     
   spreadsheet.Application.Quit
     
   spreadsheet.Close
             
   xlApp.Quit
   
End Sub

ASKER CERTIFIED SOLUTION
Avatar of ylarvor
ylarvor
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial