You receive an "Invalid procedure call or argument" error message when you call the SetAttr function in Visual Basic 6.0 (841701)



The information in this article applies to:

  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0

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.

MORE INFORMATION

Steps to reproduce the behavior

  1. In drive C on your computer, create a directory that is named MyDir.
  2. In drive C on your computer, create a text file that is named Test.txt.
  3. Start Visual Basic 6.0.
  4. On the File menu, click New Project. The New Project dialog box appears.
  5. Click Standard EXE, and then click OK. By default, a form that is named Form1 is created.
  6. On the Project menu, click References. The References - Project1 dialog box appears.
  7. Under Available References, select the Microsoft Scripting Runtime library, and then click OK.
  8. Add a command button to the Form1 form. By default, the Command1 command button is added.
  9. 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("C:\MyDir")
    
    'Try to set the attributes of the Test.txt file.
    'Because the Directory attribute is a read-only attribute, an error occurs.
    SetAttr "C:\Test.txt", FileAttr
    
    MsgBox "The file attributes have been set."
    
    End Sub
    
  10. On the Run menu, click Start. The Form1 form appears.
  11. Click Command1. You receive the error message that is mentioned in the "Symptoms" section.

Modification Type:MajorLast Reviewed:5/21/2004
Keywords:kbFileIO kberrmsg kbprb KB841701 kbAudDeveloper