[erlang-questions] Cesarini/Thompson wxErlang chapter - how to write lastLineRange?

Angel <>
Wed Mar 10 02:20:33 CET 2010

On Martes, 9 de Marzo de 2010 14:53:23 Michael Turner escribió:
> I'm trying to work through the wx example in Cesarini & Thompson
> (chapter "GUI programming with wxErlang".  On p.319 there are two
> calls to a function lastLineRange on a wx TextCtrl.  The authors don't
> supply this function, and I can't see any corresponding C++ member
> function in the wxTextCtrl API here
>   http://docs.wxwidgets.org/trunk/classwx_text_ctrl.html
> It's looking like I have to write lastLineRange myself, to finish
> working through this chapter.  Unless ... someone else has already run
> into this roadblock, got around it, and can map out the detour for me?
> I'm sure I'll kludge something up, but it would be nice to do this one
> more or less by the book, if possible.
> -michael turner
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
lastLineRange seems to be a local function, not a wxwidgets one, maybe they 
didnt want to use undo facilities for the text control... (too complicated for 
a example)

a quick fix (not tested) for this can be:

LastLineRange(Text) ->
	ListOfLines=string:tokens(Text,[[10]]),  %% Tokenize buffer on newlines
	LastLine=lists:last(ListOfLines),           %% find the last line
	StarPos= wxTextCtrl:getlastposition() - length(LastLine),
	EndPos = wxTextCtrl:getlastposition,

Maybe it just works, YMMV


Most people know C is not so high level....
                ...Everybody else just got assembler overdose

More information about the erlang-questions mailing list