Solved

file list box help

Posted on 2003-10-29
14
170 Views
Last Modified: 2010-05-03
1) i have a driver list box , dir list box and a file list box , how can i do that when i double click on any file in the file list box , it'll automatically open the file ?

2) how can i list all the files' name within a folder to a ListBox ? ( not using a file list box) ?
0
Comment
Question by:ANGmoh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9645595
Private Sub File1_DblClick()

   OpenFile Me.File1.Path & "\" & Me.File1.List(Me.File1.ListIndex)

End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9645833
2) use Dir$ function

dim f as string
dim sPath as string
sPath="c:\windows\system\"

f=dir$(spath & "*.*",vbarchive)
do while f<>""
     list1.additem spath & f
f=dir$
loop
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9646000
1)
'in general declarations section of form
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


sub filelistbox1_doubleclick()
      shellexecute me.hwnd, "open",filelistbox1.path & "\" & filelistbox1.text,vbnullstring,vbnullstring,vbnormal
end sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:ANGmoh
ID: 9649080
Richie_Simonetti : the Open file is not working ...
something wrong with it ?  

shellexecute me.hwnd, "open",filelistbox1.path & "\" & filelistbox1.text,vbnullstring,vbnullstring,vbnormal
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9649449
sorry, my mistake:

Private Sub File1_DblClick()
      ShellExecute Me.hwnd, "open", File1.Path & "\" & File1.FileName, vbNullString, vbNullString, vbNormal

end sub
0
 
LVL 1

Author Comment

by:ANGmoh
ID: 9660369
Richie ... still the same .. cant ...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9660385
I did a test and it works with no problems, what happens exactly?
0
 
LVL 1

Author Comment

by:ANGmoh
ID: 9665875
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 File1_DblClick()

sPath = strLogDefaultDir & "\"
fullpathname = sPath & List1.Text

ShellExecute Me.hwnd, "open", fullpathname, vbNullString, vbNullString, vbNormal

end sub

i'v double clicked , but nothing happen.
0
 
LVL 1

Author Comment

by:ANGmoh
ID: 9665889
i did try it out in a new form , yes it did ,open the files , but in other format (.exe,.frm) , not in txt file .
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9670602
"...but in other format (.exe,.frm) , not in txt file . "
Sorry, i didn't understand. What did you mean with that?
0
 
LVL 1

Author Comment

by:ANGmoh
ID: 9670754
what i mean is , you are able to open other files format except .txt file .

when i double click on  aaa.txt , it wont open the file .
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9670866
do you have a file asociation for that kind of file?
0
 
LVL 1

Author Comment

by:ANGmoh
ID: 9670918
they are text document , should be open with notepad .
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 50 total points
ID: 9671119
Change last parameter to vbNormalFocus
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question