Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default File Attributes

Hi,

I am using the FileSystemObject to get a file (objImage), and need to
determine whether is has both its Hidden and System attributes set.
Help says :

To determine which attributes are set, use the And operator to perform
a bitwise comparison (a bit-by-bit comparison between identically
positioned bits in two numeric expressions) of the value returned by
the Attributes function and the value of the individual file attribute
you want. If the result is not zero, that attribute is set for the
named file.

OK. So can someone please help me understand why the first 2 work, but
the last 2 don't?!

If objImage.Attributes And vbHidden Then MsgBox "vbHidden"

If objImage.Attributes And vbSystem Then MsgBox "vbSystem"

If objImage.Attributes And vbHidden And _
objImage.Attributes And vbSystem Then MsgBox "vbHidden &
vbSystem"

If objImage.Attributes And vbHidden = vbHidden And _
objImage.Attributes And vbSystem = vbSystem Then MsgBox
"vbHidden & vbSystem"

Any guidance is much appreciated!

Cheers,

Mark

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default File Attributes

Hi Mark,

Give this a whirl

If (objImage.Attributes And vbHidden Or _
objImage.Attributes And vbSystem) = vbHidden Or vbSystem Then

or

If (objImage.Attributes And vbHidden) + _
(objImage.Attributes And vbSystem) = vbHidden + vbSystem Then

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
oups.com...
Hi,

I am using the FileSystemObject to get a file (objImage), and need to
determine whether is has both its Hidden and System attributes set.
Help says :

To determine which attributes are set, use the And operator to perform
a bitwise comparison (a bit-by-bit comparison between identically
positioned bits in two numeric expressions) of the value returned by
the Attributes function and the value of the individual file attribute
you want. If the result is not zero, that attribute is set for the
named file.

OK. So can someone please help me understand why the first 2 work, but
the last 2 don't?!

If objImage.Attributes And vbHidden Then MsgBox "vbHidden"

If objImage.Attributes And vbSystem Then MsgBox "vbSystem"

If objImage.Attributes And vbHidden And _
objImage.Attributes And vbSystem Then MsgBox "vbHidden &
vbSystem"

If objImage.Attributes And vbHidden = vbHidden And _
objImage.Attributes And vbSystem = vbSystem Then MsgBox
"vbHidden & vbSystem"

Any guidance is much appreciated!

Cheers,

Mark



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default File Attributes

Hi Bob,

There seems to be something strange with the Attribute property ...

Put this code in a new workbook:

Sub test()

x = GetAttr(Range("A1").Parent.Parent.FullName)
x = x + 34 ' Set Archive & Hidden attribute
If x = vbNormal Then MsgBox "vbNormal" ' Note, AND doesn't work!
If x And vbArchive = vbArchive Then MsgBox "vbArchive"
If x And vbHidden Then MsgBox "vbHidden"
If x And vbArchive And x And vbHidden Then MsgBox "vbArchive and
vbHidden"
If x And vbArchive = vbArchive And x And vbHidden = vbHidden Then
MsgBox "vbArchive and vbHidden"
x = 0 ' Clear Archive & Hidden attributes
If x = vbNormal Then MsgBox "vbNormal" ' Note, AND doesn't work!
If x And vbArchive Then MsgBox "vbArchive"
If x And vbHidden Then MsgBox "vbHidden"

End Sub

It seems OK, apart from the 4th If statement, which doesn't work
(whereas the 5th one does), which I don't understand.

What's more, when I apply the 4th If statement to the attribute
property of a file derived via the FileSystemObject, it actually says
that NO files meet the requirements, and the 5th one says that ALL meet
the requirements!

This has got me. It sure looks like another Excel object model oddity.

The workbook that I have the full FileSystemObject is rather large, so
I can't paste the code. I could e-mail it off-line if you're interested
......

Cheers,

Mark

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default File Attributes

When you add 34 to set the archive and hidden attributes, you should check
first that they are not already set, otherwise you distort it.

