In VB6, do declared fields have default values? - vb6

I am going through some old VB6 code and in many forms, I encounter declaration statements like -
PEC_NUM_ENT(1) As Byte
EC_MORE_RW_EXIST(0) As Byte
EC_CODE_IND(0) As Byte
EC_DATA(7) As PRXDetail
My question is, do these fields have default values? If so, what are the values? Thanks.

Yes. Numerical and date types default to 0, strings to an empty string (i.e., ""), boolean to False, and variant to EMPTY.

From the VB6 documentation
When variables are initialized, a
numeric variable is initialized to 0,
a variable-length string is
initialized to a zero-length string
(""), and a fixed-length string is
filled with zeros. Variant variables
are initialized to Empty. Each element
of a user-defined type variable is
initialized as if it were a separate
variable.
PRXDETAIL looks like it might be a user-defined type

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.

How to validate that value is an Integer with Firebase rules

I'm trying to make sure that some field of an object in firebase is an integer and not decimal. There is a method isNumber() but it returns true wheter value is an integer or a decimal.
I've tried to check a value with regex, but for some reason it works properly only with values within quotation marks ie strings.
This is how my rule looks:
"$item_id":{
"created":{
".validate":"newData.val().matches(/^[0-9]+$/)"
}
}
So when I put an object with string value like this {"created":"123456789"} validation works fine. But when I put an object with number value {"created":123456789} validation fails.
Is there a way to do this?
You cannot use a regular expression to validate a number, since regular expressions match patterns in strings.
You can also not really validate that something is an integer, since JavaScript doesn't have a separate integer vs floating point type. They're all just floating point numbers.
What you can validate is that something is a whole number. The simplest way I could come up with is:
".validate":"newData.isNumber() && newData.val() % 1 === 0.0"
This accepts 1 and 1.0, but will reject 1.1.

Ruby send string variable as hex

How am I to express variable as hex to send like-
a='00'
write("\x#{a}") => 0x00
Trying to include received string variable into command string of raw data and passed to com port like -
cmd="\x45\x#{a}\x01"
Send(cmd)
In Ruby
Thanks
The String#to_i function takes a base argument, which default to ten - but you can pass in sixteen instead. That'll get you the number you want as a number, rather than a string. From there, you can use the Integer#chr function to get the value you want - a string containing the character with the binary value represented by the original string.

MaskedTextBox with PasswordChar defined, how to get the displayed string value?

I have a MaskedTextBox with the PasswordChar defined so that relevant characters are not displayed raw but instead have the defined PasswordChar used instead. Just like a traditional password entry field, except I have a Mask defined so that not all the characters are turned into the PasswordChar.
I want to get the string that is actually being displayed. If I use the MaskedTextBox.Text property it gives me the raw string without substituting the PasswordChar setting. This is a problem as I want the string that has the PasswordChar values used. Any ideas?
maskedTextBox1.MaskedTextProvider.ToDisplayString()

What does this VB6 variable declaration do?

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.

Resources