MS Excel & Console App

Hi guys,

I’m sending a parameter from Excel VBA to a Xojo console application. The received argument is a string separated by semicolon that is splitted in order to store that data in an array. The problem is that the lenght of the argument is not major that 29 characters, and the variable sArg(2) only is the word “This”. I’m not sure if the argument received is broken by the event ‘Run’.

Anyone know if there is a restriction regarding to lenght of the characters sent to a console aplication …? Or someone know how to fix this ?

  
'XOJO Code
Dim sPar as String, sArg() as String
  
  'Vars
  sPar=args(1)
  sArg=sPar.Split(";")
  
  'Set workbook file
  WB_FILE=sArg(0)
  
  Select case sArg(1)
    
  case "GetMsg"
    
    Call GetData(sArg(2))
    
  end Select

'VBA Code

sArg(0) = "WBTest"
sArg(1) = "GetMsg"
sArg(2) = "This one is a test"
sPath = "PathToConsoleApp"

Call ShellExecute(0&, vbNullString, "ConsoleApp.exe", sArg(0) & ";" & sArg(1) & ";" & sArg(2), sPath, 0&)

Thanks,

Command line arguments are separated by spaces, so each word is considered a separate argument. Put quotes around multi-word arguments to group them.

Hi Andrew,

Many thanks for your reply. I’m not sure to understand correctly your suggestion. Each argument executing the API ‘ShellExecute’ from VBA is separated by comma. Could you please give me an example …?

sArg(0) = "WBTest"
sArg(1) = "GetMsg"
sArg(2) = "This one is a test" [b]'??[/b]
sPath = "PathToConsoleApp"

Call ShellExecute(0&, vbNullString, "ConsoleApp.exe", sArg(0) & ";" & sArg(1) & ";" & [b]sArg(2)[/b], sPath, 0&)

Andrew,

Sorry , I understood finally your suggestion. Many Thanks, the code would be like this:


sArg = "WBTest GetMsg ThisOneIsATest"
sPath = "PathToConsoleApp"

Call ShellExecute(0&, vbNullString, "ConsoleApp.exe", sArg, sPath, 0&)

You could also try

sArg = "WBTest GetMsg ""This One Is A Test"""

Hi Wayne,

sArg = "WBTest GetMsg ""This One Is A Test"""

Thanks, works perfect !