func Listbox_AddItem(listbox$, editbox$)
	text$ = GetText(editbox$);
	where$ = SendMessage(listbox$, LB_GETCOUNT, 0, 0);
	SendMessage(listbox$, LB_ADDSTRING, where$, text$);
Return(true);
end;


func Listbox_GetSelItem(listbox$, editbox$)
	where$ = SendMessage(listbox$, LB_GETCURSEL, 0, 0);
	text$ = GetItem(listbox$, where$);
	SetText(editbox$, text$);
Return(true);
end;


func Listbox_DelItem(listbox$)
	where$ = SendMessage(listbox$, LB_GETCURSEL, 0, 0);
	SendMessage(listbox$, LB_DELETESTRING, where$, 0);
Return(true);
end;


func Listbox_UpdateItem(listbox$, editbox$)
	text$ = GetText(editbox$);
	where$ = SendMessage(listbox$, LB_GETCURSEL, 0, 0);
	SendMessage(listbox$, LB_DELETESTRING, where$, 0);
	SendMessage(listbox$, LB_INSERTSTRING, where$, text$);
	//SendMessage(listbox$, LB_SETCURSEL, where$, text$); ?? is that functionnal for a replace ??
Return(true);
end;


func ListBox_SelAllItem(listbox$)
	where$ = SendMessage(listbox$, LB_GETCOUNT, 0, 0);
	i$=0;
		Repeat
		SendMessage(listbox$, LB_SETSEL, i$, i$);
		i$++;
		Until(i$>=where$);
	SendMessage(listbox$, LB_SETSEL, 1, 0);
Return (true);
end;


func Listbox_LoadFromList(listbox$, slist$)
	i$=0;
	scount$ = Count(slist$);
	  while (i$ < scount$)
	  SendMessage(listbox$, LB_ADDSTRING, i$, slist$);
	  Next(slist$);
	  i$++;
	end;
Return(true);
end;


func Listbox_Clear(listbox$)
	SendMessage(listbox$, LB_RESETCONTENT, 0, 0);
Return(true);
end;


func Listbox_LoadFromFile(listbox$, Filename$)
	s$ = LoadStr(Filename$, i$);
	List(slist$);
	StrToList (s$, "\n", slist$);
	i$=0;
	scount$ = Count(slist$);
	  while (i$ < scount$)
	  SendMessage(listbox$, LB_ADDSTRING, i$, slist$);
	  Next(slist$);
	  i$++;
	end;
Return(true);
end;

func Listbox_SaveToFile(listbox$, Filename$)
scount$ = SendMessage(listbox$, LB_GETCOUNT, 0, 0);
 List(slist$);
 i$ = 0;
  while (i$ <= scount$)
    Add(slist$);
    slist$ = GetItem(listbox$, i$);
    i$++;
  end;
  savetext$ = ListToStr (slist$, "\n", "");
  SaveStr(Filename$, savetext$, length(savetext$));
 Return(true);
end;

//Usage:

//Listbox_AddItem(LISTBOX101$,EDIT105$);
//Listbox_GetSelItem(LISTBOX101$,EDIT105$);
//Listbox_DelItem(LISTBOX101$);
//Listbox_UpdateItem(LISTBOX101$,EDIT105$);
//Listbox_SelAllItem(LISTBOX101$);
//listbox_LoadFromList(LISTBOX101$, slist$);
//listbox_Clear(LISTBOX101$);
//listbox_LoadFromFile(LISTBOX101$, "\\My Documents\\ListBox1.txt");
//listbox_SaveToFile(LISTBOX101$, "\\My Documents\\ListBox1.txt");