Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
718 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
[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
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:ToddBeaulieu
ID: 34901127
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
ID: 34903573
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 400 total points
ID: 34906314
> 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 1600 total points
ID: 34906582
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
ID: 34915720
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses

604 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