Char type not defined

Dim myChar As Char

throws a compilation error: "Custom type not defined"

What reference should be included in type Char?

+4
source share
2 answers

Chartype does not exist in VBA, should be used instead String.

Dim myChar As String

Please note that VBA does not match VB.NET. In VB.NET you can use Char.

EDIT: Following Michał Krzych's suggestion, I am using a fixed-length string for this particular purpose.

Dim myChar As String * 1

Here is an excerpt from the "VBA Developer Reference" by Ken Goetz and Mike Gilbert :

" VBA , , ".... " , , . , , . ."

, ;

Sub foo (char * 1) '

...

Sub

, ;

Sub foo (char ) '

Sub foo (char ) '

, , , . VBA , .

+5

, , :

Sub Test()
    Dim strA As String, strB As Byte, strC As Integer, strD As Long

    strA = "A"
    strB = 65
    strC = 75
    strD = 90

    Debug.Print Asc(strA) '65
    Debug.Print Chr(strB) 'A
    Debug.Print Chr(strC) 'K
    Debug.Print Chr(strD) 'Z
End Sub
+3

All Articles