I have macros named
CONSTANT_1
CONSTANT_2
CONSTANT_3
CONSTANT_4 etc..
I have an NSString variable sending from another class consist of macro name only, how can I access the contents of macro variable matching with this NSString.
My NSString variable is defined as:
NSString *str=@"CONSTANT_3"
You can always right-click the button, left click on Assign Macro, and see the name of the macro that way. I assume you mean it is a Forms button, which makes sense because it's a macro as you said, not a procedure written into a command button click. 64, "Information about macro being run..."
Ideally, I would like to be able to both check that a macro is defined, and check that it equals a certain value, in one line. If it is not defined, the preprocessor throws an error (or warning). It's like a combination of #ifdef and #if, and if it doesn't exist, uses #error.
The most secure way to see macros content without running them is to open Visual Basic Editor from you office document which will contain the content of the macros. To open Visual Basic Editor (Office 2010, probably 2013 and 2016): In the right section, select "Developer", it will add a tab "Developer" on the Ribbon.
is an unreliable way to check if the excel file has macros. To test it, create a workbook, say Book1.xlsm and insert a module but don't type any code. Close the file and in a new Excel file run this code from a module.
1 Here is one solution to do it, but it needs you to know all macros:
#define CONSTANT_1 1
#define CONSTANT_2 2
#define CONSTANT_3 3
#define STRINGIZE(x) #x
+ (int)getValueForContant:(NSString *)constantStr {
const char *charStr = STRINGIZE(CONSTANT_1);
NSString *str = [NSString stringWithUTF8String:charStr];
if ([constantStr isEqualToString:str]) {
return CONSTANT_1;
}
charStr = STRINGIZE(CONSTANT_2);
str = [NSString stringWithUTF8String:charStr];
if ([constantStr isEqualToString:str]) {
return CONSTANT_2;
}
return -1;
}
And use it as:
int constVal = [ClassName getValueForContant:@"CONSTANT_1"];
It'll give you int
value in return.
2 Use .plist
to define constants and loop through to get appropriate value as provided string parameter to this method;
+ (int)getValueForContant:(NSString *)constantStr
I would recommend to better use constants
NSString *const CONSTANT_1 = @"1";
NSString *const CONSTANT_2 = @"2";
NSString *const CONSTANT_3 = @"3";
The you could use CFBundleGetDataPointerForName
-(NSString *)valueOfConstantWithName:(NSString *)constantName {
void ** pointer = CFBundleGetDataPointerForName(CFBundleGetMainBundle(), (__bridge CFStringRef)constantName);
return (__bridge NSString *)(pointer ? *pointer : nil);
}
and use that method like
NSString *costant1 = [self valueOfConstantWithName:@"CONSTANT_1"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With