Solved

Can you pass parameters to a vb program???

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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