Re: Problems with ListViewCtrl on PPC2002 and PPC2003

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: pfnus (pfnus_at_hotmail.com)
Date: 10/06/04


Date: 6 Oct 2004 01:16:56 -0700

Ok, i think i have found out the problems.

Private Sub Test_Click()

Dim litm As ListItem
On Error Resume Next

Set litm=mylist.ListItems.Add(,"key1","item1")
litm.SubItems(1)="test1"

Set litm=mylist.ListItems.Add(,"key2","item2")
litm.SubItems(1)="test2"

'here i did a search of the list items by using the Key
sTemp=mylist.ListItems.Item("key1").Text <-------This is the problem
line!!!
if Err.number<>0 Then
'do something
End if

msgbox "...."
'the rest of the codes/scripts here are not executed.........

End Sub

Comments:

sTemp is "item1" if the item exist. However, if the item does not
exist, the program just do nothing, the rest of the codes are not
executed.

This happens on PPC2003.,only. There is Err generated if test it on
PPC2002.,and the application will continue executing the codes after
the problem line as mentioned above.

Why is this so??? It is not because On Error Resume Next doesn't work
in PPC2003, because if i raised an error in PPC2003 before anything, i
can catch the error in "If Err.number<>0".

"Keld Laursen" <kl@ideelektronik.obsolete.dk> wrote in message news:<OO$iKsxqEHA.412@TK2MSFTNGP10.phx.gbl>...
> There are a couple of quirks with the PPC2003 runtime modules. Some of them
> are related to on error not catching errors.
>
> But exactly what are you wanting to do with that line of code?
> > mylistview.ListItems.Item(index).Text
> doesn't seem to do anything useful.
>
> You specifically says that the ListView isn't populated yet.
>
> What happens if you do something like:
> if mylistview.ListItems.Count then
> mylistview.ListItems(mylistview.ListIndex).Text?
> end if
>
> What is the value of the index variable anyway= Something out of range?
>
> Using some foreign variable in that scenario would probably lead to code
> like this:
> if index>0 and index<=mylistview.ListItems.Count then
> Do Something with the ListView
> end if
>
> This would have the added advantage of not requiring the use of on error
> resume or other error handling code as all the usual errors (bounds etc) are
> already checked.
> In any case, it is bad practice to handle errors (at least checkable in
> advance type errors) by using on error... constructs.
>
> /Keld Laursen
>
> "pfnus" <pfnus@hotmail.com> skrev i en meddelelse
> news:a96e4cad.0410050040.2eb51d92@posting.google.com...
> > Hi,
> >
> > I am using Microsoft CE ListViewCtrl 3.0 on eVB.
> >
> > I compiled on PPC2002 but run it on PPC2003. The code runs okay on
> > PPC2002.
> >
> > The following doesn't work.. why?? There is no item inserted in my
> > list view control yet.
> > However i want to know why:-
> >
> > The statement MsgBox "I am here" was never executed., or whatever code
> > following the mylistview.ListItems.Item(index).Text was not executed.
> >
> > Private Sub Command_Click()
> > mylistview.ListItems.Item(index).Text
> > MsgBox "I am here"
> > End Sub
> >
> > I also tried the following: -
> >
> > Private Sub Command_Click()
> > On Error Resume Next
> > mylistview.ListItems.Item(index).Text
> > MsgBox "I am here"
> >
> > if Err.number<>0 Then
> > MsgBox "Error here"
> > End if
> > End Sub



Relevant Pages