Author |
Topic: FNnxtwrd() TOOL (fixed again) (Read 491 times) |
|
michael
Senior Member
member is offline


Posts: 335
|
 |
FNnxtwrd() TOOL (fixed again)
« Thread started on: Nov 1st, 2016, 01:37am » |
|
This tool should work for an interpreter style project.
This is not meant for keyboard interpreter. It is for interpreting structured macros created by a drawing program.
I have improved it after the later posts...
Code: g$="happy halloween my fellow programmers "
REPEAT
h$=FNnxtwrd(g$)
IF h$<>"" THEN PRINT h$
UNTIL h$=""
END
DEFFNnxtwrd(c$)
PRIVATE cnt%
LOCAL ret$
cnt%=cnt%+1
WHILE MID$(c$,cnt%,1)<>" "
ret$=ret$+MID$(c$,cnt%,1)
cnt%=cnt%+1
ENDWHILE
IF ret$="" THEN cnt%=0
=ret$
|
« Last Edit: Nov 2nd, 2016, 02:45am by michael » |
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: FNnxtwrd() TOOL (fixed)
« Reply #1 on: Nov 1st, 2016, 09:15am » |
|
Hi Michael,
It work fine, but it's a shame that you need to add a space and an asterisk at the end of your string. It will also fail if there are punctuation marks instead of spaces (and the punctuation marks will end up in your words).
The issue with a terminal space is particularly critical - as written the subroutine gets locked into an infinite loop!
Could you write a version that avoids those pitfalls? That might be more generally useful.
Best wishes,
D
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: FNnxtwrd() TOOL (fixed)
« Reply #2 on: Nov 1st, 2016, 2:32pm » |
|
When my button creation suite is completed, and the PAINT macro tool, it will have this tool built in. Its not meant to be a keyboard input tool. Your mouse will do the work. It will work like windows paint, but instead of making a BMP image, it will make macros. You wont be needing to do fine work, as objects, such as body parts will be easy to select and place on your creation.
It will take time, but its coming.. Here is a sneak peak at the work in progress:
( keep in mind this is a button only creation version. The PAINT version for toons will work off of this model.)
http://programming.conforums.com/index.cgi?board=Experiment&action=display&num=1477270529&start=0
|
« Last Edit: Nov 1st, 2016, 2:35pm by michael » |
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
Zaphod
Guest
|
 |
Re: FNnxtwrd() TOOL (fixed)
« Reply #3 on: Nov 1st, 2016, 3:31pm » |
|
Let's see if we can suggest alternative ways of doing this. What we are doing is scanning the string g$ one character at a time until we get to a space. We could do that more simply and faster by using INSTR(g$,CHR$32), it is what that keyword does. Then you return the first word and also keep a count of where you were.
The next time around you give it the original string again and start counting from the point you left off previously. What you could do instead is just RETURN the remainder of the string once you had got your first word and use that. In which case you can start from the beginning of the returned word again and don't need the counter. word$=LEFT$(g$,J%-1) :remainder$=MID$(g$,J%+1)
Then you had to know how many times to go through the loop and supply the original string that many times. But if you use the remainder$ you don't have to do that and you know when you are done because the remainder$ is "". This lets the repeated application of FNnxtwrd(g$)type function be compacted into a loop with a finite termination point.
So the code could look like: Code: g$="happy halloween my fellow programmers!!! * "
REPEAT
PRINT FNgetword(g$)
UNTIL g$=""
END
DEF FNgetword(RETURN z$)
LOCAL J%, b$
J%=INSTR(z$,CHR$32) :REM Find the next space
IF J% THEN
b$=LEFT$(z$,J%-1) :z$=MID$(z$,J%+1) :REM Slice off next value from string.
ELSE
=FNtrim(z$) :REM No space so must be last field in record.
ENDIF
=FNtrim(b$)
DEF FNtrim(a$)
REM trim any punctuation here as needed.
=a$
Finally I put in FNtrim(a$)which is a blank function where you could put any triming of punctuation that DDRM mentioned. And, of course, you don't need the "*" to terminate the string.
Was this a trick or a treat?
|
« Last Edit: Nov 1st, 2016, 7:37pm by Zaphod » |
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: FNnxtwrd() TOOL (fixed again)
« Reply #4 on: Nov 2nd, 2016, 02:41am » |
|
I improved the first post and will improve it more later as my program needs increase, which they will.. Thanks for the snippets... I will work on this.
|
|
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
|