Solved

how to call a vb.net program

Posted on 2004-08-31
32
289 Views
Last Modified: 2010-04-23
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?
0
Comment
Question by:happytoo
  • 12
  • 10
  • 10
32 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11946501
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
0
 

Author Comment

by:happytoo
ID: 11951809
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?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11951817
see code above.
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 11952247
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
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11952291
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)
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 11954423
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.
0
 

Author Comment

by:happytoo
ID: 11964649
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.....????
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 11966176
Sounds like a Pick question to me.  Maybe you should ask in the general programming area.
0
 

Author Comment

by:happytoo
ID: 11973573
Is there a way you can call Pick program from vb.net?  
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 11973724
You should ask this in Programming> area.  Do not drill into Languages when asking.
0
 

Author Comment

by:happytoo
ID: 11977163
How can I run a vb.net program from windows?
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 11996717
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.
0
 

Author Comment

by:happytoo
ID: 12000519
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.
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 12001275
What language are you using to gather the user input?

Do you have simple sample code?

0
 

Author Comment

by:happytoo
ID: 12002701
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.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12003305
isnt that where we started ?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:happytoo
ID: 12006252
No.  This is a new process.
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 12006322
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)
0
 

Author Comment

by:happytoo
ID: 12006471
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.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12006873
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
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12006897
then call your app like ...

yourapp "letterfilename" "DataSourceFile" "OutputFile"
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 12006967
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)



0
 

Author Comment

by:happytoo
ID: 12009491
Do you have to create another form to call statement???
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 12009971
No, just drag the fields onto the form you have already created.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12010003
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 ?
0
 

Author Comment

by:happytoo
ID: 12010279
I want my vb app to ask for the info.
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 12010795
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.
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 300 total points
ID: 12010840
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents txtTemplate As System.Windows.Forms.TextBox
    Friend WithEvents txtDataSource As System.Windows.Forms.TextBox
    Friend WithEvents txtoutput As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.txtTemplate = New System.Windows.Forms.TextBox
        Me.txtDataSource = New System.Windows.Forms.TextBox
        Me.txtoutput = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'txtTemplate
        '
        Me.txtTemplate.Location = New System.Drawing.Point(136, 40)
        Me.txtTemplate.Name = "txtTemplate"
        Me.txtTemplate.TabIndex = 0
        Me.txtTemplate.Text = ""
        '
        'txtDataSource
        '
        Me.txtDataSource.Location = New System.Drawing.Point(136, 72)
        Me.txtDataSource.Name = "txtDataSource"
        Me.txtDataSource.TabIndex = 1
        Me.txtDataSource.Text = ""
        '
        'txtoutput
        '
        Me.txtoutput.Location = New System.Drawing.Point(136, 104)
        Me.txtoutput.Name = "txtoutput"
        Me.txtoutput.TabIndex = 2
        Me.txtoutput.Text = ""
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(104, 144)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 3
        Me.Button1.Text = "Go"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(24, 40)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "Template"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(24, 72)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "Datasource"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(24, 104)
        Me.Label3.Name = "Label3"
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "Output"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 181)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.txtoutput)
        Me.Controls.Add(Me.txtDataSource)
        Me.Controls.Add(Me.txtTemplate)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim wrdapp As Object
            wrdapp = CreateObject("Word.Application")
            wrdapp.Documents.Open(Me.txtTemplate.Text).MailMerge.OpenDataSource(Me.txtDataSource.Text)
            wrdapp.Visible = False
            wrdapp.ActiveDocument.MailMerge.Execute()
            wrdapp.ActiveDocument.Printout()
            wrdapp.Documents(Me.txtoutput.Text).Close(False)
        Catch Ex As Exception
            MessageBox.Show("Unable to complete" & vbCrLf & Ex.Message)
        End Try
    End Sub
End Class
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12010845
is what TRUENEUTRAL is talking about.
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 12011079
Thanks, greg,
Yet another copy of the default form code :)
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12011090
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.
0
 
LVL 5

Assisted Solution

by:TRUENEUTRAL
TRUENEUTRAL earned 200 total points
ID: 12011107
I usually do something like this:

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
...
#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim wrdapp As Object
            wrdapp = CreateObject("Word.Application")
            wrdapp.Documents.Open(Me.txtTemplate.Text).MailMerge.OpenDataSource(Me.txtDataSource.Text)
            wrdapp.Visible = False
            wrdapp.ActiveDocument.MailMerge.Execute()
            wrdapp.ActiveDocument.Printout()
            wrdapp.Documents(Me.txtoutput.Text).Close(False)
        Catch Ex As Exception
            MessageBox.Show("Unable to complete" & vbCrLf & Ex.Message)
        End Try
    End Sub
End Class
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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