|
-
Jun 20th, 2000, 09:12 PM
#1
Thread Starter
Lively Member
Hi all
Trying to fix a crazy problem.
My program is alright on debug,but the compiled version always crashes.
The function:
Public Function combo_list(cur_cb As ListBox, count As Integer, Optional text_str) As Integer
On Error GoTo erhand
Dim i As Integer
Dim found As Integer
i = 1
If IsMissing(text_str) Then
i = 2
check_test = cur_cb.Text
Else
i = 3
check_test = text_str
End If
i = 4
i = 5
For i = 0 To count
If check_test = cur_cb.List(i) Then
found = 1
Exit For
End If
Next
If found = 1 Then
combo_list = i + 1
Else
combo_list = -1
End If
Exit Function
erhand:
MsgBox "combolist : " & Chr(13) & Err.Description & Chr(13) & "number: " & Err.Number & Chr(13) & "number of items: " & " number in loop: " & i & Chr(13) & "list box is: ", 64
End Function
the i variable indecates where the function crashes in the error message.
it always happens when I call a method of cur_cb
(cur_cb.List(i) or cur_cb.Text)
Is there any logical explantion ???
Thanks.
Dan.
-
Jun 21st, 2000, 07:30 AM
#2
Fanatic Member
Hi Dan
I think I may have the answer your looking for:
It seems from your code (as you did not explain what it does) that you pass a Listbox and count(this i reckon is the number of items you wish to search through - starting from zero, and NOT the whole listbox) and also a text variable (word).
Point 1
If you wish to search all the listitems then it does not make sense to pass the total each time (as a param) when you can get access to it in the routine.
If this is not the case and you wish to search from zero up to the N'th item then that makes more sense (from my understanding of your implementation of the parameters)
The function:
Code:
Public Function combo_list(cur_cb As ListBox, count As Integer, Optional text_str) As Integer
Dim i As Integer
Dim found As Integer
Dim myword as string
On Error resume next
'initialise return value
combo_list=0
'check for text
myword=trim(text_str)
if err<>0 then exit function
'if we are here then text exists
check_test = text_str
'now depending on if i understood you
'its either the next block of code or
'the one below the next block
'CODE BLOCK - OPTION 1
'search upto the N'th listitem
'first check to ensure it is a valid value
if count<1 or count >cur_cb.listcount then exit function
For i = 0 To count
If check_test = cur_cb.List(i) Then
combo_list=i+1
exit function
End If
Next
'CODE BLOCK - OPTION 2
'search all the listitems
For i = 0 To cur_cb.listcount-1
If check_test = cur_cb.List(i) Then
combo_list=i+1
exit function
End If
Next
'
End Function
DocZaf
{;->
-
Jun 21st, 2000, 09:05 PM
#3
Thread Starter
Lively Member
Zaf,
The count parameter is a parameter I added while trying to debug my code.
It does not appear in the orriginal function.
This is the original:
Public Function combo_list(cur_cb As ListBox,Optional text_str) As Integer
Dim i As Integer
Dim found As Integer
If IsMissing(text_str) Then
check_test = cur_cb.Text
Else
check_test = text_str
End If
For i = 0 To cur_cb.listcount-1
If check_test = cur_cb.List(i) Then
found = 1
Exit For
End If
Next
If found = 1 Then
combo_list = i + 1
Else
combo_list = -1
End If
End Function
The function is supposed to find the index number in the listbox (given by parameter) of a string .
The string is ither a parameter(Optional text_str) or if the parameter is not sent then it is the selected item of the listbox itself(cur_cb.Text).
I must mention that I have the same function running in a nother program (compiled in vb5),but insted of a list box the function accepts a combobox,and it works fine.
I dont know if the difference is that now I am working with vb6 or that the new function accepts a listbox rather than a combobox.
Your Help is much appresiated
Thanks.
Dan.
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
|