From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem creating variant variable

Hello!

 

I have issues with the filetype VARIANT and the Excel function Excel_WorkbookSaveAs.

 

I am getting the following error:

 

159, 5 error: unexpected type name 'VARIANT': expected expression

 

Below you will finde an excerpt of my code. I am creating the VARIANT var to store the filename of an Excel Workbook. To concert a string to variant I am using CA_VariantSetCString. I assume the reason for the error is a missing header file where the type VARIANT is defined, but I couldn't figure out which one.

 

Does anyone has an idea how to fix this error?

 

Thanks!

 

#include "excelreport.h"
#include "excel2000.h"
#include <cvirte.h>		
#include <userint.h>

...

VARIANT vFilename;
	CA_VariantSetCString(&vFilename,"Test_xlsx_xls");
	Excel_WorkbookSaveAs(workbookHandle, NULL,vFilename, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, ExcelConst_xlNoChange, CA_DEFAULT_VAL,CA_DEFAULT_VAL,CA_DEFAULT_VAL,CA_DEFAULT_VAL);						 
0 Kudos
Message 1 of 6
(5,041 Views)

From the code excerpt you posted it's not possible to understand what that error means; neither we know on which line the error arises... 

 

VARIANT type is defined in OAIdl.h file: nevertheless, I discourage you from including this file alone, since you may be missing some other necessary include. Additionally, simply including excel2000dem.h should be enough for the program to compile successfully. In my opinion the error is not in a missing include, especially if you are using VARIANT type elsewere in the code without similar errors: it possibly lies in some problem in the lines immediately preceding the offending one (e.g. a missing semicolon or something like that).

 

 

BTW, the filename you are using is missing the necessary extension: this can prevent automatically opening the file once created and could ultimately generate runtime errors while running the code (I don't remember how tolerant is Excel automation in this respect).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(5,027 Views)

The error occurs during the declaration of the

 

VARIANT vFilename;

 

and it is the first time that I am using the VARIANT type. Before adding the posted lines, the code compiled without a problem, so I would assume the VARIANT caused the problem. (This was the reason why I posted just the small excerpt ;))

 

Thanks for the hint with the filepath! I really need to change that in the future. Without any extension Excel just opens the doc from My Documents.

0 Kudos
Message 3 of 6
(5,011 Views)

Does the VARIANT declaration work anywhere else in the project or in other projects? 

 

[Edit] I made a mistake in my build that I posted previously. Take a look at the LabWindows/CVI ActiveX Excel Example. You can find in in the Help >> Find Examples by searching  Excel, or by looking here:
C:\Users\Public\Documents\National Instruments\CVI2013\samples\activex\excel

 

It looks like this example does not have the VARIANT type, but it at least shows you how to use ActiveX for Excel in LabWindows/CVI.

Taylor B.
National Instruments
0 Kudos
Message 4 of 6
(5,006 Views)

Hello,

 

There is a Data Types shipping for LabWindows/CVI. You can find it by going to Help >> Find Examples and searching "variant". The name of the example is: DataTypes.cws.
Also it can be found here: C:\Users\Public\Documents\National Instruments\CVI2013\samples\activex\servers\Datatypes

 

This example does use VARAINT.

 

Taylor B.
National Instruments
0 Kudos
Message 5 of 6
(5,001 Views)

PMFJI, but unless you have C99 extensions enabled, you can only declare automatic variables at the start of a block (i.e. immediately after a {). If variables are declared after an expression, then you will get exactly the error you describe.

 

Have you enabled C99 extensions (Options|Build Options...)?

--
Martin
Certified CVI Developer
0 Kudos
Message 6 of 6
(4,980 Views)