Set length on DIM statement

G

Glenn Suggs

Can anyone tell me the syntax of a DIM statement where you want to define a
variable as fixed length? I've used it before but can't remember and I can't
locate it in the Help screens.

Thanks in advance
 
D

Douglas J Steele

You can only do it with string variables:

Dim strName As String(20)

will limit the variable to 20 characters.
 
A

Allen Browne

Dim MyString As String * 50

Example:

Public Sub ShowFixedLength()
Dim stf As String * 32 'Fixed length string.

stf = "Everything after the first 32 characters is lost."
Debug.Print stf
stf = "Has trailing spaces"
Debug.Print stf & "." 'Dot shows where spaces end.
End Sub
 
D

Douglas J Steele

Oops. Allen and Klatuu are correct: it's String * 20, not String(20).

Sorry about that.
 
Top