Results 1 to 13 of 13

Thread: why isn't this code working?

  1. #1

    Thread Starter
    Lively Member Blaster's Avatar
    Join Date
    Jun 2001
    Posts
    70

    Question why isn't this code working?

    VB Code:
    1. Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. If Data.GetFormat(vbCFBitmap) Then Picture1.Picture = LoadPicture(Data.Files(1))
    3. End Sub

    now it should display the file in Picture1.Picture but it doesn't what is up??

  2. #2

  3. #3

  4. #4

    Thread Starter
    Lively Member Blaster's Avatar
    Join Date
    Jun 2001
    Posts
    70
    not working maybe i'm doing it wrong

    VB Code:
    1. Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. Is Data.GetFormat(vbcfbitmap) True
    3. Picture1.Picture = LoadPicture(Data.Files(1))
    4. End Sub

    I get syntax error

  5. #5
    Lively Member
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    115
    The reason why you get a syntax-error is because you can't write
    Code:
    Is Data.GetFormat(vbcfbitmap) True
    There are no such thing as "Is" in Visual Basic...
    And as MartinLiss wrote, the GetFormat-method only applies to the Clipboard-object.

  6. #6

    Thread Starter
    Lively Member Blaster's Avatar
    Join Date
    Jun 2001
    Posts
    70
    how do I fix my problem then?

  7. #7
    Tygur
    Guest
    Are you trying to drag an image or an image file?
    Also, make sure you set the OLEDropMode property for the picturebox to Manual or Automatic.

    GetFormat does not only work with the Clipboard Object. It also works for the DataObject object.

  8. #8

    Thread Starter
    Lively Member Blaster's Avatar
    Join Date
    Jun 2001
    Posts
    70
    yeah it is set on automatic and I am trying to drag an image file

  9. #9
    Tygur
    Guest
    Set it to manual and put this code in (Notice how similar to your code this is. You only missed one thing ):
    VB Code:
    1. Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. If Data.GetFormat(vbCFFiles) Then
    3.     'Ignore errors because a bad file can be dragged.
    4.     On Error Resume Next
    5.     Picture1.Picture = LoadPicture(Data.Files(1))
    6. End If
    7. End Sub

  10. #10

    Thread Starter
    Lively Member Blaster's Avatar
    Join Date
    Jun 2001
    Posts
    70
    omg! your soo elite!!

  11. #11
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    There are no such thing as "Is" in Visual Basic...
    There Sure IS.. Try
    If Data1 IS Nothing Then Exit Sub

  12. #12
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    "Is" is a keyword in VB, but it's not used in that manner.
    Code:
    If TypeOf(objBlah) Is TextBox Then MsgBox "It's a textbox"
    .GetFormat and .GetData apply to both the Clipboard and DataObject. I've never used this OLEDrag??? stuff before,
    but this may be the way to get it. This method works for pasting bitmaps from the clipboard, but I don't know how to
    actually test out the OLE event.
    Code:
    'Inside your OLEDragDrop event...
    If Data.GetFormat(vbCFBitmap) Then picOut.Picture = Data.GetData(vbCFBitmap)
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  13. #13
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Well I see someone else said it already. I've been watching tv and stopped writing the post
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width