Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asterisks in variable declarations in VB6

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
like image 587
Giora Ron Genender Avatar asked Sep 03 '11 13:09

Giora Ron Genender


People also ask

How are variables declared in VB?

You declare a variable to specify its name and characteristics. The declaration statement for variables is the Dim Statement. Its location and contents determine the variable's characteristics. For variable naming rules and considerations, see Declared Element Names.

How many types of variable declaration are there in Visual Basic?

Visual Basic recognizes the following five categories of variables: Numeric. String.

What is declaration of variable?

Declaration of a variable is for informing the compiler of the following information: name of the variable, type of value it holds, and the initial value if any it takes. i.e., declaration gives details about the properties of a variable. Whereas, Definition of a variable says where the variable gets stored.

When defining a variable in VB which keyword appears at the beginning of the statement?

The As keyword precedes the declaration of the variable type (String, Date, Integer etc). For a complete list of Visual Basic variable types see Understanding Visual Basic Variable & Constant Types.


1 Answers

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.

like image 118
Luke Girvin Avatar answered Sep 20 '22 06:09

Luke Girvin