PDA

View Full Version : Numbered List



catventure
01-12-2005, 15:25
Hi,

I do not think there is a way to display a listbox containing an array and have each item in the list consecutively numbered but I found it quite easy to create some code to do the job:



'code executed before showing strings in listboxes
'adds listnumber prefix to array elements for display purposes only

for i=1 to 500
verb(i)=ltrim$(str$(i)+". "+verb(i))
noun(i)=ltrim$(str$(i)+". "+noun(i))
deletion(i)=ltrim$(str$(i)+". "+deletion(i))
if i<101 then
charnoun(i)=ltrim$(str$(i)+". "+charnoun(i))
end if
if i<201 then
prep(i)=ltrim$(str$(i)+". "+prep(i))
objnoun(i)=ltrim$(str$(i)+". "+objnoun(i))
end if
next


'code after exiting listbox dialog
'removes listnumber prefixes from array elements
'and restores them to normal

for i=1 to 500
verb(i)=remove$(verb(i),ltrim$(str$(i))+". ")
noun(i)=remove$(noun(i),ltrim$(str$(i))+". ")
deletion(i)=remove$(deletion(i),ltrim$(str$(i))+". ")
if i<101 then
charnoun(i)=remove$(charnoun(i),ltrim$(str$(i))+". ")
end if
if i<201 then
prep(i)=remove$(prep(i),ltrim$(str$(i))+". ")
objnoun(i)=remove$(objnoun(i),ltrim$(str$(i))+". ")
end if
next


This works fine and will show each entry in the listbox preceded by a number like so:

1. word
2. word
3. word
.........etc.


although if I code it using a WHILE/WEND loop TB hangs and I have to exit using CRTL+ALT+DELETE.
I've probably coded it wrong somewhere -------->



'code executed before showing strings in listboxes
'adds listnumber prefix to array elements for display purposes only
for i=1 to 500
verb(i)=ltrim$(str$(i)+". "+verb(i))
noun(i)=ltrim$(str$(i)+". "+noun(i))
deletion(i)=ltrim$(str$(i)+". "+deletion(i))
while i<101
charnoun(i)=ltrim$(str$(i)+". "+charnoun(i))
wend
while i<201
prep(i)=ltrim$(str$(i)+". "+prep(i))
objnoun(i)=ltrim$(str$(i)+". "+objnoun(i))
wend
next


Anyway the first way is good enough for me and shows how to have numbered arrays in listboxes.

catventure.

ErosOlmi
01-12-2005, 15:49
catventure,

during first FOR loop i is =1
After 3 lines you enter a WHILE/WEND infinite loop because inside this loop i will never change.

I think the correct code is to substitute WHILE i<101 with IF I<101 THEN
The same for the other WHILE/WEND loop.

Is it ok?
Eros

catventure
01-12-2005, 16:04
Hi Eros,

Yes it will work using IF and END IF perfectly as I found.
I must've been using while/wend wrongly.

A question for you: I've made some code to call up the ColorDialog requester to pick a color for the background of a texteditor...
How to convert the hex$ returned into the RGB components for the
CONTROL SET COLOR command?

Thank you.

catventure.

Petr Schreiber
01-12-2005, 16:31
Hi catventure,

It's quite simple, you can use it directly:


lColor = Dialog_ChooseColor&#40;0, rgb&#40;255, 0, 0&#41;, %CC_RGBINIT OR %CC_FULLOPEN &#41;
CONTROL SET COLOR hDlg, %IDTEXTBOX, %BLACK, lColor


this will make textbox to have black text and selected backgroud

Psch

catventure
01-12-2005, 18:54
Hi Psch,

Right, didn't know that. Anyway it does not seem to work if called in Windows Event handler loop. See below code. It seems you must do some further operation such as CONTROL SET TEXT to make the selected background color appear. Run this program. Background will not change after color selection. Run it agian with relevant line unremmed it does.
Weird...



USES "UI"


DIM Msg AS LONG
DIM wParam AS LONG
DIM lParam AS LONG
DIM hDlg AS LONG

dim lcolor as Long

DIALOG NEW 0, "TextBox example", -1, -1, 195, 180, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, _
0 TO hDlg

CONTROL ADD TEXTBOX , hDlg, 10, "Text box: left allign" , 5, 15, 185, 15, %WS_BORDER OR %WS_TABSTOP , %WS_EX_CLIENTEDGE
CONTROL ADD TEXTBOX , hDlg, 20, "Text box: center allign", 5, 30, 185, 15, %WS_BORDER OR %WS_TABSTOP OR %ES_CENTER , %WS_EX_CLIENTEDGE
CONTROL ADD TEXTBOX , hDlg, 30, "Text box: right allign" , 5, 45, 185, 15, %WS_BORDER OR %WS_TABSTOP OR %ES_RIGHT , %WS_EX_CLIENTEDGE
'CONTROL ADD TEXTBOX , hDlg, 40, "Text box: read only" , 5, 60, 185, 15, %WS_BORDER OR %WS_TABSTOP OR %ES_READONLY , %WS_EX_CLIENTEDGE
control add button,hdlg,40,"Change Background Color",5,60,185,15,%WS_BORDER or %WS_TABSTOP,%WS_EX_CLIENTEDGE
CONTROL ADD TEXTBOX , hDlg, 50, "" , 5, 75, 185, 100, %WS_BORDER OR _
%WS_TABSTOP OR _
%ES_WANTRETURN OR _
%ES_MULTILINE OR _
%ES_AUTOHSCROLL OR _
%ES_AUTOVSCROLL OR _
%WS_VSCROLL OR _
%WS_HSCROLL, _
%WS_EX_CLIENTEDGE


'---Show dialog in MODELESS state, the only managed state at the moment
DIALOG SHOW MODELESS hDlg

'---Message pump loop
WHILE IsWindow(hDlg)

'---Get the message and fill wParam and lParam
Msg = GetMessage(hDlg, wParam, lParam)

'---Now test the message
SELECT CASE Msg

case %WM_COMMAND
select case wparam
case 40
lcolor = Dialog_ChooseColor(hdlg, rgb(255, 255, 255), %CC_RGBINIT OR %CC_FULLOPEN )
if lcolor = -1 then
msgbox 0, "Color Dialog Cancelled By User"
else
CONTROL SET COLOR hdlg, 50,rgb(255,255,255),lcolor
'msgbox 0, "Your color is: " & hex$(lcolor, 6)
end if
'=======================
'REM WITHOUT THE FOLLOWING LINE THE BACKGROUND COLOR DOES NOT CHANGE
'control set text hdlg,50,"Background Color Changed!"
'========================
end select

CASE %WM_SYSCOMMAND
SELECT CASE wParam
CASE %SC_CLOSE
EXIT WHILE
END SELECT

CASE ELSE

END SELECT

WEND

'---Close the dialog
DIALOG END hDlg


Regards,
catventure.

catventure
01-12-2005, 19:11
As a workaround I found if you use the line:

control append text hdlg,50,"" instead of the control set text line

after the set control color operation then the color change to the background of the textbox will be done, but more importantly, without affecting any existing text that might be in the textbox. :)

So that's OK then.

catventure

Petr Schreiber
01-12-2005, 21:06
Hi,

you're right :),
But I found another solution, try:



CONTROL REDRAW hDlg, %ID_OF_CONTROL


Bye,
Psch

catventure
01-12-2005, 22:47
CONTROL REDRAW hDlg, %ID_OF_CONTROL


That would make more sense to use that Psch.

I had no idea such a command existed!

Well spotted.

Assuming it works, I'll alter my code to use that.

Cheers,
catventure