cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Data import a file based on a programme variable

PhilipOakley
5-Regular Member

Data import a file based on a programme variable

(This is for V14 M030 (or V11.2a))

I'm looking for the workaround to allow the data import component to allow the file name for import to be selected programmatically. The basic wizard requires one to set the filename, and to edit it via the right click properties.

A colleague has been tasked with auto processing ~50 different data sets, so doing it by hand is not really a sensible solution. (One of the issues is the data file also has some columns which are hex data, so we need the general data entry, and then post proces it once it's inside mathcad, or use matlab (not as nice)

I'm sure there was a work around I Just can't find it at the moment. Anyone remember how to do it?

Philip

ACCEPTED SOLUTION

Accepted Solutions

It depends on how the component, or better which component is inserted.

If you use "Insert/Data/File Input" the filename can only be changed by using the properties menu (or possibly via script.

But if you use "Insert/Data/Data Import Wizard" or "Insert/Component/Data Import Wizard" you can add exactly one Input Variable and that is taken automatically as the path/filename.

View solution in original post

9 REPLIES 9

Not sure if this would suffice, but if you insert a table using the wizard you can right click and then chose "Add Input variable". This field would be taken as filename and accepts a Mathcad string variable, so I guess you can make it a function with that input variable as parameter.

PhilipOakley
5-Regular Member
(To:Werner_E)

Many of the components don't appear to allow the 'add input variable', and then there is the problem of associating the variable with the place the component reads the filename from. It appears quite tricky.

It depends on how the component, or better which component is inserted.

If you use "Insert/Data/File Input" the filename can only be changed by using the properties menu (or possibly via script.

But if you use "Insert/Data/Data Import Wizard" or "Insert/Component/Data Import Wizard" you can add exactly one Input Variable and that is taken automatically as the path/filename.

PhilipOakley
5-Regular Member
(To:Werner_E)

That looks like the distinction I was looking for. It's no so easy to detect these subtle differences that depend on how you insert the component.

I've passed it on to my colleague and hopefully he'll test it soon 😉

Philip

I've tried to get this method to address multiple files without success--the only way I can envision is to embed the component in a program, something Mathcad doesn't want to do.

You can pass a list of filenames to the READFILE function, and put that in a loop

Turn the component into a function. So, for example, in the output variable placeholder write "GetData(FileName)" and in the input variable placeholder write "FileName". You can then call the function GetData in a program.

Could you do it with a script?

PhilipOakley
5-Regular Member
(To:RichardJ)

I've got the basics for a script that could be adapted, but sometimes one wants to avoid inflicting additional VBscripting tasks on the users (and the debugging hassle).

It would be good if the data import function could take a format string so that it could cope with different separators, hex data, and ignorable columns 😉 But you can't have everything when you are waiting for prime time.

I've got the basics for a script that could be adapted, but sometimes one wants to avoid inflicting additional VBscripting tasks on the users (and the debugging hassle).

I would always want to avoid it. Unfortunately, Mathcad's file handling has never been as versatile or complete as needed, so sometimes there is no choice.

It would be good if the data import function could take a format string so that it could cope with different separators, hex data, and ignorable columns 😉 But you can't have everything when you are waiting for prime time.

We can't even have the things we already have

Announcements

Top Tags