?
Solved

Can you pass parameters to a vb program???

Posted on 1998-10-01
3
Medium Priority
?
199 Views
Last Modified: 2010-04-30
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.
0
Comment
Question by:hobster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Expert Comment

by:abhinavm
ID: 1437714
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
0
 
LVL 2

Author Comment

by:hobster
ID: 1437715
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

0
 
LVL 1

Accepted Solution

by:
ylarvor earned 0 total points
ID: 1437716
Option Explicit

Dim cmd As String
Dim nb_car As Integer
Dim begin_nam, end_nam As String

Sub main()
   cmd = Command()
   nb_car = InStr(cmd, ".xls")
   nb_car = nb_car + 4
   begin_nam = Trim$(Left(cmd, nb_car))
   end_nam = Trim$(Mid(cmd, nb_car))

   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\" & begin_nam)
   spreadsheet.SaveAs "N:\temp\ole\" & end_nam
       
   spreadsheet.Application.Quit
       
   spreadsheet.Close
               
   xlApp.Quit
   
End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question