Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

Open Notepad from listbox

I have a list box and the 3rd column is file name, how do i make open file with Notepad when clicking on selected item.
0
jasonkk
Asked:
jasonkk
  • 6
  • 5
  • 4
  • +2
1 Solution
 
xSinbadCommented:
You should use the shell command;

dim strShell
bknouse ="notepad.exe " & listboxnamehere
call shell (bknouse)
0
 
xSinbadCommented:
That should be

dim strShell
strShell ="notepad.exe " & listboxnamehere
call shell (bknouse)
0
 
nico5038Commented:
Check out the SHELL command from the help file. It has a sample like:
Shell("C:\WINDOWS\CALC.EXE", 1)

Nic;o)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
bruintjeCommented:
Private Sub Listbox1_DblClick(Cancel As Integer)
  Shell("C:\WINDOWS\NOTEPAD.EXE" & Listbox1.ItemData(Listbox1.ListIndex), 1)
End Sub

HTH:O)Bruintje
0
 
bruintjeCommented:
Private Sub Listbox1_DblClick(Cancel As Integer)
 Shell "C:\WINDOWS\NOTEPAD.EXE" & Listbox1.ItemData(Listbox1.ListIndex), 1
End Sub

0
 
jasonkkAuthor Commented:
xSinbad,

The listbox has 3 columns and sometimes the record is more than 1.
I need to know how to open file with Notepad when clicking on selected item based on 3rd column data from multiple datas.

i.e.) The listbox consists of 3 column(Year, Title, No).

Thanks


                   
0
 
VolibrawlCommented:
Be sure that the name of the file that you want to open includes the path.  Here is a routine for a ComboBox where the path is in column2 and the filename is in column3:


Private Sub Combo0_AfterUpdate()
    Dim shellout As String
    shellout = "C:\windows\notepad.exe "
    shellout = shellout & Me.Combo0.Column(1)
    shellout = shellout & Me.Combo0.Column(2)

    Shell shellout
End Sub
0
 
jasonkkAuthor Commented:
xSinbad,

The listbox has 3 columns and sometimes the record is more than 1.
I need to know how to open file with Notepad when clicking on selected item based on 3rd column data from multiple datas.

i.e.) The listbox consists of 3 column(Year, Title, No).

Thanks


                   
0
 
bruintjeCommented:
Private Sub Listbox1_DblClick(Cancel As Integer)
Shell "C:\WINDOWS\NOTEPAD.EXE" & Listbox1.Column(2, Listbox1.ListIndex)), 1
End Sub

will take the third column
0
 
jasonkkAuthor Commented:
I forgot to mention that the files are located in "C:\My Documents" directory and the file name is number which is "001" not "001.txt".
Thanks for your help
0
 
VolibrawlCommented:
1. It does not matter if the filename is .txt or not as long as you have the FULL actual filename to feed into the code.

2. If they are always in c:\mydocuments, just be sure you add that path into whichever solution you end up using.

3. In general, note that the 3rd column is column(2) BECAUSE the first column is alwayw column(0)


eg. bruintje's solution would be:

Private Sub Listbox1_DblClick(Cancel As Integer)
Shell "C:\WINDOWS\NOTEPAD.EXE c:\mydocuments\" & Listbox1.Column(2, Listbox1.ListIndex)), 1
End Sub


The combobox code would change to:

Private Sub Combo0_AfterUpdate()
   Dim shellout As String
   shellout = "C:\windows\notepad.exe c:\my documents\"
   shellout = shellout & Me.Combo0.Column(2)
   Shell shellout
End Sub




0
 
bruintjeCommented:
?

so something like

Private Sub Listbox1_DblClick(Cancel As Integer)
Shell "C:\WINDOWS\NOTEPAD.EXE" & "C:\My Documents\" & Listbox1.Column(2, Listbox1.ListIndex)) & "001", 1
End Sub

or is that number different every day/time? can it also be read from a box?

:O)Bruintje


0
 
bruintjeCommented:
correction "001" has to be ".001"
0
 
jasonkkAuthor Commented:
Thanks,

But, I have a small problem though with the way on opening the file.
Whenever it opens the file, it goes to background.
Do you know how to make it comes up in front.
0
 
VolibrawlCommented:
Jason ... we are kind of guessing here. Can you provide us with this info ...

1. Is this a listbox (FOR SURE) or a combo box?
2. Type here EXACTLY what is in the 3rd column of any row
3. Type exactly the FileName of ANY of the files you want to open using notepad.  Include the extension if there is one.
4. If there is no extension on any of the files, how were they created?  Nearly every program tries to put an extension on its file names so you must have overridden it?





0
 
VolibrawlCommented:
Well ignore my last post since we got it working.

No, I don't know how to make it come to the front, but I'll  try to find out.
0
 
VolibrawlCommented:
Jason, the trailing ",1" causes it to open with the ocus, ",3" causes it to open maximized.

Which formula are you using to get to where you are?  We need to just add the ",1" to the end of it.
0
 
VolibrawlCommented:
For Listbox1:

Private Sub Listbox1_DblClick(Cancel As Integer)
Shell "C:\WINDOWS\NOTEPAD.EXE " & "C:\My Documents\" & Listbox1.Column(2, Listbox1.ListIndex), 1
End Sub



OR for Combo0:

Private Sub Combo0_AfterUpdate()
   Shell ("C:\WINDOWS\NOTEPAD.EXE " & "C:\My Documents\" & Combo0.Column(2)), 1
   
End Sub

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now