 |
 |
|

11-12-2003, 12:08 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
Sorry.......
|
I know it must be really annoying for you guys when someone like me comes and asks the most stupid questions, but im really struggling with my college project and at present i have no reference to help me ( i do have same VB on its way).
Im trying to search for text in a listbox. I have the following code.
Private Sub CmdSearch_Click()
For i = 1 To 15
If TxtTitle.Text Like title(i) Then
lbltitle.Caption = title(i)
End If
Next i
End Sub
So when the user clicks the cmdsearch button, the txttitle textbox data is compared to an array of string i have called title(15) and whe it gets the right match it will paste the name of the relevant title(15) into the lbltitle label.
Unfortunatly, when i run the program, as soon as i click on the cmdsearch i get the message "sub or function not defined" and the "title(i)" after the "like" is highlighted.
I have never used the "like" command before but i presumeit is there if you need to compare to variables.
Im not sure if ive explained myself fully here but if anyone has any ideas i would appreciate it.
Thanks
Will
|
|

11-12-2003, 12:24 PM
|
 |
Senior Contributor
|
|
Join Date: Dec 2002
Location: Netherlands
Posts: 867
|
|
|
Just replace 'Like' with '='
If txttitle.text = title(i) then
Wilbert
|
|

11-12-2003, 12:25 PM
|
|
Contributor
|
|
Join Date: Aug 2002
Posts: 515
|
|
|
Has Title() been initilized/declared & given data?
|
|

11-12-2003, 12:26 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
Nope, didnt work, i did try that first before i tried "like". It just comes up with the same error message.
|
|

11-12-2003, 12:27 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
Yes, title was initialised
Private Sub Form_Load()
Dim title(15) As String
Dim genre(15) As String
Dim year(15) As Integer
Dim rating(15) As String
Dim length(15) As Integer
Dim description(15) As String
That is the first few lines of the form_load routine.
I did think that maybe it had something to do with title being a local variable and not a global one but we havent covered that at college yet so wasnt sure.
|
|

11-12-2003, 12:35 PM
|
 |
Senior Contributor
|
|
Join Date: Dec 2002
Location: Netherlands
Posts: 867
|
|
|
Yes that's true, declare those arrays in the general section of your form.
|
|

11-12-2003, 12:38 PM
|
|
Junior Contributor
|
|
Join Date: Oct 2003
Location: So. Calif
Posts: 342
|
|
|
Will,
All those variables are going to go out of focus as soon as the form_load event is done, and therefore will not be available anywhere else. I believe in MSDN they call it Scope.
remove the variables from that event and put them in the General Declarations section of the form code window, right under the option explicit statement. Then try again and let us know
|
|

11-12-2003, 12:39 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
hmm, did that and noqw i get the message complie error: member already exists a object module from wehich the object module derives.
|
|

11-12-2003, 12:57 PM
|
|
Junior Contributor
|
|
Join Date: Oct 2003
Location: So. Calif
Posts: 342
|
|
|
Where/when is this error happening? what line is being highlighted?
|
|

