a%&8b is valid variable name or not in BASIC - vb6

a%&8b is valid variable name basic
Suggest me if it is valid in VB6
Help me. It is my exams

a%&8b is NOT a valid name. Specifically, you cannot have & and % in the name.
The rules for VBA are:
You must use a letter as the first character.
You can't use a space, period (.), exclamation mark (!), or the characters #, &, $, # in the name.
Name can't exceed 255 characters in length.
Another source on VB6 lists the following:
Variable names in Visual Basic are made up of letters (upper and lower case) and digits. The underscore character, "_", is also permitted. Names must not begin with a digit. Names can be as long as you like.
Some examples of valid (but not very descriptive) Visual Basic variable names:
foo
Bar
BAZ
foo_bar
a_foo42_
QuUx
Some examples of invalid Visual Basic variable names:
2foo
must not begin with a digit
my foo
spaces not allowed in names
$foo
$ not allowed -- only letters, digits, and _
while
language keywords cannot be used as names
_xxx
leading underscore not allowed.

Related

What is the usage of tilde symbol (~) in oracle

What is the usage of tilde symbol (~) in Oracle.
Please share me the output for the below query if we are using the column name and table name with two tilde symbols.
SELECT ~column_name~ from ~Table_name~
From the Database Object Names and Qualifiers documentation:
Nonquoted identifiers must begin with an alphabetic character from your database character set. Quoted identifiers can begin with any character.
Nonquoted identifiers can contain only alphanumeric characters from your database character set and the underscore (_), dollar sign ($), and pound sign (#). Database links can also contain periods (.) and "at" signs (#). Oracle strongly discourages you from using $ and # in nonquoted identifiers.
Quoted identifiers can contain any characters and punctuations marks as well as spaces. However, neither quoted nor nonquoted identifiers can contain double quotation marks or the null character (\0).
In the query:
SELECT ~column_name~ from ~Table_name~
~column_name~ and ~Table_name~ are non-quoted identifiers as they are not surrounded by double-quotes ". However, since they do not start with an alphabetic character and they contain ~ characters (which are not alpha-numeric, _, $ or #) then the identifiers are invalid and the query will raise an exception, outputting:
ORA-00911: invalid character
and will not execute.
fiddle
To directly answer the title of your question, tilde is rarely used as a PL/SQL not equals operator:
begin
if 1 ~= 2 then
dbms_output.put_line('Not equal');
end if;
end;
/
As far as I know, that is the only valid use of tilde in Oracle, and as MTO explained, it certainly can't be used for object names without double quotes.

Postgres, How can I deny to create a database with a werid name (trailing space, leading space, or even avlid using space in a database name)

I'm trying to add some constraints on database creation command in PostgreSQL.
Currently, I could do
psql -c "CREATE database \" x y\"\"z' \""
Then, I will get a database named literally " x y"z' " (without the double-quotes boundary).
It seems that pgsql supports any characters in it's database name, which is cool.
But it leads me headaches when I am doing automation stuff with bash script.
Yes, some additional work could be done to handle these cases in script. But I think these kind of names are actually meaningless (at least in my situation :), so, is there a way to add some constraints on database naming. For example, only allow [a-zA-Z0-9_.]+.
Just do not use double quotes, which you should avoid anyway if at all possible. See Documentation:
SQL identifiers and key words must begin with a letter (a-z, but also
letters with diacritical marks and non-Latin letters) or an underscore
(_). Subsequent characters in an identifier or key word can be
letters, underscores, digits (0-9), or dollar signs ($). Note that
dollar signs are not allowed in identifiers according to the letter of
the SQL standard, so their use might render applications less
portable. The SQL standard will not define a key word that contains
digits or starts or ends with an underscore, so identifiers of this
form are safe against possible conflict with future extensions of the
standard. ... There is a second kind of identifier: the delimited
identifier or quoted identifier. It is formed by enclosing an
arbitrary sequence of characters in double-quotes ("). A delimited
identifier is always an identifier, never a key word. ... Quoted
identifiers can contain any character, except the character with code
zero. (To include a double quote, write two double quotes.) This
allows constructing table or column names that would otherwise not be
possible, such as ones containing spaces or ampersands.
Not doubling quoting in you examples makes those names invalid and Postgres has no problem telling about it. So just do not use them.
Alternately you could create an event trigger. Within there you can restrict object names as needed, esp useful if you have strict naming standards. This would allow for database enforcement of those standards;
create function app_validate_table_name()
returns event_trigger
language 'plpgsql'
as $$
begin
if obj.object_identity ~! '[A-Za-z$_][[A-Za-z0-9$_]{0,62}'
then
raise exception 'App Error: Request Name (%) is invalid for <Your App Name here>',obj.object_identity;
end if
return;
end ;
$$;
create event trigger app_table_event_trigger on ddl_command_end
when tag in ('ALTER TABLE', 'CREATE TABLE')
execute procedure app_validate_table_name();
While the same can be applied to other objects it unfortunately does not seem to apply to creating a database itself.
Disclamer: The above has NOT been tested.

Replace non-word characters, unless given sequence matches

I have a string like this:
"Jim-Bob's email ###hl###address###endhl### is: jb#example.com"
I want to replace all non-word characters (symbols and whitespace), except the ### delimiters.
I'm currently using:
str.gsub(/[^\w#]+/, 'X')
which yields:
"JimXBobXsXemailX###hl###address###endhl###XisXjb#exampleXcom"
In practice, this is good enough, but it offends me for two reasons:
The # in the email address is not replaced.
The use of [^\w] instead of \W feels sloppy.
How do I replace all non-word characters, unless those characters make up the ###hl### or ###endhl### delimiter strings?
str.gsub(/(###.*?###|\w+)|./) { $1 || "X" }
# => "JimXBobXsXemailX###hl###address###endhl###XisXXjbXexampleXcom"
This approach uses the fact that alternations work like case structure: the first matching one consumes the corresponding string, then no further matching is done on it. Thus, ###.*?### will consume a marker (like ###hl###; nothing else will be matched inside it. We also match any sequence of word characters. If any of those are captured, we can just return them as-is ($1). If not, then we match any other character (i.e. not inside a marker, and not a word character) and replace it with "X".
Regarding your second point, I think you are asking too much; there is no simple way to avoid that.
Regarding the first point, a simple way is to temporarily replace "###" with a character that you will never use (let's say you are using a system without "\r", so that that character is not used; we can use that as a temporal replacement).
"Jim-Bob's email ###hl###address###endhl### is: jb#example.com"
.gsub("###", "\r").gsub(/[^\w\r]/, "X").gsub("\r", "###")
# => "JimXBobXsXemailX###hl###address###endhl###XisXXjbXexampleXcom"

Significance of an ampersand in VB6 function name?

I just got a bunch of legacy VB6 (!) code dumped on me and I keep seeing functions declared with an ampersand at the end of the name, for example, Private Declare Function ShellExecute& . . ..
I've been unable to find an answer to the significance of this, nor have I been able to detect any pattern in use or signature of the functions that have been named thusly.
Anyone know if those trailing ampersands mean anything to the compiler, or at least if there's some convention that I'm missing? So far, I'm writing it off as a strange programmer, but I'd like to know for sure if there's any meaning behind it.
It means that the function returns a Long (i.e. 32-bit integer) value.
It is equivalent to
Declare Function ShellExecute(...) As Long
The full list of suffixes is as follows:
Integer %
Long &
Single !
Double #
Currency #
String $
As Philip Sheard has said it is an indentifier type for a Long. They are still present in .Net, see this MSDN link and this VB6 article
From the second article:
The rules for forming a valid VB variable name are as follows:
(1) The first character must be a letter A through Z (uppercase or
lowercase letters may be used). Succeeding characters can be letters,
digits, or the underscore (_) character (no spaces or other characters
allowed).
(2) The final character can be a "type-declaration character". Only
some of the variable types can use them, as shown below:
Data Type Type Declaration Character
String $
Integer %
Long &
Single !
Double #
Currency #
Use of type-declaration
characters in VB is not encouraged; the modern style is to use the
"As" clause in a data declaration statement.

Shell # inside (( ))

I am new to shell. I am not quite understand the following function. This function basically increase the hour by 1.
I am wondering why the developer put "10#" in front of $g_current_hour+1. From my understanding, dose # in shell means comments?
f_increment_hour() {
g_next_hour=$((10#$g_current_hour+1))
}
Everything depends on the context. Here 10# means base 10.
Constants with a leading 0 are interpreted as octal numbers. A
leading 0x or 0X denotes hexadecimal. Otherwise, numbers take the
form [base#]n, where the optional base is a decimal number between
2 and 64 representing the arithmetic base, and n is a number in that
base. If base# is omitted, then base 10 is used.
'#' will be interpreted as part of a token unless it is preceded by a space, newline, or semi-colon.
(or any other non-word symbol)
Section 2.3 "Token recognition" of the language spec, states:
7. If the current character is an unquoted <newline>, the current
token shall be delimited.
8. If the current character is an unquoted <blank>, any token
containing the previous character is delimited and the current
character shall be discarded.
9. If the previous character was part of a word, the current character
shall be appended to that word.
10. If the current character is a '#' , it and all subsequent characters
up to, but excluding, the next <newline> shall be discarded as
a comment. The <newline> that ends the line is not considered
part of the comment.
When the shell is parsing its input and reads "foo#bar", as it is processing the '#' character it applies rule 9 and appends the # to the token. Once rule 9 is applied, it stops checking and rule 10 is never considered. If the character preceding the '#' is whitespace, then rule 9 does not apply, so rule 10 is checked and a comment is started.
In other words, a '#' only starts a comment if the character preceded it is not part of a word ( eg whitespace or semi-colon), so "foo#bar" is one token, and not "foo" followed by a comment, but "foo #bar" is the token "foo" followed by a comment.

Resources