question

London MT avatar image
0 Likes"
London MT asked Phil BoBo edited

rundocument() is returning 2, the file isn't opening.

rundocument("open","C:\Users\PAHT_TO_EXAMPLE.csv") is returning 2, and nothing opens... What could be the reason?

Second question: Is the return value an errormsg ? And if so, how can I read it?

Thanks

FlexSim 18.2.2
flexsim commands
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

tannerp avatar image tannerp commented ·

Is your model something you could upload so we can look at it? If it contains proprietary information, you can always upload it to a private question so only FlexSim U.S. can see it.

0 Likes 0 ·
London MT avatar image London MT tannerp commented ·

Hi @Tanner Poulton,

Thanks for your quick reply.

I've opened a new model and tried it, I get the same return value.

Thanks

Jarek

0 Likes 0 ·
tannerp avatar image tannerp London MT commented ·

I'm not positive, but it could be that it's not a ".doc" file. Here's an excerpt from the User Manual that might help:

What are you hoping to import? Is it a table?

0 Likes 0 ·

1 Answer

Jordan Johnson avatar image
3 Likes"
Jordan Johnson answered Phil BoBo edited

The rundocument() command returns the result of ShellExecute, a Windows API function. If the returned value is less than 32, then the return value indicates an error code. In this case, error code 2 indicates that the file is not found. See this link for more information on ShellExecute, and see this link for error code values and descriptions.

My guess is that this has to do with the \ character. In a string literal, be sure to use \\, to escape the \ character:

rundocument("open","C:\\Users\\PAHT_TO_EXAMPLE.csv")
· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

London MT avatar image London MT commented ·
@jordan.johnson

thanks for that reply, it solved the error.

If I would like to do Error handling on this, e.g.

if rundoc < 32 ; printout msg;

How would I do that in Flexsim?

Thanks,

Jarek

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ London MT commented ·

You can print messages to the output console using print() or pt() and pr(). You can print messages to the system console using mpt() and mpr(). If you want a dialog box to appear, you can use the msg() command. You could also write a file, using fpt() and fpr().

0 Likes 0 ·
London MT avatar image London MT Jordan Johnson ♦♦ commented ·

@jordan.johnson I meant the following:

int errorcode = rundocument(...);

if (errorcode < 32)

{

mpt(ErrorcodeToString(errorcode));

}

So I want to know if it's possible in Flexsim to get something like FormatMessage to be able to do error handling around this. If ErrorcodeToString is a simple user-defined command I would also be keen to hear your ideas on how to do that.

Hope this was clear. Many Thanks.

0 Likes 0 ·
Show more comments