General discussion

Locked

Simple Visual Basic click function

By LabRaT ·
First--I don't know the VB language but I can build a form and add a control button with a click command. I need to build a simple app with 4 buttons that each will open a PDF file. I am using VB 5.0 Pro and will compile the app to a exe and copy toa CD. The PDF reader exe will be included on the CD. This should be just a simple line or 2 of code for the click command but I don't have time in this project to learn the language. I've gone thru the help tutorials but they are geared toward building databases and lists. A single click on the button should call the reader exe and display the document--no error traps or anything fancy. When the doc is closed the form should remain open in the background for the next choice. Can someone quicklygive me the code for this? I need this for a quick demo for a management meeting tomorrow. I promise to learn more later but I need help now.

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Simple Visual Basic click function

by Don Christner In reply to Simple Visual Basic click ...

There is of course a millon ways to do this, but perhaps the easiest is to use the Webbrowser control. Place the webbrowser control on the form and then for each command button do the following.

Private Sub cmdPDF1_Click()
Dim strURL1 As String
strURL1 = "c:\readme.pdf"
WebBrowser1.Navigate (strURL1)
End Sub

dim sets up a variable to store the path (one for each file)

strURL1= stores a path & filename to the variable

webbrowser1.navigate (strURL) make the webbrowser control load your variable(file)

Name your controls something meaningful not just 1,2,3 etc.

To add the webbrowser control to your project, you'll click on Project. Then Components, then scroll down to Microsoft Internet Controls. The bad newsis, I'm not sure if this was included in VB5 or just VB6.

Don

Collapse -

Simple Visual Basic click function

by LabRaT In reply to Simple Visual Basic click ...

Doesn't work. Debug hangs on:
WebBrowser1.Navigate (strURL1)

I added the Microsoft Internet Controls as you said. They were there and it added an icon to the tool bar. But is that all I needed to do? All I really want is to start the Acrobat Reader that I will have on the CD.

Collapse -

Simple Visual Basic click function

by Don Christner In reply to Simple Visual Basic click ...

After adding it to the toolbar on the left; did you drag it onto the form? This will be your browser window. It will act as if you are in Internet Explorer, Acrobat Reader is a plugin for IE, so you'll see the PDF file open within the browser.

Ifyou want to get alot more complicated you can use API calls to launch Acrobat, open the file and then wait until you close Acrobat. Much more involved.

Give it a try and let me know.

Don

Collapse -

Simple Visual Basic click function

by LabRaT In reply to Simple Visual Basic click ...

Poster rated this answer

Collapse -

Simple Visual Basic click function

by Don Christner In reply to Simple Visual Basic click ...

I tried a few different ways to handle this and I think that I have an easier way. I know it works if Acrobat is installed on the harddrive, not sure about only on the CD.

Private Sub Command1_Click()
Shell "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\acrobat.exe c:\fuses.pdf", vbMaximizedFocus
End Sub

Private Sub Command2_Click()
Shell "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\acrobat.exe c:\readme.pdf", vbMaximizedFocus
End Sub

This forum messes up the formating, the shell command can be all on one line. Basically, shell then a space then "path to acrobat.exe then space then the filename you want to open then ",vbmaximizedfocus. I did a simple form with two command buttons set to shell to two different pdf files andit worked great.

Don

Collapse -

Simple Visual Basic click function

by LabRaT In reply to Simple Visual Basic click ...

Thanks! Never got the webbrowser thing to work--maybe it is only in v6.0 as you said. The shell command is what I used. I used it in this form:
shell "start c:\acrord32.exe \readme.pdf"

I'm not sure what the vbMaximizedFocuse is for. When used, it just blink a blank black window (like a DOS command window?) but then started the reader and displayed the file. I took it out and the file displayed quicker and it didn't look as clunky with the black screen flashing on. Thank again for your help!!

Collapse -

Simple Visual Basic click function

by LabRaT In reply to Simple Visual Basic click ...

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums