Microsoft KB Archive/841701

= You receive an &quot;Invalid procedure call or argument&quot; error message when you call the SetAttr function in Visual Basic 6.0 =

Article ID: 841701

Article Last Modified on 5/21/2004

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Learning Edition

-



SYMPTOMS
In Microsoft Visual Basic 6.0, when you call the SetAttr function, you may receive the following error message:

Invalid procedure call or argument



CAUSE
This problem occurs because you are trying to set a read-only attribute. The error typically occurs when the Attributes parameter of the SetAttr function contains a value that corresponds to the Alias attribute, the Directory attribute, or the Volume attribute. This error occurs when either of the following conditions are true:
 * You retrieve the file attributes of a file or a directory that has the Alias attribute, the Directory attribute, or the Volume attribute set. Then you pass these file attributes as the Attributes parameter of the SetAttr function.
 * You pass the vbAlias constant, the vbDirectory constant, or the vbVolume constant as the Attributes parameter of the SetAttr function.



Steps to reproduce the behavior
 In drive C on your computer, create a directory that is named MyDir. In drive C on your computer, create a text file that is named Test.txt. Start Visual Basic 6.0. On the File menu, click New Project. The New Project dialog box appears. Click Standard EXE, and then click OK. By default, a form that is named Form1 is created. On the Project menu, click References. The References – Project1 dialog box appears. Under Available References, select the Microsoft Scripting Runtime library, and then click OK.</li> Add a command button to the Form1 form. By default, the Command1 command button is added.</li>  Double-click the Command1 command button, and then replace the existing code with the following code: Option Explicit

Private Sub Command1_Click Dim FileAttr As FileAttribute

'MyDir is a directory in drive C on your computer. 'Retrieve the file attributes of the MyDir directory. 'Because MyDir is a directory, the FileAttr variable contains the Directory attribute. FileAttr = GetAttr(&quot;C:\MyDir&quot;)

'Try to set the attributes of the Test.txt file. 'Because the Directory attribute is a read-only attribute, an error occurs. SetAttr &quot;C:\Test.txt&quot;, FileAttr

MsgBox &quot;The file attributes have been set.&quot;

End Sub </li> On the Run menu, click Start. The Form1 form appears.</li> Click Command1. You receive the error message that is mentioned in the &quot;Symptoms&quot; section.</li></ol>

Keywords: kberrmsg kbprb kbfileio KB841701

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.