11-12-2003, 01:00 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
This is the full code of my project (not a lot)
Dim title(15) As String
Dim genre(15) As String
Dim year(15) As Integer
Dim rating(15) As String
Dim length(15) As Integer
Dim description(15) As String
Private Sub CmdSearch_Click()
For i = 1 To 15
If TxtTitle.Text = title(i) Then
lbltitle.Caption = title(i)
End If
Next i
End Sub
Private Sub Form_Load()
title(1) = "The Matrix"
title(2) = "Final Destination"
title(3) = "Signs"
title(4) = "Scary Movie"
title(5) = "Shallow Hal"
title(6) = "The Others"
title(7) = "Sixth sense"
title(8) = "Terminator 3"
title(9) = "Next Friday"
title(10) = "Liar Liar"
genre(1) = "Sci Fi"
genre(2) = "Horror"
genre(3) = "Horror"
genre(4) = "Comedy"
genre(5) = "Comedy"
genre(6) = "Horror"
genre(7) = "Horror"
genre(8) = "Action"
genre(9) = "Comedy"
genre(10) = "Comedy"
year(1) = 1999
year(2) = 2000
year(3) = 2002
year(4) = 2000
year(5) = 2001
year(6) = 2001
year(7) = 1999
year(8) = 2003
year(9) = 2000
year(10) = 1997
rating(1) = "R"
rating(2) = "R"
rating(3) = "PG-13"
rating(4) = "R"
rating(5) = "PG-13"
rating(6) = "PG-13"
rating(7) = "PG-13"
rating(8) = "R"
rating(9) = "R"
rating(10) = "PG-13"
length(1) = 136
length(2) = 98
length(3) = 106
length(4) = 88
length(5) = 113
length(6) = 101
length(7) = 107
length(8) = 109
length(9) = 98
length(10) = 86
description(1) = "A computer hacker learns from mysterious rebels about the true nature of his reality and his role in the war against the controllers of it."
description(2) = "After having a vision of his friends crashing in a plane, he tells them not to get on only later his friends start getting killed one by one."
description(3) = "A family living on a farm finds mysterious crop circles in their fields which suggests something more frightening to come."
description(4) = "A year after disposing the body of a man they accidently killed, a group of dumb teenagers are stalked by a bumbling serial killer."
description(5) = "A shallow man falls in love with a 300 pound woman because of her inner beauty."
description(6) = "A woman who lives in a darkened old house with her two photosensitive children becomes convinced that her family home is haunted."
description(7) = "A boy who communicates with spirits that don't know they're dead seeks the help of a disheartened child psychologist."
description(8) = "John Connor is now in his 20's, and a female terminator, called T-X or Terminatrix, is after him. "
description(9) = "Craig Jones moves from the ghetto to the suburbs to live with his lottery-winning uncle and cousins."
description(10) = "Jim Carrey is back in yet another great comedy, although it doesn't quite live up to the spectacular Dumb & Dumber"
Dim i As Integer
For i = 1 To 15
List1.AddItem (title(i))
Next i
For i = 1 To 15
List2.AddItem (genre(i))
Next i
For i = 1 To 15
List3.AddItem (year(i))
Next i
For i = 1 To 15
List4.AddItem (rating(i))
Next i
For i = 1 To 15
List5.AddItem (length(i))
Next i
For i = 1 To 15
List6.AddItem (description(i))
Next i
End Sub
The error message appears when i try running and it highlights the "genre(15) as string" part of the code right near the top. For some reason it doesnt give me the error message on the title(15) even though they are both declaring variables. The top bit of the code is under (general) (declarations)
|
|

11-12-2003, 01:06 PM
|
|
Banned
|
|
Join Date: Nov 2003
Location: England
Posts: 7
|
|
|
for i = 0 to 14
if searchlist.list(i) = searchtext then
''add the code here''
end if
next i
i can't remember if listboxes start at 0 or 1 anyway...
change searchtext to the text you want to find and searchlist to the listbox and it should work
|
|

11-12-2003, 01:10 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
Nope, still no joy, got the same message i had before. I tried moving the variables back to the form_load section and i still got the old error message.
|
|

11-12-2003, 01:14 PM
|
|
Banned
|
|
Join Date: Nov 2003
Location: England
Posts: 7
|
|
|
are u trying to search for text in a listbox or textbox? Cause if u searching a listbox then TxtTitle.Text will only return the text of the highlighted part of the listbox
|
|

11-12-2003, 01:17 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
txttile.text is the textbox that the user can type the title in that they are searching for and i want the details from txttitle.text to be compared to the title(15) array which is show in the listbox.
|
|

11-12-2003, 01:17 PM
|
|
Junior Contributor
|
|
Join Date: Oct 2003
Location: So. Calif
Posts: 342
|
|
|
Will ....
Save the project as it is ..... Zip it(all forms,modules.... everything) and upload it. For some reason it is creating that object twice. I would like to look at it, but since this is homework, we kind of limit ourselves to helping with homework and not doing it for someone.
|
|

11-12-2003, 01:21 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
Sure, where can i uplaod it to. I can mail it you if thats easier, its only a few k. I understand the thing about it being homework but at the end of the day if someone did it for me i wouldnt learn anything and that wouldnt do me much good.lol
|
|

11-12-2003, 01:22 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
Sorry, just seen the attachments bit at the bottom.
|
|

11-12-2003, 01:25 PM
|
|
Banned
|
|
Join Date: Nov 2003
Location: England
Posts: 7
|
|
|
there isn't a problem with ur code there although, personally, i think it would be easier to search listbox instead of an array
|
|

11-12-2003, 01:30 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Location: Blackpool, UK
Posts: 36
|
|
|
Well i didnt know you could do that.lol But....... Ive done the array becuase title(3) is relevent to genre(3) and length(3) etc, so all the arrays are linked around the same movie, if you get what i mean.
But im a pure beginner, only been doing VB for 7 weeks so maybe i could use the dearch listbox function, i have no idea. This guy at college did his project using a listview and his works really well, but he did VB last year and he knows what he's doing.lol
|
|

11-12-2003, 01:46 PM
|
|
Junior Contributor
|
|
Join Date: Oct 2003
Location: So. Calif
Posts: 342
|
|
|
Will ...
No Form ... the project wont load. try again
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|