I have an application that I am trying to remove items from a Listview control but every time I use the deletestring command the program crashes on me. I have been able to duplicate this with even a skeleton application with the same results. Below is a sample code where I simply add two items to a listview control and then click a button and it is supposed to delete an item from the listview. Instead the application just exist (crashes) without any warning. Anyone have any ideas what I am doing wrong?
Def w1 as Window
OpenWindow w1,0,0,600,710,@MINBOX|@MAXBOX|@SIZE,NULL,"Test",&main
CONTROL w1,@BUTTON,"Poll",425,100,70,20,0x50000000,1
CONTROL w1,@LISTBOX,"All",23,26,300,500,0x50B00148,5
addstring(w1,5,"Test 1")
addstring(w1,5,"Test 2")
WAITUNTIL w1 = 0
END
SUB main
select @class
endselect
IF @CLASS = @IDCLOSEWINDOW
CLOSEWINDOW w1
ENDIF
select @CONTROLID
case 1
gosub dothis
endselect
RETURN
ENDSUB
sub dothis
deletestring W1,5,0
return
endsub
Your main routine is structured wrong.
The following version of your program works as expected.
Def w1 as Window
OpenWindow w1,0,0,600,710,@MINBOX|@MAXBOX|@SIZE,NULL,"Test",&main
CONTROL w1,@BUTTON,"Poll",425,100,70,20,0x50000000,1
CONTROL w1,@LISTBOX,"All",23,26,300,500,0x50B00148,5
addstring(w1,5,"Test 1")
addstring(w1,5,"Test 2")
WAITUNTIL w1 = 0
END
SUB main
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
CLOSEWINDOW w1
case @IDCONTROL
SELECT @CONTROLID
case 1
dothis()
endselect
endselect
RETURN
ENDSUB
sub dothis()
deletestring W1,5,0
return
endsub
Thanks I wasn't even paying attention to my sloppy code. ;) After I fixed the structure it worked fine. thanks again.
mlwhitt
You used "sloppy code" and "structure" in your replay.
There's a significant difference between the two.
Programs can still work even when the code is sloppy.
If the fundamental structure is wrong they typically never work.
Think of you program as a car.
You can't drive it without tires (a structual issue) but you can drive it with dirty tires(a sloppy issue).
Your program didn't work because of the structual issue. (The proper arrangement of the nested select statements.)
Just wanting to make sure you understand. Not questioning your programming skill/experience. ;)
Larry