Page 1 of 1
Buildops
Posted: Thu Sep 07, 2006 4:05 am
by mydsworld
Can anyone please tell me how to use a variable (to be used in 'Per-Record' ) to remember its value.
Posted: Thu Sep 07, 2006 6:36 am
by ray.wurlod
Welcome aboard. :D
Initialize the variable in the "before" code, and use it in the "per record" section. If you must, create a static variable. If that term is unfamiliar, enrol in a class to learn some C.
Posted: Thu Sep 07, 2006 7:00 am
by mydsworld
I tried that. I have defined the following in Definitions :
#include<stdio.h>
#include<iostream.h>
int x ;
static int y ;
In Pre-Loop :
y = 0 ;
Then in Per-Record :
x = in0.id ;
if(x != y) {
< Taking some action> ;
}
else {
< Take some other action > ;
}
y = x ;
Input is auto-read. But I find control never go to 'else' section though there are such records.
Posted: Thu Sep 07, 2006 7:04 am
by ray.wurlod
You're going to have to incorporate some debugging statements in your code to capture the actual values of x and y and record them somewhere so that you can work out what's happening.
Posted: Thu Sep 07, 2006 7:12 am
by mydsworld
Thanks for your advise.
I even tried that. 'y' is always 0.
I tried another approach. I made the auto-read for input false. Now I am defining the control (looping) in my own. In that case the dbout I am having is where to put the entire code : Pre-Loop,Per-Record,Post-Loop editor.
Posted: Thu Sep 07, 2006 3:37 pm
by ray.wurlod
You only have access to the rows in the per-record code. Therefore you ought not to be writing your own loop. The variable called y is behaving properly like a static variable (I misunderstood your original requirement); try making it a regular variable.