Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Var++ and Var - - Increment/Decrement

Status
Not open for further replies.

metron9

Programmer
Mar 5, 2002
94
US
If someone has a program that will read thru my old code
and replace

VARIABLE++ with VARIABLE = VARIABLE + 1

I sure could use it. It is slow and errorprone to replace the code manually.

I will write one if there are no replies. anyone that needs to convert old clipper code can have it when im finished.

Ill write it in foxbase of course.
 
Would this always be the first and only thing on a line? Is VARIABLE ++ valid also? (i.e. with a space)

Can it be part of an expression?

As you can tell I didn't use Clipper, but I've written lots of cleanup / conversion type programs.

Rick
 
Well you put me to the test Here is a program that answers your questions with the output. The ++ or -- work the same as the C programming language on variables. I was surprised to see that "a ++" with the space between the "a" and the "++" compiled and ran. Also the ++ or -- can be prefixed or postfixed as in ++a or a++ if you wrote x=++a the a variable would be incremented by 1 and then assigned to x, with x=a++ the x variable would be assigned the value of a and then the a variable would be incremented.

no spaces between the ++ or -- are allowed. ie "+ +" or "- -"


Program:
a=1
? a
a++
? a
a ++
? a
x=a++
? x
? a
? a++
? a
++ a
? a
++a
? a


Output:
1
2
3
3
4
4
5
6
7


 
Well I've, got a "simple" program that will process all .PRG files in a given directory. It seems to handle the following variants as a start:
var++
var--
++var
--var
var ++
var --
++ var
-- var

Since expressions like:
x=a++
?++a
x = y ++a && !
really expand to two (or more) commands, I didn't attack those yet (especially since you didn't give examples of:
?++a
x=++a
)

Since it's more than a couple lines, and most people probably aren't all that interested, please provide a way to get the program to you. You can always &quot;fix&quot; an email address so that it won't be picked up the automatic page readers for SPAM mail. Just post it like <yourfirstpart> AT NOSPAM <yoursecondpart> DOT com, I'll figure it out and Zip it up to you.

Rick
 
Sure send me the program
mark@ccspecial.com

I am sure it even creates a file like this:

LINE (xxxx) File xxx.PRG -> x=a++
CHANGED TO ---------------->> x=a
a=a+1



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top