By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Opening a file in paint using VIsual Basic 6

P: 4
Basically, i have a program that shows images and i want it to open the image currently selected with mspaint so they can edit it.

Currently i can open paint when the user clicks a button i have set out however i cannot get paint to open the file being viewed.

I get the error "File path not found" but i'm not sure why, i thought it would be as simple as adding the "filepath" variable onto it.

Here's the code i currently have:
--------------------------------------------------------

Option Explicit

Dim paint As String
Dim filepath As String
------------------------------------------------------
Private Sub cmdpaint_Click() 'Button to open paint'

paint = cmdpaint
filepath = File1.Path + "\" + File1.FileName 'File path of currently selected file'

If paint = True Then Shell "C:\WINDOWS\system32\mspaint.exe" & "filepath"

End Sub


Many thanks for your help :)
May 2 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
At first glance, I see two main problems in this line of code...
If paint = True Then Shell "C:\WINDOWS\system32\mspaint.exe" & "filepath"
First, you have not left a space after "mspaint.exe". Try that at the DOS prompt and see what happens.

Second, you are not passing the pathname/filename, you are simply passing the literal value "filepath". Unless your image is called "filepath" with no extension and resides in the current directory, this is unlikely to work. You almost certainly intended to use the variable name filepath there, not a literal.

Oh, and a minor point - you are assuming the Windows directory will always be the same. Hm...
May 2 '07 #2

P: 4
At first glance, I see two main problems in this line of code...
First, you have not left a space after "mspaint.exe". Try that at the DOS prompt and see what happens.
I tried leaving a space after "mspaint.exe" and nothing i get the error that filepath.bmp doesn't exsist, which bring me to your other point:

Second, you are not passing the pathname/filename, you are simply passing the literal value "filepath". Unless your image is called "filepath" with no extension and resides in the current directory, this is unlikely to work. You almost certainly intended to use the variable name filepath there, not a literal.
My intention was to store the file path of the currently selected image in the "filepath" variable and then call it, but i guess it's not that simple..

I also know that some people will not have a default windows installation but i'll address that issue in a forthcoming update.

Any ideas on how to rectify my problem?

Many thanks.

Oh, and a minor point - you are assuming the Windows directory will always be the same. Hm...[/quote]
May 2 '07 #3

P: 4
It didnt process my changes....but anyway..sorry for double post.

What i've decided is that do you know how to show the "open with" box that is shown when you execute a file windows doesnt recognise?

My plan is to create a button that will show the "Open Wit" dialogue box so the user has a choice over programs they have on their machine.

It also solves the default program installation problem.

Is the above possible?
May 2 '07 #4

Expert 5K+
P: 8,434
...
My intention was to store the file path of the currently selected image in the "filepath" variable and then call it, but i guess it's not that simple..
Actually, it is. The problem is that you have used the wrong syntax in that line. The quotes (") around filepath make that a literal value. So where you meant to pass the value which is stored in the variable called filepath, you have instead passed the string "filepath".

If you put back the space after .exe and remove the quotes around filepath, I think you may find that it works.

As for the "which program" dialog, I don't know. Probably what you would need to do is have some kind of installation procedure which associates your application with that file type. I don't know whether the packaging/deployment that is bundled with VB will do that. You might need to look into a third-party product for that.

Or you may be able to simply do it from your code. I believe we've had posts on TheScripts in the past which accessing the list of file types and associated applications. Try a bit of searching and see what you can find. Note, it will probably help if you include some variant of the word "enumerate" in the search.
May 3 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.