Do

x = x Or 34

I don't think the problem is with attributes, but do you understand what AND
and OR does?

If x And (vbArchive Or vbHidden) Then _
MsgBox "vbArchive and vbHidden"


--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
oups.com...
Hi Bob,

There seems to be something strange with the Attribute property ...

Put this code in a new workbook:

Sub test()

x = GetAttr(Range("A1").Parent.Parent.FullName)
x = x + 34 ' Set Archive & Hidden attribute
If x = vbNormal Then MsgBox "vbNormal" ' Note, AND doesn't work!
If x And vbArchive = vbArchive Then MsgBox "vbArchive"
If x And vbHidden Then MsgBox "vbHidden"
If x And vbArchive And x And vbHidden Then MsgBox "vbArchive and
vbHidden"
If x And vbArchive = vbArchive And x And vbHidden = vbHidden Then
MsgBox "vbArchive and vbHidden"
x = 0 ' Clear Archive & Hidden attributes
If x = vbNormal Then MsgBox "vbNormal" ' Note, AND doesn't work!
If x And vbArchive Then MsgBox "vbArchive"
If x And vbHidden Then MsgBox "vbHidden"

End Sub

It seems OK, apart from the 4th If statement, which doesn't work
(whereas the 5th one does), which I don't understand.

What's more, when I apply the 4th If statement to the attribute
property of a file derived via the FileSystemObject, it actually says
that NO files meet the requirements, and the 5th one says that ALL meet
the requirements!

This has got me. It sure looks like another Excel object model oddity.

The workbook that I have the full FileSystemObject is rather large, so
I can't paste the code. I could e-mail it off-line if you're interested
.....

Cheers,

Mark



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default File Attributes

Hi Bob,

There seems to be something strange with the Attribute property ...

Put this code in a new workbook:

Sub test()

x = GetAttr(Range("A1").Parent.Parent.FullName)
x = x + 34 ' Set Archive & Hidden attribute
If x = vbNormal Then MsgBox "vbNormal" ' Note, AND doesn't work!
If x And vbArchive = vbArchive Then MsgBox "vbArchive"
If x And vbHidden Then MsgBox "vbHidden"
If x And vbArchive And x And vbHidden Then MsgBox "vbArchive and
vbHidden"
If x And vbArchive = vbArchive And x And vbHidden = vbHidden Then
MsgBox "vbArchive and vbHidden"
x = 0 ' Clear Archive & Hidden attributes
If x = vbNormal Then MsgBox "vbNormal" ' Note, AND doesn't work!
If x And vbArchive Then MsgBox "vbArchive"
If x And vbHidden Then MsgBox "vbHidden"

End Sub

It seems OK, apart from the 4th If statement, which doesn't work
(whereas the 5th one does), which I don't understand.

What's more, when I apply the 4th If statement to the attribute
property of a file derived via the FileSystemObject, it actually says
that NO files meet the requirements, and the 5th one says that ALL meet
the requirements!

This has got me. It sure looks like another Excel object model oddity.

The workbook that I have the full FileSystemObject is rather large, so
I can't paste the code. I could e-mail it off-line if you're interested
......

Cheers,

Mark



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default File Attributes

Bob,

Meant to say, those 2 suggestions didn't help with my particular
attribute problem.

Cheers,

Mark

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data value display attributes linked to table attributes MDT at Paragon Home Inspections, LLC Charts and Charting in Excel 0 November 15th 06 12:53 AM
Getting NTFS file attributes Kiran Excel Discussion (Misc queries) 1 August 4th 05 08:13 PM
Filecopy, file attributes Eric[_28_] Excel Programming 1 February 24th 05 01:31 PM
File Attributes dsti3 Excel Discussion (Misc queries) 1 February 10th 05 05:51 AM
file attributes via macro SUNIL Excel Programming 2 January 14th 04 09:43 AM


All times are GMT +1. The time now is 06:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"