|
-
Dec 6th, 2000, 12:32 PM
#1
Thread Starter
New Member
hi,
how can i run a file such as helloworld.html with its default viewer after i click a cmdButton or some how in the code ...
-
Dec 6th, 2000, 12:34 PM
#2
Frenzied Member
-
Dec 6th, 2000, 12:35 PM
#3
_______
<?>
Code:
'open a file with associated app can be done this way [using API]
'open a file with it's associated application
'this example opens an mp3 file with winamp
'put this in a bas module
'
Public Declare Function ShellEx Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As Any, _
ByVal lpDirectory As Any, ByVal nShowCmd As Long) As Long
'
Sub ShellDef(strFileName)
x = ShellEx(Form1.hwnd, "open", strFileName, "", "", 1)
End Sub
'this goes in your form
Private Sub Command1_Click()
' >>> code for event on form <<<
'
Dim strYourFileVariable$
strYourFileVariable = "c:\myfolder\myFile.mp3"
ShellDef strYourFileVariable
'=====================================
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Dec 6th, 2000, 12:40 PM
#4
Copy into a Module:
Code:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public Const SW_SHOWNORMAL = 1
then copy this into your form:
Code:
Public Sub Link2Net(AddUrl As String)
Dim iloc As Long
iloc = ShellExecute(Me.hwnd, vbNullString, AddUrl, vbNullString, "c:\", SW_SHOWNORMAL) 'Me.hwnd or formname.hwnf
End Sub
Private Sub Command1_Click()
Call Link2Net(Text2.Text) ' I used a textbox for the url but just put the url inplace ("http://www.whatever.com")
End Sub
Hope that helps!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Dec 6th, 2000, 12:54 PM
#5
Thread Starter
New Member
i had try both of the code shown .... nothing happen when i try to open html file type (offline) ...??
-
Dec 6th, 2000, 03:02 PM
#6
Try shelling IE directly with the file as the command line.
Code:
Shell "C:\Program Files\Internet Explorer\IExplore.exe C:\OfflineFile.htm", vbNormalFocus
-
Dec 6th, 2000, 04:45 PM
#7
Lively Member
This should work:
[code]
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
ShellExecute hwnd, "open", "helloworld.html", "", "", 1
End Sub
To VB or not to VB, that's the question...
-
Dec 7th, 2000, 12:27 AM
#8
Thread Starter
New Member
sorry, is my mistake. all the code work perfectly ... thank!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|