What does this VB6 variable declaration do? - vb6

I just found this in some old code, and I'm not sure what it means.
Dim sTemp As String * 1
What is the * 1 at the end?
Thanks!

It means that the variable is a string of exactly one character in length.
Essentially, a fixed-length string.

It's a fixed length string of one character. This was handy cause you could define a structure of fixed strings and read a file right into the structure.

It creates a fixed-length string. In that example, the variable will only ever contain one character.

Related

Converting variable to type 'string' in CMake

Please tell me how does one convert a variable to a variable of type string in CMake.
I have a variable that contains both digits and letters. Say of the form: "Ax3.0.1". I don't know exactly what type of variable CMake sees this at but I want to convert it to a string so I can itterate through it. Please tell me how can I do that. Thank you.
Internally, every variable in CMake is a string. However, unlike to many other programming languages, in CMake string is not an array of characters. So one cannot directly iterate over characters in the string with foreach.
The closest thing is iteration over character indicies with extracting character by index:
set(var "Ax3.0.1")
# Compute length of the string
string(LENGTH ${var} var_length)
# But foreach needs the last index, not a range.
math(EXPR last_char_index "${var_length} - 1")
message("Characters in string '${var}':")
foreach(char_index RANGE ${last_char_index}) # Iterate over indicies
# Create variable 'char' which contains specific character of the string.
string(SUBSTRING "${var}" "${char_index}" "1" char)
message("${char}")
endforeach()
As you can see, this looks quite ugly. Actually, for extract specific character(s) from the string regular expressions are usually used.

Replacing chars in string

I have this code:
inspect w-string1 replacing all x'C48D' by 'c'
But I got this error by compiler
Operand has wrong size
Is there any solution how to replace more chars by one char thru inspect command. Or I must do it by myself via perform loop?
When using the INSPECT statement, both strings must be the same length. The only way to replace multiple characters by a different number of characters is to write your own loop to do it.

Delete all spaces at the beginning of each line in a variable that contains a large string

I use a vbs variable that contains a large string. This string holds on many lines and some of these lines begin with one or more spaces. I need to delete all spaces at beginning of each line in my variable. To do that, I use a regular expression such as ^\s+, but it only ignores spaces at begin of string and not in all lines as part of my variable.
Please could you please, help me with something that do it?
Thank you in advance
The variable holds a string that contains line break characters, is that? if it is, try setting the property Multiline of the RegExp to true.
From: http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/
(You could also split each line into an array and do the Regex on a loop on each)

VB6 Dim varCode As String * 2

what does this mean?
Dim varCode As String * 2
From my basic understanding, it means string multiply 2?
That is the syntax for a fixed length string in VB6
You are declaring a string with a length of 2.
See also: String Length Declaration for Visual Basic 6.0 Users
It means that the variable has a
LIMIT on how many characters it will hold.
Important Note:
Even if the string is empty, it will represent 2 Empty Spaces.
Example, Having:
Dim MyVar * 100
would store in a Database 100 Empty spaces if you have not set it value.
It's important to know that to save Memory and DiskSpace.
Please Rate my Answer!!

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.

Resources