|
-
Nov 29th, 2000, 04:42 PM
#1
Thread Starter
Fanatic Member
A combo box has a property of text, if you use this property whatever is slected in the combo box is equal to the text property. If you have a list box what is the equivalent for this? In other words if I fill a listbox and want to select sometyhing out of it what is the property for this?
-
Nov 29th, 2000, 04:50 PM
#2
Junior Member
Check it out
This is how you select something in a listbox
List1.Selected(Index) = True
If you have five entries in the listbox, then Index should range from 0 to 4.
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 05:04 PM
#3
Thread Starter
Fanatic Member
If you are filling this list box in dynamically then how owuld you identify the item? I can't hard code the index number in because the list box is being filled in a runtime.
-
Nov 29th, 2000, 05:14 PM
#4
The Listbox has a .Text property for when something is selected.
-
Nov 29th, 2000, 05:24 PM
#5
Fanatic Member
If you are allowing multiple items to be selected (i.e. if the MultiSelect property is set to 1-Simple or 2-Extended)then you should probably use a formula similar to this....
Code:
Dim iCt As Integer
For iCt = 0 To (List1.ListCount - 1)
If List1.Selected(iCt) = True Then
Debug.Print List1.List(iCt)
End If
Next iCt
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Nov 29th, 2000, 05:38 PM
#6
Thread Starter
Fanatic Member
When I use the text property and try and open the file selected it opens acrobat reader (I am using the shell command) and then it says cannot open file, file does not exist. I know that it does because I can go to the directory and find it.
Here is the code
If lstQuery.Text <> "" Then
Shell ("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\") & lstQuery.Text, vbMaximizedFocus
Else
MsgBox "Please select a file from the list box", vbExclamation
End If
This list box gets filled in according to a query that I wrote.
-
Nov 29th, 2000, 06:01 PM
#7
Junior Member
Don't use lstQuery.text, instead use lstQuery.list(iCt) to retieve the filename in your listbox.
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 06:09 PM
#8
Junior Member
I got it...
qoute:
Shell ("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\") & lstQuery.Text, vbMaximizedFocus
remove the second bracket, and place it after lstQuery.text like this:
Shell ("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text), vbMaximizedFocus
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 06:12 PM
#9
Thread Starter
Fanatic Member
How owuld I set the index argument to what ever is selected. In other words if I put this piece of code in it still wants a value for iCt. How do I tell it that iCt is equal to whatever is selected?
-
Nov 29th, 2000, 06:14 PM
#10
Junior Member
I actually meant this
Shell "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text, vbMaximizedFocus
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 06:16 PM
#11
Fanatic Member
If you want to return the current index of the listbox then use this
Code:
List1.List(List1.ListIndex)
but I think that has the same effect as List1.Text??
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Nov 29th, 2000, 06:17 PM
#12
use lstQuery.List(lstQuery.ListIndex)
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 29th, 2000, 06:20 PM
#13
Junior Member
'Make a loop like this one
For Index = 0 To lstFiles.ListCount - 1
If lstFiles.Selected(Index) = True Then
Shell "C:\Program Files\Adobe\Acrobat 4.0 Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text, vbMaximizedFocus
Else
MsgBox "Please select a file from the list box", vbExclamation
End If
next Index
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 06:35 PM
#14
Thread Starter
Fanatic Member
-
Nov 29th, 2000, 06:52 PM
#15
Junior Member
by lstFiles, I really meant lstQuery... alright.
Just one little tip...
use the listIndex property, if your lstQuery is not set to multiline. Otherwise use the loop I'd given you, for multiline selections, it's more accurate.
enjoy coding...
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 07:18 PM
#16
Thread Starter
Fanatic Member
Ok when I do this it works great, there is only one thing that is holding me back I believe. I still get a file not found error the problem is that it is not seeing the .pdf extension on the file name. Here is my code (rabih's actually)
For index = 0 To lstQuery.ListCount - 1
If lstQuery.Selected(index) = False Then
Shell "C:\Program Files\Adobe\Acrobat 4.0 Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text, vbMaximizedFocus
Else
MsgBox "Please select a file from the list box", vbExclamation
End If
Next index
If I put a break point on the line
Shell "C:\Program Files\Adobe\Acrobat 4.0 Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text,
It will get the file selected at lstquery.text (if I put my mouse over that it has the correct file name in it). The problem is that the file does not have the .pdf extension, is there a way to tack that on automatically?
-
Nov 29th, 2000, 07:40 PM
#17
Junior Member
Listen Brian:
1. Are using a ListBox or a FileListBox ?
If you're using a ListBox then how are you filling it? Show me your code...
If you're using a fileListBox then file extensions, are automatically added to each file.
If you haven't used FileListBoxes before... they are just like ListBoxes but mainly for displaying the contents of folders, eg: if you place a FileListBox on your form called File1 then add this to form_Load
Private Sub form_Load()
File1.Path = "G:\efile's\"
End Sub
then you'll see all the files in that directory complete with an extension.
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 07:43 PM
#18
Thread Starter
Fanatic Member
Sorry for my ignorance on the subject and I appreciate your patience. I am using a listbox. The following code is how I fill it (through a query with parameters that are passed through an input box).
Dim strSql As String
Dim strLName As String
Dim rsdigiID As New ADODB.Recordset
Dim condigiID As New ADODB.Command
lstQuery.Clear
dbConnect
strLName = InputBox("Please enter the Last Name that you would like to search for")
If strLName = "" Then
MsgBox "Please enter a Last Name", vbOKOnly
Exit Sub
End If
strLName = "select * from tbldigidoc where tbldigidoc.L_Name like '" & strLName & "'"
With condigiID
.ActiveConnection = cnndigi
.CommandType = adCmdText
.CommandText = strLName
Set rsdigiID = .Execute()
End With
Do Until rsdigiID.EOF
lstQuery.AddItem rsdigiID("Name_of_Document")
rsdigiID.MoveNext
Loop
rsdigiID.Close
Set rsdigiID = Nothing
Set condigiID = Nothing
What next?, Thanks a lot!
-
Nov 29th, 2000, 07:58 PM
#19
Junior Member
'Change this line, Hope this one works
Do Until rsdigiID.EOF
lstQuery.AddItem rsdigiID("Name_of_Document") & ".pdf"
rsdigiID.MoveNext
Loop
Tell me what happens, Okay
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 08:08 PM
#20
Thread Starter
Fanatic Member
Well it worked and it didn't at the same time. When I placed that in there it did put a .pdf on the end of it but it still gives the message, filke not found. Ahhhhh! I going nuts with what should be a simple function, anyway any ideas?
-
Nov 29th, 2000, 08:43 PM
#21
Junior Member
Brian...
I'm going nuts too, and my TV got screwed up all of a sudden. If you feel like it, email me with your project files at my email address [email protected]... and I'll see that your code should hopefully run.
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 29th, 2000, 09:14 PM
#22
Junior Member
Listen Brian...
Sometimes while you're coding, you run into dead ends. You face tiny problems that seem really silly and that could drive you mad. Those kind of situations, are solved with persistance and only persistance. Keep debugging, and use trial and error till you solve it. And when you do, you'd have learnt a valuable lesson.
By the way, how old are you? 
I'll goto bed now, good luck.
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 30th, 2000, 12:26 AM
#23
PowerPoster
Hi! Brainh, May be you can try to remove those single qoute in your directry name and use the Trim() function before you add any data into your listbox:
Code:
'Do use the With Statement, to speed up your performance too
With rsdigiID
If .RecordCount <> 0 Then
'To ensure all the data is sort accordingly
.MoveLast
.MoveFirst
Do Until .EOF
'To ensure there is no leading/trailling space
lstQuery.AddItem Trim(.Fields("Name_of_Document"))
.MoveNext
Loop
End If
End With
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_ERR = (-1)
Private Const LB_GETCURSEL = &H188
Private Sub Command1_Click()
Dim Idx As Integer
'Get the current list index
Idx = SendMessage(lstQueryList.hwnd, LB_GETCURSEL, 0, 0)
'If not error
If Idx <> LB_ERR Then
Shell "C:\Program Files\Adobe\Acrobat 4.0 Reader\AcroRd32.exe G:\efiles\" & lstQueryList.List(Idx), vbMaximizedFocus
Else
MsgBox "Please select a file from the list box", vbExclamation
End If
End Sub
-
Nov 30th, 2000, 02:50 AM
#24
Addicted Member
hey, if you want you can use the following code. With this you can open the associated program (like doubleclicking on the file in the explorer)
Code:
'function to start file with associated program
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
Dim lngResult As Long
Dim sFile As String
sFile = "c:\temp\test.pdf"
'this will open acrobat reader
lngResult = ShellExecute(hwnd, "Open", sFile, "", "", vbNormalFocus)
-
Nov 30th, 2000, 10:29 AM
#25
Thread Starter
Fanatic Member
Well I will try these different methods, I am on Pacific Time so I just got to work. Rabih I am 25, probably a little older than you expected. I am a network administrator (Netware 4.11) but have jumped into this VB project.
-
Nov 30th, 2000, 01:56 PM
#26
Junior Member
Replace your cmdView_Click
'I just added the trim function here, 'cause your DB may have the Name_Of_Document containing unnecessary spaces
'tell me what happens
Private Sub cmdView_Click()
If lstQuery.List(lstQuery.ListIndex) <> "" Then
Shell "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\" & Trim(lstQuery.List(lstQuery.ListIndex)), vbMaximizedFocus
Else
MsgBox "Please select a file from the list box", vbExclamation
End If
End Sub
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 30th, 2000, 02:09 PM
#27
Thread Starter
Fanatic Member
You'll never guess what happened. It will open some files and not others. I went to confirm that a certain file was there and ried to open it and it opens Adobe Acrobat and then gives me the error message (Cannot open file, file does not exist). I try another one and it works fine... AHHHHHHHHHHHHHHHHHHH, am I going nuts? By the way how old are you?
-
Nov 30th, 2000, 02:16 PM
#28
Junior Member
I'm 23, just two years younger than you. I bet you thought I was 14 or something. You won't believe it, by some of the VB gurus on this forum, are this old. AAHHHHHHHHH, I'm ready to help you, tell me exactly what went wrong this time? Atleast, something worked right.. !
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 30th, 2000, 02:30 PM
#29
Thread Starter
Fanatic Member
OK here goes:
When I run one of the queries it fills the list box as it should. I then click on one of the names in the list box and click on the view button. Each time it will being up Adobe Reader as it should but sometimes it (Adobe) will say "There was an erro opening this document, this file does not exist", and about 50% of the timew it will actually open the file. I am verifying that the files exist and I have tried it with files created by different owners, the only thing else that I can thing of as far as file properties is size, I have also tried it with various dates. There is know sensible explanantion that I can come up with right now, thanks for all of your help.
-
Nov 30th, 2000, 02:44 PM
#30
Junior Member
Could it be, that you're logged on as a user, and when you try to open files belonging to other users, that could be inaccessible to you.?
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 30th, 2000, 02:53 PM
#31
Thread Starter
Fanatic Member
No because I have supervisor rigths to the root. I can opne any file in my container. I have tried opening various files, it doe snot matter how big or small, date created, owner, file name size, anything. I can't seem to pin point what is causing the inconsistency.
-
Nov 30th, 2000, 03:16 PM
#32
Junior Member
You know what Brian? you're facing many problems, due to the way the Name_Of_Document field is storing document names. Even though we are trimming unnecessary spaces from Name_Of_Document... what if the filename actually contains a space just before the dot and the extension.
To demonstrate this problem, this is an example:
If you have a file called Pamela.pdf, that is stored in the Name_Of_Document field as Pamela .pdf - that's with a space- then we display the name in the lstQuery as Pamela.pdf 'cause we trimmed it. Now this works fine.
But if you have a file called Pamela .pdf -with a space in it- then you display it in the lstQuery without the space as Pamela.pdf after being trimmed. So when you try to run it, it won't... 'cause it expects a file called Pamela .pdf. You get my point.
So this problem as I said, is due to the way you stored the document names in the database under Name_Of_Document... You must check each filename and whehter it contains any Leading or tailing spaces in your directory and thier correspondent names in the database. You could also code a small program to do that trimming in the database for you.
That's as much as my grey cells could do, Brian...
Tell me what happens? alright
Remember what I said about persistance... You need patience too.
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 30th, 2000, 04:21 PM
#33
Junior Member
Well...
Brian, you had a lunch break.. or what?
Keep me updated, will you ?
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Nov 30th, 2000, 04:30 PM
#34
Thread Starter
Fanatic Member
Sorry, I have to take care of some user problems and on top of that my email portion of the application just stopped working. What a day. There is no reason for that part to stop functioning as I have not made any changes to the coding. Anyway, I will let you know as soon as I can about the other part I am just trying to catch my breath. If you have anymore suggestions I sure would appreciate them and thank you for your help thus far.
-
Nov 30th, 2000, 05:45 PM
#35
Junior Member
Wow, I finally connected.
I know you're too busy Brian, take your time...
I'm always there...
Rabih Waked
Using Visual Basic 6 Enterprise Edition with SP4.
The clock is ticking, the end of days
A journey awaits...
-
Dec 1st, 2000, 11:33 AM
#36
Thread Starter
Fanatic Member
Well you figured it out. It was a space problem. The DB had a space in the names and the files did also but when I trimmed the name at the list box it would cause an error because that was not the correct name anymore. I have manually changed all of the names that were like that to get rid of all spaces (there were only about 45 entries). I have also got it so it trims the name before renming it. I hopefully have got this one tasken care of. Thanks for all of your help, I could have not made it without you!
-
Dec 1st, 2000, 12:26 PM
#37
Junior Member
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
|