Link to home
Start Free TrialLog in
Avatar of happytoo
happytoo

asked on

how to call a vb.net program

Here's the thing,  we are running in Unix OS environment.  We have a program set to run WordPerfect.  But now, we are trying to convert the WordPerfect to MSWord for Windows.  We are going to use VB.net to run our merge letter program.  I already have the datasource, the word document and a simple vb.net program to execute the merge.  I have to run this vb.net program to execute different database and word document.  I probably need to set up parameters but how do I do that?
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

ok let me see if I have this straight, you are running MS word in a unix environment ... are you using wine or another windows emulator ?

As for passing parameters you will notice that there are a few overloads of the mian method available

Function Main(ByVal CmdArgs() As String) As Integer
   Dim ArgNum As Integer   ' Index of individual command-line argument.
   If CmdArgs.Length > 0 Then   ' See if there are any arguments.
      For ArgNum = 0 To UBound(CmdArgs)
         Console.WriteLine("Received Parameter " & CmdArgs(ArgNum)
      Next ArgNum
   End If
   Return 0  
End Function

notice that here it is processing command line arguments

programname foo bar test test

will wun with the output of

Received Parameter foo
Received Parameter bar
Received Parameter test
Received Parameter test

you could pass the database and the word document to your program through this method
Avatar of happytoo
happytoo

ASKER

No.  We currently running WordPerfect6.0 in a unix environment.  What I'm trying to accomplish now is to use MSword using VB.net.  Like I said, I already have an executable command using vb.net to merge and print the letters out to the spooler.  But in the code I have written, I hard coded the file document and data file.  My question is how can I call this program to execute multiple different database?
see code above.
happytoo...

in gregory's code, just replace the line...
>Console.WriteLine("Received Parameter " & CmdArgs(ArgNum)
with your call to your application.

Another way to do this would be to use a config file to define the databases it will execute on.  You would set up a tag with some sort of delimited list of values, then read the config file to get the list.

See .NET help on reading configuration files
actually i was saying for him to put code like that in his main (then pass the values he read into his function that did the work with the database)
yes, but if he combines your solution with a config file, he can easily modify his list of parameters and run against the modified list.
Sorry guys,   but I have to revised my question.  I don't really need a VB.net program to perform this task.  What I'm looking for is how can I execute vb.net program from Universe on Windows.  We are running Universe on Windows NT and using Pick basic language.  Any idea on this experts.....????
Sounds like a Pick question to me.  Maybe you should ask in the general programming area.
Is there a way you can call Pick program from vb.net?  
You should ask this in Programming> area.  Do not drill into Languages when asking.
How can I run a vb.net program from windows?
1. Install the .NET framework
2. Copy the executable in
3. Double-click the executable

But that isn't what you wanted to know, right?

It sounds like you just need to ask this in the Programming area.  You are much more likely to find someone there that knows about Pick (whatever that is) than in a specialized area for .NET programming.
This might be a solution to my problem since I cannot get an answer regarding this topic.  What I want to do is this.  I'd like to have a user to enter a 3 different data input just like this:

Enter form letter
Enter data file
Enter form type

Then whatever the data input on these 3 questions, I'll be able to pass these inputs to run the merge program.

How do I do that?  Please help as this might be my last option to solve my issue.  I'd really appreciate it so much.

Thanks.
What language are you using to gather the user input?

Do you have simple sample code?

I'm using VB.NET.  I have a vb.net program that executes the merge but I hard coded the files I'm merging to.  So what I want to do is to have a user enter 3 inputs that way I can pass them as parameters.
isnt that where we started ?
No.  This is a new process.
gregory,

I think happytoo is either very confused (and is asking this in the wrong forum)
OR
happytoo has a major language barrier and is having trouble communicating.


Happytoo,

Apparent facts I have been able to determine from this post are as follows:
1. Your legacy environment is UNIX
2. Your legacy application is a wordperfect for UNIX application
3. You are upgrading to MS Word for Windows
4. You are using VB.NET in conjunction with MS Word to create some sort of mail merge program
5. You have hardcoded the database and MS Word document paths into the VB.NET program and it is working, but you would like to set it up so the database and document paths are passed to it as parameters instead of hardcoded.
6. You are using something called Universe.
7. You are trying to call a VB.NET program (and possible pass it parameters) using Pick Basic.

Comments and questions about those facts:
1. Irrelevant
2. Irrelevant
3. Irrelevant
4. OK, now we are approaching the subject.
5. Have you been able to get this part coded?
6. You will need to be a *LOT* more specific, as there are literally hundreds of IT products out there going by that name.  I see you are using Pick?  Are you talking about the Universe OS?  If so, where does it come into play here?
7. Not even sure this is possible, however, I *AM* sure that this is not the correct forum in which to ask this question if you want a solution.  A better forum would be the General Programming area (or even the UNIX area)
Ok, let me make myself clear here.  I have a simple program written in vb.net that does the merging part.  Here it is.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim wrdapp As Object

        wrdapp = CreateObject("Word.Application")
        wrdapp.Documents.Open("c:\temp\VB\formletter.doc").MailMerge.OpenDataSource("c:/temp/VB/testdata.csv")
        wrdapp.Visible = False
        wrdapp.ActiveDocument.MailMerge.Execute()
        wrdapp.ActiveDocument.Printout()
        wrdapp.Documents("c:\temp\VB\formletter.doc").Close(False)
    End Sub

Since that Visual Basic has no connection with Universe Pick Basic the only or might be a solution to my issue is have a user enter the FORM TYPE, LETTER NAME, and the DATA FILE.  This way, I don't have to hard code the files.  And I can pass these 3 variables as parameters but I don't know how to do that.  That's why I'm asking for your expertise on this.

Thank you.
ok so your form is already in vb.net ... you can put text boxes on your form and let them enter it or ...

Function Main(ByVal CmdArgs() As String) As Integer
   Dim ArgNum As Integer   ' Index of individual command-line argument.
   If CmdArgs.Length = 3 Then   ' See if there are any arguments.
       dim letterfile as string = CmdArgs(0)
      dim DataSource as string = CmdArgs(1)
      dim Output as string = CmdArgs(2)
        Dim wrdapp As Object

        wrdapp = CreateObject("Word.Application")
        wrdapp.Documents.Open(letterfile).MailMerge.OpenDataSource(DataSource)
        wrdapp.Visible = False
        wrdapp.ActiveDocument.MailMerge.Execute()
        wrdapp.ActiveDocument.Printout()
        wrdapp.Documents(Output).Close(False)
   End If
   Return 0  
End Function
then call your app like ...

yourapp "letterfilename" "DataSourceFile" "OutputFile"
So why even mention Pick Basic?

Why not build a user form (GUI) in VB.NET?

There must be some reason you have mentioned Pick so often...

but maybe not... I ramble aimlessly myself sometimes.

So, drag some text boxes and a button onto your Form1

Take the code out of the form load event and put it in the button click event as follows:

       Dim wrdapp As Object
        wrdapp = CreateObject("Word.Application")
        wrdapp.Documents.Open(textbox1.text).MailMerge.OpenDataSource(textbox2.text)
        wrdapp.Visible = False
        wrdapp.ActiveDocument.MailMerge.Execute()
        wrdapp.ActiveDocument.Printout()
        wrdapp.Documents(textbox1.text).Close(False)



Do you have to create another form to call statement???
No, just drag the fields onto the form you have already created.
ok this is getting confusing ...

do you want your vb app to ask for the info or do you want to pass it from another app ?
I want my vb app to ask for the info.
drag the textboxes onto the form you have created.  According to your code, you have a form named "Form1"

follow the instructions from my earlier post to drag fields on and replace the code.
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada 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
is what TRUENEUTRAL is talking about.
Thanks, greg,
Yet another copy of the default form code :)
I have noticed that many people when told to put a textbox on a form blank ... given something they can just copy/paste they get it.
SOLUTION
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