Solved

Trying to pass two parameters to an VB.NET .exe program from Microsoft Office Access VBA 2007 but not working?

Posted on 2011-02-15
5
673 Views
Last Modified: 2013-11-27
Per the following code, I'm trying to pass two values to an .exe that will modify an Access database and then based on the second value, open the database when finished.  But when I run the vba below I keep getting an error on the .exe file that states:

Unhandled exception has occured in your application.  If you click continue the application will ignore this error and attempt to continue.  If you click QUit, the application will close immediately.

Input string was not in a correct format.

The vb.net file I'm trying to run with its code can be found at this link:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26823374.html

I'm pretty sure the Access VBA is correct but not sure on the Visual Basic.NET side?

WIth Details stating:

ee the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.FormatException: Input string was not in a correct format.
   at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToBoolean(String Value)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4952 (win7RTMGDR.050727-4900)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
Archive_EC_database
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///Q:/EC/0MSAccess/Features/Archive_EC_database.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.



Public Declare Function StartupShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


Public Function Open_Archiving()
On Error GoTo Err_This

  Dim sNameOnly As String
  sNameOnly = Right(CurrentDb.Name, Len(CurrentDb.Name) - InStrRev(CurrentDb.Name, "\"))

  Call StartupShellExecute(0&, "Open", sArchiveEXE, Chr(34) & Network_Path(CurrentDb.Name) & sNameOnly & Chr(34), True, 1)

Exit_This:
  Exit Function

Err_This:
  Call Error_Action(Err, Err.description, "modRibbon @ Open_Archiving", Erl())
  Resume Exit_This

End Function

Open in new window

0
Comment
Question by:stephenlecomptejr
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:ToddBeaulieu
Comment Utility
You've got this filed under VB.net, but this looks like VBA.

I  don't have VB to try this and it's an awfully long time...

First off, I think you have your arguments off.

You're passing in  < true, 1 > as the last two args, but the API's looking for a string and a bool. Obviously, that's not right. I'd start there.

Next up, you are supposed to pass all args in a single string with a space between them. Again, I can't test this, but I worry about directories and filenames with spaces in them. I'm not sure what to do there. I don't know if it wants quotes around the filename (in case of spaces), a space and then the second arg. I don't think you need to quote the entire string.

Anyway, you're not passing two args up there, you're just passing one, with the invalid string arg, which is most likely the cause of the exception.
0
 
LVL 1

Author Comment

by:stephenlecomptejr
Comment Utility
So Todd,

Some things that could help me further-

If I were to utilize one command line via Run - what should the syntax be for DOS?
And if it were another vb.net calling another .exe what should be the syntax be for such whereby I change the vb.net coding (shown on the other URL)?
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 100 total points
Comment Utility
> Input string was not in a correct format.
This is a conversion error. Somewhere in the code, you are converting from string to double/integer etc and its not working. What arguments are you passing (show us the generated command line)
0
 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 400 total points
Comment Utility
I just tested this with a vb.net app, calling it from a cmd line.

Assuming your option base is NOT 1, then args are 0-based. Adjust accordingly. If you run this program with the following command line, it works perfectly.

"vb forms quick tests" "C:\My File Name" true

I had spaces in the test app name, so I had to use quotes. I used quotes around the filename because it's got spaces.

In the screenshot, you can see that I'm able to extract the arguments just fine. The first arg is the vb app itself.
Imports System.Text.RegularExpressions
Imports System.Collections

Friend Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim args() As String = Environment.GetCommandLineArgs()
        Dim sFilename As String = "NOT SPECIFIED"

        Message("Arg count = {0}", args.Length)
        Message("Arg 0 = [{0}]", args(0))

        If args.Length > 1 Then
            Message("Arg 1 = [{0}]", args(1))

            If args.Length > 2 Then
                Message("Arg 2 = [{0}]", args(2))
            End If
        End If


        Dim bAutoOpenFlag As Boolean = False

        If args.Length > 1 Then
            sFilename = args(1)

            If args.Length > 2 Then
                Boolean.TryParse(args(2), bAutoOpenFlag)
            End If
        End If

        Message("Filename = [{0}]", sFilename)
        Message("Flag = [{0}]", bAutoOpenFlag.ToString())

    End Sub

    Private Sub Message(ByVal Text As String, ByVal ParamArray Args() As Object)
        Dim formatted As String = String.Format(Text, Args)
        ListBox1.Items.Add(formatted)
        Console.WriteLine(formatted)
    End Sub

End Class

Open in new window

vb-args.png
0
 
LVL 1

Author Closing Comment

by:stephenlecomptejr
Comment Utility
Both were right.  Code Cruiser helped me see that another section of code was causing a problem.  I appreciate Todd's help and initiative in solving the other part of where I still had to adjust the startup code the right way.   Without his input, I never would have come close to solving this issue.

Much appreciation.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now