Fix for Smarterm macro error: “Error in line: Script is too large to be compiled”
I had long been besieged by this error, and I know I can’t be the only one. I could find nothing regarding this error in the manual, the help file, or even endless Googling. Splitting your code out to multiple .stm macro files is the easy answer. But that is problematic because passing variables to functions between macro files is iffy at best. I don’t think it’s even possible without using precompiled files.
I finally stumbled across this forum post.
http://www.pstnet.com/forum/Topic1767-5-1.aspx
It was about some psychology software tool but apparently the same principle applies.
That led me to this: http://www.pstnet.com/support/kb.asp?TopicID=1300
Remove string literals. That’s it. You may not remember what a string literal is, in your subs or functions, if you put some text within quotes: sName = “Beverly” that is a string literal. I found that I use these all over the place. When you record a macro and then look at the code it uses string literals. The code samples in the macro guide are littered with literals. So I’d always assumed that this was the proper way to do things.
Anyway so what to do? You can’t just remove these string literals they are essential. One easy thing to do is replace anything you can with one of the built in constants.
So instead of using “” use ebNullString.
Sub Test1() If x = "" Then Exit Sub End If 'Change it to this: If x = ebNullString Then Exit Sub End If End Sub
I was able to do a search and replace and found that I’d used “” all over the place.
If you need even more space take it a step further, replace string literals with constants.
‘For those string literals you create, make a constant instead:
Sub ChooseLoop() If sName = "West" Then Call WestLoop() Else Call EastLoop() End If End Sub 'Outside the sub declare a constant instead: Const WEST = "West" Sub ChooseLoop() If sName = WEST Then Call WestLoop() Else Call EastLoop() End If End Sub
By replacing just a couple of my commonly used string literals, I gained an extra 37 lines of compile space!