What's the meaning of the asterisk (*) and the number, after the variable declaration? As seen in WpName As String * 6
Public Type WayPoint
WpIndex As Integer
WpName As String * 6
WpLat As Double
WpLon As Double
WpLatDir As String * 1
WpLonDir As String * 1
End Type
The asterisk declares the variable as a fixed-length string, where the number indicates the length of the string:
http://www.1sayfa.com/1024/diger/vb/ch07.htm#Heading8
The declaration of a fixed-length string variable contains an asterisk (*) to tell Visual Basic that the string will be a fixed length. The final parameter, strlength, tells the program the number of characters that the variable can contain.
They may be required for an API call, see this question:
VB6 - Is there any performance benefit gained by using fixed-width strings in VB6?
The only time in VB6 or earlier that I had to use fixed length strings was with working with API calls.
Related
This question already has an answer here:
more than one character in rune literal in go [closed]
(1 answer)
Closed 8 months ago.
I am new to Go language i just started learning by doing, but while running this code, im getting
the error as:
a./prog.go:41:11: invalid character literal (more than one character)
package main
import ("fmt")
func main() {
const NAME = "Michael"
const(
age int = 22
color = 'Fair'
)
fmt.Println(NAME)
fmt.Println(age)
fmt.Println(color)
}
In the above code, you are using single quotes for color variable value, that is what causing this error, try changing it to double quotes as below:
color = "Fair"
this should work.
(Not only) for Go, it can be a good exercise to have open the Go Reference Specification, as it is quite short and written for the language user. Here is what the official rules say about "runes" and "strings":
Rune Literals
A rune literal represents a rune constant, an integer value identifying a Unicode code point. A rune literal is expressed as one or more characters enclosed in single quotes, as in 'x' or '\n'.
For strings:
String Literals
[there are two types, raw and interpreted string literals!]
Raw string literals are character sequences between back quotes, as in `foo`. [...]
Interpreted string literals are character sequences between double quotes, as in "bar".
It can be handy to browse through the surrounding paragraphs to discover more rules and possible gotchas that one might encounter when coming from other languages.
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.
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!!
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.
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.