Solved

Can you pass parameters to a vb program???

Posted on 1998-10-01
3
160 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now