MazterzDemon

either i did this wrong or vb is wrong...

im try to get the label to show if the current file is ReadOnly or not...

If Label4.Text = IO.FileAttributes.ReadOnly = True Then

Label11.Text = "Read-Only File"

ElseIf Label4.Text = IO.FileAttributes.ReadOnly = False Then

Label11.Text = "Not ReadOnly"

Else

Label11.Text = ("Select a Proper File")

End If

But when i go to debug mode and activate the command it says

Conversion from string "C:\" to type 'Double' is not valid.

on the first IF command

and if the file path is incorrect it should automatically use the "Label11.Text = ("Select a Proper File")" right

i understand i could be using the fileattributes.readonly wrong....

somone tell me how though




Re: Visual Basic Express Edition VB not recognizing else command?

Brendan Grant

Try this instead:

Code Snippet

Dim f As New IO.FileInfo(Label4.Text)

If f.Exists Then

If f.Attributes And IO.FileAttributes.ReadOnly Then
Label11.Text = "Read-Only File"
Else
Label11.Text = "Not ReadOnly"
End If

Else
Label11.Text = ("Select a Proper File")
End If

Here we use the value of Label4 to create a FileInfo instance with which we can check the file attributes, but first we see if the file exists and if not, display the warning message to Label11, otherwise we check to see if the file is read-only or not.

Does this work better for you






Re: Visual Basic Express Edition VB not recognizing else command?

MazterzDemon

do i need to add a DIM command

it says F is not declared

if so wuts the Dim code






Re: Visual Basic Express Edition VB not recognizing else command?

Brendan Grant

Oops, I missed a line on the copy/paste.

The example above has been updated with the proper Dim statement.






Re: Visual Basic Express Edition VB not recognizing else command?

js06

I don't know if this is any better but i had it so here you go

I was wondering, why are you using a label to store the path

If My.Computer.FileSystem.GetFileInfo(Me.Label4.Text.ToString).Attributes = IO.FileAttributes.ReadOnly Then

MsgBox("read only")

Else

MsgBox("Not read only")

End If






Re: Visual Basic Express Edition VB not recognizing else command?

MazterzDemon

all right, it works thanks...

.... do youknow if tehres a way to change that property from my program... lol






Re: Visual Basic Express Edition VB not recognizing else command?

MazterzDemon

oh becuase the user types the directory in the textbox1 and the filename in textbox2 and picks the extension in a the combobox..

its for creating, moddifing and deleting files...






Re: Visual Basic Express Edition VB not recognizing else command?

js06

My.Computer.FileSystem.GetFileInfo("filename").Attributes = IO. FileAttributes.ReadOnly

My.Computer.FileSystem.GetFileInfo("filename").Attributes = IO.FileAttributes.Normal