You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Language/Concepts/Getting-Started/deftype-statements.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,21 +59,33 @@ The statement name determines the data type.
59
59
60
60
<br/>
61
61
62
+
For example, in the following program fragment, `Message` is a string variable:
63
+
64
+
```vb
65
+
DefStrA-Q
66
+
...
67
+
Message="Out of stack space."
68
+
```
69
+
62
70
A **Def**_type_ statement affects only the [module](../../Glossary/vbe-glossary.md#module) where it is used. For example, a **DefInt** statement in one module affects only the default data type of variables, arguments passed to procedures, and the return type for **Function** and **Property Get** procedures declared in that module; the default data type of variables, arguments, and return types in other modules is unaffected. If not explicitly declared with a **Def**_type_ statement, the default data type for all variables, all arguments, all **Function** procedures, and all **Property Get** procedures is **Variant**.
63
71
64
72
When you specify a letter range, it usually defines the data type for variables that begin with letters in the [first 128 characters of the character set](../../reference/user-interface-help/character-set-0127.md). However, when you specify the letter range A-Z, you set the default to the specified data type for all variables, including variables that begin with international characters from the [extended part of the character set (128-255)](../../reference/user-interface-help/character-set-128255.md).
65
73
66
74
After the range A-Z has been specified, you can't further redefine any subranges of variables by using **Def**_type_ statements. After a range has been specified, if you include a previously defined letter in another **Def**_type_ statement, an error occurs. However, you can explicitly specify the data type of any variable, defined or not, by using a **[Dim](../../reference/user-interface-help/dim-statement.md)** statement with an **As**_type_ clause.
67
75
68
-
<!--[MISSING EXAMPLE CODE] For example, you can use the following code at the module level to define a variable as a **Double** even though the default data type is **Integer**: -->
76
+
For example, you can use the following code at the module level to define a variable as a **Double** even though the default data type is **Integer**:
77
+
78
+
```vb
79
+
DefIntA-Z
80
+
DimTaxRateAsDouble
81
+
```
69
82
70
83
**Def**_type_ statements don't affect elements of [user-defined types](../../Glossary/vbe-glossary.md#user-defined-type) because the elements must be explicitly declared.
71
84
72
-
<!--[MISSING EXAMPLE CODE and SUBJECT] For example, in the following program fragment, is a string variable:-->
73
85
74
86
<!--[MISSING EXAMPLE CODE] ## Example
75
87
76
-
This example shows various uses of the **Def**_type_ statements to set default data types of variables and function procedures whose names start with specified characters. The default data type can be overridden only by explicit assignment by using the **Dim** statement. **Def**_type_ statements can only be used at the module level (that is, not within procedures).-->
88
+
This example shows various uses of the **Def**_type_ statements to set default data types of variables and function procedures whose names start with specified characters. The default data type can be overridden only by explicit assignment by using the **Dim** statement. **Def**_type_ statements can only be used at the module level (that is, not within procedures).-->
@@ -28,10 +28,10 @@ The **Mid** statement syntax has these parts.
28
28
29
29
## Remarks
30
30
31
-
The number of characters replaced is always less than or equal to the number of characters in _stringvar_.
31
+
The number of characters replaced is always less than or equal to the number of characters in _stringvar_.
32
32
33
33
> [!NOTE]
34
-
> Use the **MidB** statement with byte data contained in a string. In the **MidB** statement, _start_ specifies the byte position within _stringvar_ where replacement begins and _length_ specifies the numbers of bytes to replace.
34
+
> Use the **MidB** statement with byte data contained in a string. In the **MidB** statement, _start_ specifies the byte position within _stringvar_ where replacement begins, and _length_ specifies the numbers of bytes to replace.
The required _path_[argument](../../Glossary/vbe-glossary.md#argument) is a [string expression](../../Glossary/vbe-glossary.md#string-expression) that identifies the directory or folder to be created. The _path_ may include the drive. If no drive is specified, **MkDir** creates the new directory or folder on the current drive.
20
+
The required _path_[argument](../../Glossary/vbe-glossary.md#argument) is a [string expression](../../Glossary/vbe-glossary.md#string-expression) that identifies the directory or folder to be created. The _path_ may include the drive. If no drive is specified, **MkDir** creates the new directory or folder on the current drive.
21
21
22
22
## Example
23
23
24
-
This example uses the **MkDir** statement to create a directory or folder. If the drive is not specified, the new directory or folder is created on the current drive.
24
+
This example uses the **MkDir** statement to create a directory or folder. If the drive is not specified, the new directory or folder is created on the current drive.
|_oldpathname_|Required. [String expression](../../Glossary/vbe-glossary.md#string-expression) that specifies the existing file name and location — may include directory or folder, and drive.|
26
-
|_newpathname_|Required. String expression that specifies the new file name and location — may include directory or folder, and drive. The file name specified by_newpathname_ can't already exist.|
24
+
|_oldpathname_|Required. [String expression](../../Glossary/vbe-glossary.md#string-expression) that specifies the existing file name and location; may include directory or folder, and drive.|
25
+
|_newpathname_|Required. String expression that specifies the new file name and location; may include directory or folder, and drive. The file name specified by _newpathname_ can't already exist.|
27
26
28
27
## Remarks
29
28
30
-
The Name statement renames a file and moves it to a different directory or folder, if necessary. Name can move a file across drives, but it can only rename an existing directory or folder when both newpathname and oldpathname are located on the same drive. Name cannot create a new file, directory, or folder.
31
-
Using **Name** on an open file produces an error. You must close an open file before renaming it. **Name**[arguments](../../Glossary/vbe-glossary.md#argument) cannot include multiple-character (**\***) and single-character (**?**) wildcards.
29
+
The **Name** statement renames a file and moves it to a different directory or folder, if necessary. **Name** can move a file across drives, but it can only rename an existing directory or folder when both _newpathname_ and _oldpathname_ are located on the same drive. **Name** cannot create a new file, directory, or folder.
30
+
31
+
Using **Name** on an open file produces an error. You must close an open file before renaming it. **Name**[arguments](../../Glossary/vbe-glossary.md#argument) cannot include multiple-character (**\***) and single-character (**?**) wildcards.
32
32
33
33
## Example
34
34
35
-
This example uses the **Name** statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist. On the Macintosh, "HD:" is the default drive name and portions of the pathname are separated by colons instead of backslashes.
35
+
This example uses the **Name** statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist. On the Macintosh, "HD:" is the default drive name, and portions of the pathname are separated by colons instead of backslashes.
36
36
37
37
38
38
```vb
@@ -45,4 +45,7 @@ Name OldName As NewName ' Move and rename file.
0 commit comments