• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

Deleting a file using if Keycode... HLP PLS

Hello,

Im want to del a file using the DEL key.
this is the code that won't work

Private Sub File1_Click()
    SelectedFile = File1.Path & "\" & File1.FileName
    Image1.Picture = LoadPicture(SelectedFile)
 If KeyCode = vbKeyDelete Then GoTo Kill
Exit Sub
Kill:
    MsgBox "Are you sure?"
    Kill File1.Path & "\" & File1.FileName
    File1.Refresh
End Sub

What is wrong ?!?

ThnX, TJ2002
0
TJ2002
Asked:
TJ2002
  • 5
  • 3
1 Solution
 
DeAnCommented:
use the keyup instead of click

Private Sub File1_KeyUp(KeyCode As Integer, Shift As Integer)

Integer, X As Single, Y As Single)
   SelectedFile = File1.Path & "\" & File1.FileName
   Image1.Picture = LoadPicture(SelectedFile)
If KeyCode = vbKeyDelete Then GoTo Kill
Exit Sub
Kill:
   MsgBox "Are you sure?"
   Kill File1.Path & "\" & File1.FileName
   File1.Refresh

End Sub
0
 
TJ2002Author Commented:
thnx,

but the loadPicture wont work any more....
is it also posible to use it whit multi files??

TJ
0
 
DeAnCommented:
I had some extra code in there from pasting:

  Integer, X As Single, Y As Single)

(I'm sure you got rid of that)

is the file a valid picture file you're selecting from the File1 list?

for multiple files selected you will have to loop through each selected item and kill them.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TJ2002Author Commented:
Yep.. i removed the Integer, X As Singl....

im sure that the image is valid... it works whit te 'OLD' code...

PS; the code is for a FileListBox!!, i for got to say that;p

TJ2002
0
 
DeAnCommented:
you can separate the code like this.

Private Sub File1_Click()
  Dim SelectedFile As String
  SelectedFile = File1.Path & "\" & File1.FileName
  Image1.Picture = LoadPicture(SelectedFile)
End Sub

Private Sub File1_KeyUp(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyDelete Then GoTo Kill
  Exit Sub
Kill:
  'MsgBox File1.Path & "\" & File1.FileName
  Kill File1.Path & "\" & File1.FileName
  File1.Refresh
End Sub
0
 
TJ2002Author Commented:
THANX....

It's working..

GreetZ
TJ2002
0
 
DeAnCommented:
this should delete all selected

Private Sub File1_Click()
  Dim SelectedFile As String
  SelectedFile = File1.Path & "\" & File1.FileName
  Image1.Picture = LoadPicture(SelectedFile)
End Sub

Private Sub File1_KeyUp(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyDelete Then GoTo Kill
  Exit Sub
Kill:
  Dim i As Integer
  For i = 0 To File1.ListCount - 1
    If File1.Selected(i) = True Then
    Kill File1.Path & "\" & File1.List(i)
    End If
  Next i
  File1.Refresh
End Sub
0
 
DeAnCommented:
yw, thx for the points
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now