ouvrir un fichier avec le programme associé dans pivotal
1 réponse
maxime_phan
bonjour a tous,
jai nu projet pivotal crm, la partie client est programmable en VB,
actuellement jai un bouton sur lequel jai un =E9v=E8nement click ou je
colle le code siuvant qui marche:
////////////////////////////////////////////////////////////////////////////=
//////////
Dim objShell, objFolder, chemin, SecuriteSlash, Desk
Set objShell =3D CreateObject("Shell.Application")
Set objFolder =3D objShell.BrowseForFolder(&H0&, "Choisisser votre
fichier", &H4000&)
On Error Resume Next
chemin =3D objFolder.ParentFolder.ParseName(objFolder.Title).Path & ""
If objFolder.Title =3D "Bureau" Then
chemin =3D "c:WINDOWSBUREAU"
End If
If objFolder.Title =3D "" Then
chemin =3D ""
End If
SecuriteSlash =3D InStr(objFolder.Title, ":")
If SecuriteSlash > 0 Then
chemin =3D Mid(objFolder.Title, SecuriteSlash - 1, 2) & ""
End If
Label4.Caption =3D objFolder.Title
Label1.Caption =3D chemin
////////////////////////////////////////////////////////////////////////////=
/////////
ce code mouvre une dialog qui me permet de choisir un fichier et
r=E9cup=E9rer son chemin. maintenant jaimerai l'ouvrir avec le programme
associ=E9 (par exemple notepad un fichier test.txt).
Avez vous un code qui fait ca? JE PRECISE QUE DANS PIVOTAL ON NE PEUT
PAS UTILISER LES API WINDOWS (ou alors je ne sais pas comment faire)
peu de gens connaissent le dev pivotal apparemment.
jespere que qq pourra m'aider..
merci d'avance
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Jacques93
Bonjour maxime_phan, a écrit :
bonjour a tous, jai nu projet pivotal crm, la partie client est programmable en VB, actuellement jai un bouton sur lequel jai un évènement click ou je colle le code siuvant qui marche: ////////////////////////////////////////////////////////////////////////////////////// Dim objShell, objFolder, chemin, SecuriteSlash, Desk Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.BrowseForFolder(&H0&, "Choisisser votre fichier", &H4000&) On Error Resume Next chemin = objFolder.ParentFolder.ParseName(objFolder.Title).Path & "" If objFolder.Title = "Bureau" Then chemin = "c:WINDOWSBUREAU" End If If objFolder.Title = "" Then chemin = "" End If SecuriteSlash = InStr(objFolder.Title, ":") If SecuriteSlash > 0 Then chemin = Mid(objFolder.Title, SecuriteSlash - 1, 2) & "" End If Label4.Caption = objFolder.Title Label1.Caption = chemin /////////////////////////////////////////////////////////////////////////////////////
ce code mouvre une dialog qui me permet de choisir un fichier et récupérer son chemin. maintenant jaimerai l'ouvrir avec le programme associé (par exemple notepad un fichier test.txt). Avez vous un code qui fait ca? JE PRECISE QUE DANS PIVOTAL ON NE PEUT PAS UTILISER LES API WINDOWS (ou alors je ne sais pas comment faire) peu de gens connaissent le dev pivotal apparemment. jespere que qq pourra m'aider.. merci d'avance
Dommage que tu ne puisses pas utiliser les API's :
mais apparemment tu peux utiliser le scripting. Comme tu peux connaître facilement l'extension, on peux retrouver l'application associée (à adapter, ici l'extension est dans un TextBox). Testé avec .txt, .xls .doc, .pdf) :
Private Sub Command1_Click() Dim WshShell As Object Dim sApp As String
sApp = GetApp(Me.Text1.Text) 'Extension, par exemple .txt Set WshShell = CreateObject("WScript.Shell") WshShell.Run (sApp & " " & Chr$(34) & CheminEtNomDuFichier & Chr$(34)) set WshShell = Nothing End Sub
Private Function GetApp(Ext As String) As String Dim WshShell As Object Dim sType As String Dim sApp As String
Set WshShell = CreateObject("WScript.Shell") sType = WshShell.RegRead("HKLMSoftwareClasses" & Ext & "") If Len(sType) > 0 Then sApp = WshShell.RegRead("HKLMSoftwareClasses" & _ sType & "ShellOpenCommand")
If InStr(sApp, Chr$(34) & "%1" & Chr$(34)) > 0 Then sApp = Left(sApp, InStr(sApp, Chr$(34) & "%1" & Chr$(34)) - 1) End If
If InStr(sApp, "%1") > 0 Then sApp = Left(sApp, InStr(sApp, "%1") - 1) End If
If InStr(sApp, "/") > 0 Then sApp = Left(sApp, InStr(sApp, "/") - 1) End If GetApp = sApp End If Set WshShell = Nothing End Function
n'est pas très standard, il faudra peut être faire d'autres contrôles
-- Cordialement,
Jacques.
Bonjour maxime_phan,
maxime_phan@hotmail.com a écrit :
bonjour a tous,
jai nu projet pivotal crm, la partie client est programmable en VB,
actuellement jai un bouton sur lequel jai un évènement click ou je
colle le code siuvant qui marche:
//////////////////////////////////////////////////////////////////////////////////////
Dim objShell, objFolder, chemin, SecuriteSlash, Desk
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(&H0&, "Choisisser votre
fichier", &H4000&)
On Error Resume Next
chemin = objFolder.ParentFolder.ParseName(objFolder.Title).Path & ""
If objFolder.Title = "Bureau" Then
chemin = "c:WINDOWSBUREAU"
End If
If objFolder.Title = "" Then
chemin = ""
End If
SecuriteSlash = InStr(objFolder.Title, ":")
If SecuriteSlash > 0 Then
chemin = Mid(objFolder.Title, SecuriteSlash - 1, 2) & ""
End If
Label4.Caption = objFolder.Title
Label1.Caption = chemin
/////////////////////////////////////////////////////////////////////////////////////
ce code mouvre une dialog qui me permet de choisir un fichier et
récupérer son chemin. maintenant jaimerai l'ouvrir avec le programme
associé (par exemple notepad un fichier test.txt).
Avez vous un code qui fait ca? JE PRECISE QUE DANS PIVOTAL ON NE PEUT
PAS UTILISER LES API WINDOWS (ou alors je ne sais pas comment faire)
peu de gens connaissent le dev pivotal apparemment.
jespere que qq pourra m'aider..
merci d'avance
Dommage que tu ne puisses pas utiliser les API's :
<http://faq.vb.free.fr/index.php?question=8>
mais apparemment tu peux utiliser le scripting. Comme tu peux connaître
facilement l'extension, on peux retrouver l'application associée (à
adapter, ici l'extension est dans un TextBox). Testé avec .txt, .xls
.doc, .pdf) :
Private Sub Command1_Click()
Dim WshShell As Object
Dim sApp As String
sApp = GetApp(Me.Text1.Text) 'Extension, par exemple .txt
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run (sApp & " " & Chr$(34) & CheminEtNomDuFichier & Chr$(34))
set WshShell = Nothing
End Sub
Private Function GetApp(Ext As String) As String
Dim WshShell As Object
Dim sType As String
Dim sApp As String
Set WshShell = CreateObject("WScript.Shell")
sType = WshShell.RegRead("HKLMSoftwareClasses" & Ext & "")
If Len(sType) > 0 Then
sApp = WshShell.RegRead("HKLMSoftwareClasses" & _
sType & "ShellOpenCommand")
If InStr(sApp, Chr$(34) & "%1" & Chr$(34)) > 0 Then
sApp = Left(sApp, InStr(sApp, Chr$(34) & "%1" & Chr$(34)) - 1)
End If
If InStr(sApp, "%1") > 0 Then
sApp = Left(sApp, InStr(sApp, "%1") - 1)
End If
If InStr(sApp, "/") > 0 Then
sApp = Left(sApp, InStr(sApp, "/") - 1)
End If
GetApp = sApp
End If
Set WshShell = Nothing
End Function
bonjour a tous, jai nu projet pivotal crm, la partie client est programmable en VB, actuellement jai un bouton sur lequel jai un évènement click ou je colle le code siuvant qui marche: ////////////////////////////////////////////////////////////////////////////////////// Dim objShell, objFolder, chemin, SecuriteSlash, Desk Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.BrowseForFolder(&H0&, "Choisisser votre fichier", &H4000&) On Error Resume Next chemin = objFolder.ParentFolder.ParseName(objFolder.Title).Path & "" If objFolder.Title = "Bureau" Then chemin = "c:WINDOWSBUREAU" End If If objFolder.Title = "" Then chemin = "" End If SecuriteSlash = InStr(objFolder.Title, ":") If SecuriteSlash > 0 Then chemin = Mid(objFolder.Title, SecuriteSlash - 1, 2) & "" End If Label4.Caption = objFolder.Title Label1.Caption = chemin /////////////////////////////////////////////////////////////////////////////////////
ce code mouvre une dialog qui me permet de choisir un fichier et récupérer son chemin. maintenant jaimerai l'ouvrir avec le programme associé (par exemple notepad un fichier test.txt). Avez vous un code qui fait ca? JE PRECISE QUE DANS PIVOTAL ON NE PEUT PAS UTILISER LES API WINDOWS (ou alors je ne sais pas comment faire) peu de gens connaissent le dev pivotal apparemment. jespere que qq pourra m'aider.. merci d'avance
Dommage que tu ne puisses pas utiliser les API's :
mais apparemment tu peux utiliser le scripting. Comme tu peux connaître facilement l'extension, on peux retrouver l'application associée (à adapter, ici l'extension est dans un TextBox). Testé avec .txt, .xls .doc, .pdf) :
Private Sub Command1_Click() Dim WshShell As Object Dim sApp As String
sApp = GetApp(Me.Text1.Text) 'Extension, par exemple .txt Set WshShell = CreateObject("WScript.Shell") WshShell.Run (sApp & " " & Chr$(34) & CheminEtNomDuFichier & Chr$(34)) set WshShell = Nothing End Sub
Private Function GetApp(Ext As String) As String Dim WshShell As Object Dim sType As String Dim sApp As String
Set WshShell = CreateObject("WScript.Shell") sType = WshShell.RegRead("HKLMSoftwareClasses" & Ext & "") If Len(sType) > 0 Then sApp = WshShell.RegRead("HKLMSoftwareClasses" & _ sType & "ShellOpenCommand")
If InStr(sApp, Chr$(34) & "%1" & Chr$(34)) > 0 Then sApp = Left(sApp, InStr(sApp, Chr$(34) & "%1" & Chr$(34)) - 1) End If
If InStr(sApp, "%1") > 0 Then sApp = Left(sApp, InStr(sApp, "%1") - 1) End If
If InStr(sApp, "/") > 0 Then sApp = Left(sApp, InStr(sApp, "/") - 1) End If GetApp = sApp End If Set WshShell = Nothing End Function