![]() |
#1
|
||||
|
||||
![]()
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 Shouldn't the else statement be ignored since the resulting file is an AI?
__________________
Sean Waiting for a ride in the T.A.R.D.I.S. |
#2
|
||||
|
||||
![]()
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. |
#3
|
||||
|
||||
![]()
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. |
#4
|
||||
|
||||
![]()
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 The rest seems OK. |
#5
|
||||
|
||||
![]()
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. |
#6
|
||||
|
||||
![]()
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) .... |
#7
|
||||
|
||||
![]() ![]() ![]() 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.
__________________
Sean Waiting for a ride in the T.A.R.D.I.S. |
#8
|
||||
|
||||
![]()
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 ... |
#9
|
||||
|
||||
![]() 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
__________________
Sean Waiting for a ride in the T.A.R.D.I.S. |
#10
|
||||
|
||||
![]()
Sweetness!!!!!
It finally works! WOOHOO!!!!
__________________
Sean Waiting for a ride in the T.A.R.D.I.S. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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 |