OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-02-2004, 10:35
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default Population of Image Box

I am creating the following user form. In the area of the image box, I want a preview of the "browsed for" image. I have already set this up to where it works in MSWord, however, in Draw I want to be able to include the extension for AI to be used as an import, along with the other image formats. I understand that the AI will not be able to be seen in the image box. Thusly, I would like the code to determine if the "browsed" image is an AI and if so, place the image "c:\pna.bmp" in the image box.

Here is the snippet of code I am currently using...
Code:
Sub ShowOpenFile()
Dim OFName As OPENFILENAME
Dim sPath As String

    OFName.lStructSize = Len(OFName)
    OFName.hwndOwner = 0&
    OFName.hInstance = 0&
    OFName.lpstrFilter = "Image Files" + Chr$(0) + "*.jpg;*.bmp;*.gif;*.jpeg;*.ai"
    OFName.lpstrFile = Space$(254)
    OFName.nMaxFile = 255
    OFName.lpstrFileTitle = Space$(254)
    OFName.nMaxFileTitle = 255
    sPath = GetBackEnd
    If sPath = vbNullString Then
        OFName.lpstrInitialDir = "c:\"
    Else
        sPath = Left(sPath, InStrRev(sPath, "\") - 1)
        If Len(Dir(sPath, vbDirectory)) > 0 Then
            OFName.lpstrInitialDir = sPath
        Else
            OFName.lpstrInitialDir = "c:\"
        End If
    End If
    OFName.lpstrTitle = "Select an image File (*.jpg), (*.bmp), (*.gif), (*.ai)"
    OFName.flags = 0

    If GetOpenFileName(OFName) Then
        BrowseOpenFile = OFName.lpstrFile
        txbImagePath.Text = BrowseOpenFile
        If OFName.lpstrFilter = "*.ai" Then
            With Image1
            .Picture = LoadPicture("c:\pna.bmp")
            .PictureAlignment = fmPictureAlignmentCenter
            .PictureSizeMode = fmPictureSizeModeZoom
            End With
        Else
        With Image1
        .Picture = LoadPicture(BrowseOpenFile)
        .PictureAlignment = fmPictureAlignmentCenter
        .PictureSizeMode = fmPictureSizeModeZoom
        End With
        End If
    Else
        BrowseOpenFile = vbNullString
        MsgBox "No file Selected."
    End If
End Sub
I get an invalid picture error within the "Else .Picture = LoadPicture..." Line

Shouldn't the else statement be ignored since the resulting file is an AI?
Attached Images
 
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 10-02-2004, 10:43
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Once again I have determined a solution.

Alex, would you look at this and see if there is a more efficient way for me to go about this?

Code:
Sub ShowOpenFile()
Dim OFName As OPENFILENAME
Dim sPath As String

    OFName.lStructSize = Len(OFName)
    OFName.hwndOwner = 0&
    OFName.hInstance = 0&
    OFName.lpstrFilter = "Image Files" + Chr$(0) + "*.jpg;*.bmp;*.gif;*.jpeg;*.ai"
    OFName.lpstrFile = Space$(254)
    OFName.nMaxFile = 255
    OFName.lpstrFileTitle = Space$(254)
    OFName.nMaxFileTitle = 255
    sPath = GetBackEnd
    If sPath = vbNullString Then
        OFName.lpstrInitialDir = "c:\"
    Else
        sPath = Left(sPath, InStrRev(sPath, "\") - 1)
        If Len(Dir(sPath, vbDirectory)) > 0 Then
            OFName.lpstrInitialDir = sPath
        Else
            OFName.lpstrInitialDir = "c:\"
        End If
    End If
    OFName.lpstrTitle = "Select an image File (*.jpg), (*.bmp), (*.gif), (*.ai)"
    OFName.flags = 0

    If GetOpenFileName(OFName) Then
        BrowseOpenFile = OFName.lpstrFile
        txbImagePath.Text = BrowseOpenFile
        If Right$(OFName.lpstrFilter, 3) = ".ai" Then
            With Image1
            .Picture = LoadPicture("c:\pna.bmp")
            .PictureAlignment = fmPictureAlignmentCenter
            .PictureSizeMode = fmPictureSizeModeZoom
            End With
        Else
        With Image1
        .Picture = LoadPicture(BrowseOpenFile)
        .PictureAlignment = fmPictureAlignmentCenter
        .PictureSizeMode = fmPictureSizeModeZoom
        End With
        End If
    Else
        BrowseOpenFile = vbNullString
        MsgBox "No file Selected."
    End If
End Sub
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #3  
Old 10-02-2004, 10:48
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

O.K. This sux!!! I guess it doesn't work the way I expected. I still need help. :cry:
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #4  
Old 10-02-2004, 11:02
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

Your problem is that you are comparing the filter string to the ".ai". If I'm not mistaken, the filter string doesn't change and is always what you have specified.

I guess you'd better check the extension of the actual file selected. Like:

Code:
If LCase$(Right$(BrowseOpenFile, 3)) = ".ai" Then
Note also that I used LCase function to ensure that the file name is in lowercase when comparing (otherwise MyFILE.AI will be not detected).

The rest seems OK.
Reply With Quote
  #5  
Old 10-02-2004, 12:09
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

OK for some reason it still doesn't work. I have tried numerous things, but I think I am losing the battle. I think for some reason the code isn't really reading the .ai. If I choose any other file that isn't an AI the code works fine and returns the image to the image box, but when I choose an AI the invalid image error occurs. It's still reading that portion of the code that puts the browsed image in the image box, instead of the "preview not avialable" image.

Here is the newest code
Code:
Sub ShowOpenFile()
Dim OFName As OPENFILENAME
Dim sPath As String

    OFName.lStructSize = Len(OFName)
    OFName.hwndOwner = 0&
    OFName.hInstance = 0&
    OFName.lpstrFilter = "Image Files" + Chr$(0) + "*.jpg;*.bmp;*.gif;*.jpeg;*.ai"
    OFName.lpstrFile = Space$(254)
    OFName.nMaxFile = 255
    OFName.lpstrFileTitle = Space$(254)
    OFName.nMaxFileTitle = 255
    sPath = GetBackEnd
    If sPath = vbNullString Then
        OFName.lpstrInitialDir = "c:\"
    Else
        sPath = Left(sPath, InStrRev(sPath, "\") - 1)
        If Len(Dir(sPath, vbDirectory)) > 0 Then
            OFName.lpstrInitialDir = sPath
        Else
            OFName.lpstrInitialDir = "c:\"
        End If
    End If
    OFName.lpstrTitle = "Select an image File (*.jpg), (*.bmp), (*.gif), (*.ai)"
    OFName.flags = 0

    If GetOpenFileName(OFName) Then
        BrowseOpenFile = OFName.lpstrFile
        txbImagePath.Text = BrowseOpenFile
        If LCase$(Right$(BrowseOpenFile, 3)) = ".ai" Then
            PictureNotAvail
        Else
            PreviewAvail
        End If
    Else
        BrowseOpenFile = vbNullString
        MsgBox "No file Selected."
    End If

End Sub
Sub PictureNotAvail()
    With Image1
    .Picture = LoadPicture("c:\pna.bmp")
    .PictureAlignment = fmPictureAlignmentCenter
    .PictureSizeMode = fmPictureSizeModeZoom
    End With
End Sub
Sub PreviewAvail()
    With Image1
    .Picture = LoadPicture(txbImagePath.Text)
    .PictureAlignment = fmPictureAlignmentCenter
    .PictureSizeMode = fmPictureSizeModeZoom
    End With
End Sub
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #6  
Old 10-02-2004, 12:16
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

I believe you need to add this code right after you call GetOpenFileName:

Code:
Dim n As Long
....
If GetOpenFileName(OFName) Then
    BrowseOpenFile = OFName.lpstrFile
    n = InStr(BrowseOpenFile, vbNullChar)
    If n <> 0 Then BrowseOpenFile = Left$(BrowseOpenFile, n - 1)
    ....
This should help.
Reply With Quote
  #7  
Old 10-02-2004, 12:18
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default


I'm posting the actual form for anyone to use on their machine. I'm so completely confused at this point.

I am using CD11 BTW.
Attached Files
File Type: zip OrderForm1.zip (11.2 KB, 1026 views)
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #8  
Old 10-02-2004, 12:21
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

Another thing you might want to do instead is to trap any errors from LoadPicture and if an error occured, then load the other picture (you will still need to cut off the NULL char from the file name returned by GetOpenFileName):

Code:
Dim pic As Picture
...
On Error Resume Next
Set pic = LoadPicture(BrowseOpenFile)
If Err.Number <> 0 Then
    Set pic = LoadPicture("c:\pna.bmp")
End If
.Picture = pic
...
In this case, even if a file has, say, a BMP extension but is corrupt, you will still show "No Preview available" and your program will not crash.
Reply With Quote
  #9  
Old 10-02-2004, 12:24
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Code:
If GetOpenFileName(OFName) Then
        BrowseOpenFile = OFName.lpstrFile
        txbImagePath.Text = BrowseOpenFile
        n = InStr(BrowseOpenFile, vbNullChar)
        If n <> 0 Then BrowseOpenFile = Left$(BrowseOpenFile, n - 1)
            If LCase$(Right$(BrowseOpenFile, 3)) = ".ai" Then
                PictureNotAvail
            Else
                PreviewAvail
            End If
        End If
    Else
        BrowseOpenFile = vbNullString
        MsgBox "No file Selected."
    End If
At this point I am getting an "Else without If" error when I click the browse button. AAARRRGGGHHH!!!
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #10  
Old 10-02-2004, 13:17
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Sweetness!!!!!

It finally works! WOOHOO!!!!
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image picture location RVogel CorelDRAW/Corel DESIGNER VBA 0 31-03-2005 12:05
Apply Outline - Scale with Image geopig CorelDRAW/Corel DESIGNER VBA 4 06-05-2004 07:23
Import image into bounding box Craig Tucker CorelDRAW/Corel DESIGNER VBA 2 07-10-2003 20:06
Save as HTML Image Map adriano Corel Photo-Paint VBA 1 15-04-2003 10:16
fonts used by a CDR image spelhatre CorelDRAW/Corel DESIGNER VBA 1 04-04-2003 11:12


All times are GMT -5. The time now is 10:41.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com