Page 1 of 1

Skip case-fix for keyword in Macro call

Posted: Mon Jul 30, 2012 3:54 pm
by Tenaja
If you ever need to use DEFAULT as a macro parameter, the IDE case-corrects it to Default. This can mess you up if you require it to be in all caps. (And yes, I required the parameter to NOT be in quotes.) Here is an example with the workaround:

Code: Select all

Dim MySettings.s(0)
Macro DoubleQuote
"
EndMacro
Macro DEFc
	DEF
EndMacro
Macro AULTc
	AULT
EndMacro

Macro InitSettings(SetName)								;  creates a constant, adds one to MySettings array size, and fills it with the text.
	ReDim MySettings(#PB_Compiler_EnumerationValue)
	Enumeration #PB_Compiler_EnumerationValue
		#SETTING_#SetName
	EndEnumeration
	MySettings(#SETTING_#SetName)		= DoubleQuote#SetName#DoubleQuote
EndMacro

InitSettings(DEFc#AULTc)		; <--- makes just this ONE word, DEFAULT all caps
InitSettings(SET_ONE)
InitSettings(SET_TWO)

Debug MySettings(0)				; Prints string in all caps
Debug #SETTING_DEFAULT			; All constants are defined with all caps, too.
Debug MySettings(1)
Debug #SETTING_SET_ONE
Debug MySettings(2)
Debug #SETTING_SET_TWO
This is a hack I just threw together, but it works. Feel free to add other methods.

And I think it may be posted elsewhere, but just in case it is not, this is also a method to cleanly initialize an array without the dreaded data + read loop. I have not measured the cost of the ReDim (in terms of speed) but since there is no loop, it can't be too bad. This method works great when you have numerous settings to deal with, and avoids typing an Enumeration and Data, and hope they stay synchronized.