Page 1 of 1

New Key Words?

Posted: Sat Sep 11, 2004 12:21 pm
by RichardL
Hi,

I'm a beginner with PureBasic so may have overlooked the obvious, please excuse!

1. It would be good to have INC and DEC to increment/decrement a variable.

INC MyVariableName

is neater than:

MyVariableName = MyVariableName + 1

etc

2. SWAP(variable1, variable2)
This makes life so much quicker when writing sorting routines that involve multiple arrays

v.l = Sernum.l(n.w) : Sernum.l(n.w) = Sernum.l(n.w+1) : Sernum.l(n.w+1)=v.l

becomes
SWAP(Sernum.l(n.w) ,Sernum.l(n.w+1)

Should work with all variable types.

3. ARRAYFILL Arrayname(),Value
Great for initialising / clearing.

4. MID(String$,Posn,Limit) = Item$
Insertion is a neat way to build/modify strings.


I have acheived the function of all these suggestions by other means, but PB would be better with them.

Also, BMOVE, MEMBFILL would be nice...

My previous BASIC was 16bit GFA, so these are the things I miss when migrating programs to PB.

Apart from the standard editor, I'm acheiving results with PB... thats what counts.
jaBPe is an improvement

RichardL

Posted: Sat Sep 11, 2004 12:27 pm
by Pupil
for your #1 use this :

Code: Select all

variable + <expression>
; it's the same as
variable = variable + <expression>
; this goes for all operators that need a LHS and RHS
so instead of your:
"INC MyVariableName"
do this:

MyVariableName + 1

Posted: Sat Sep 11, 2004 12:50 pm
by RichardL
Thanks... I did not spot that one.

Posted: Tue Sep 14, 2004 11:03 am
by Kazmirzak
You can do Swap() with a procedure:

Code: Select all

Procedure Swap(p1,p2)
  Protected temp
  temp.l=PeekL(p1) : PokeL(p1,PeekL(p2)) : PokeL(p2,temp)
EndProcedure


a=100 : b=200 : 

Swap(@a,@b)
Notice that this works for Longs and Floats; if you want to swap Words or Bytes, you have to use PokeW,PeekW, and PokeB,PeekB.

Posted: Sun Sep 19, 2004 1:17 pm
by blueznl
ah, INC... gfabasic users unite! :-)

turning asm on, you could do INC a

alternatives:

a=a+1
a+1

unfortunately, there's no a++ (which i liked, as my eyes somehow confuse my mind every time i see a a+1 without an '=' sign...)