Use command to call exe file

Peter_1985 2,486 Reputation points
2022-01-19T04:58:44.837+00:00

Hi,
C Sharp code below is to return either 0 or 1, and how to make use of such exe file on one VBA command to call this exe file?

namespace Validate_File1
{
class Program
{
static int Main(string[] args)
{
string s0;
s0 = args[0];

        if (s0.Trim() == "")
        {
            Console.WriteLine("No argument is input.");return 0;
        }
        if (File.Exists(s0))
        {
            return 1;
        }
        else
            return 0;

    }

}
}

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,239 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,568 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,486 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,640 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,231 Reputation points
    2022-01-19T05:32:10.323+00:00

    Hi,
    try this:

    Imports System.IO
    
    Module Module1
    
      Function Main(args As String()) As Integer
        If args Is Nothing OrElse (args.Count > 0 AndAlso String.IsNullOrEmpty(args(0).Trim)) Then
          Console.WriteLine("No argument is input.")
          Return 0
        End If
        Dim s0 As String = args(0)
        If File.Exists(s0) Then
          Return 1
        Else
          Return 0
        End If
      End Function
    
    End Module
    
    0 comments No comments

  2. Peter_1985 2,486 Reputation points
    2022-01-19T05:37:35.893+00:00

    Hi,
    Thanks. How about the way to call such .exe file, via one VBA command?

    0 comments No comments