Click to See Complete Forum and Search --> : URGENT!!! Keyword


kent_ng
August 17th, 1999, 09:50 AM
How can I use a keyword as a function or sub routine name?

ex. Private Sub Select
%2

Lothar Haensler
August 17th, 1999, 10:48 AM
you can't.
From the docs:
"They can't be the same as restricted keywords.
A restricted keyword is a word that Visual Basic uses as part of its language. This includes predefined statements (such as If and Loop), functions (such as Len and Abs), and operators (such as Or and Mod)."
"They" refers to variables. The variable naming conventions are valid for variables and user-defined procedures.

kent_ng
August 17th, 1999, 11:11 AM
The problem that I am having is I must provide a SELECT SUB in my VB program, an OLE automation program,
to another app that's using calling SELECT in my program and the worst of all I can't change that app that's calling my
program!!!! :(.
So, is there any way that i could create a sub with SELECT as the sub name??

August 18th, 1999, 08:49 AM
I have just dealt with a similar problem. I am using an automation interface and one of the methods is named "Print" which is a keyword in Visual Basic. To solve it, I
put square brackets around the method name. So, instead of writing pDoc.Print " ", 1 , 1, true, true, true, true I have to say pDoc.[Print] " ", 1 , 1, true, true, true, true




I got the answer from the MSDN library and this is what it says:

Naming Conventions in Visual Basic

While you are writing Visual Basic code, you declare and name many elements (Sub and Function procedures, variables, constants, and so on). The names of the procedures, variables, and constants that you declare in your Visual Basic code must follow these guidelines:

They must begin with a letter.


They can't contain embedded periods or type-declaration characters (special characters that specify a data type.


They can be no longer than 255 characters. The names of controls, forms, classes, and modules must not exceed 40 characters.


They can't be the same as restricted keywords.
A restricted keyword is a word that Visual Basic uses as part of its language. This includes predefined statements (such as If and Loop), functions (such as Len and Abs), and operators (such as Or and Mod).

For More Information For a complete list of keywords, see the Language Reference.

Your forms and controls can have the same name as a restricted keyword. For example, you can have a control named Loop. In your code you cannot refer to that control in the usual way, however, because Visual Basic assumes you mean the Loop keyword. For example, this code causes an error:

Loop.Visible = True ' Causes an error.

To refer to a form or control that has the same name as a restricted keyword, you must either qualify it or surround it with square brackets: [ ]. For example, this code does not cause an error:

MyForm.Loop.Visible = True ' Qualified with the form
' name.
[Loop].Visible = True ' Square brackets also
' work.

You can use square brackets in this way when referring to forms and controls, but not when declaring a variable or defining a procedure with the same name as a restricted keyword. Square brackets can also be used to force Visual Basic to accept names provided by other type libraries that conflict with restricted keywords.

August 18th, 1999, 08:58 AM
The problem that I am having is that I have to create a sub using the keyword SELECT, not%