Problem with client terminal global variable in while loop.

 

Hello, I'm trying to change a variable in a while loop and every loop set a new client terminal variable.

This is the while condition

      while (GlobalVariableCheck("paaridearv")<43)
      {
         if(avatud<1)
         {
            Kirjuta();
         }
      }


This is the loop

void Kirjuta()

   int varset=GlobalVariableSet("avatud",1);
   int positsioonid  =   FileOpen("positsioonid.bin",FILE_BIN|FILE_READ|FILE_WRITE);
   if (positsioonid>0)
   {
      FileSeek(positsioonid,0,SEEK_END);
      FileWriteDouble(positsioonid,sorting1,DOUBLE_VALUE);
      FileSeek(positsioonid,0,SEEK_END);
      FileWriteDouble(positsioonid,sorting2,DOUBLE_VALUE);
      FileClose(positsioonid);
      int varget = GlobalVariableGet("avatud");// uus var
      avatud=varget;
      GlobalVariableSet("avatud",avatud-1);
      paaridearv++;
      GlobalVariableSet("paaridearv",paaridearv);
   }
   return(0);
}


Even after many iterations the "paaridearv" client terminal global variable value is still 1

Taavi

 

Did you notice that GlobalVariableCheck just returns a bool value of either true or false. So in your loop it makes no sense to check whether a bool value is less than 43. GlobalVariableGet returns the actual double value of the GlobalVariable.

The commands you are using to change the value of paaridearv (paaridearv++;) and then set that to the GlobalVariable (GlobalVariableSet("paaridearv",paaridearv);) are both inside a conditional which checks the file handle of the open file to make sure that the file is open. If the file isn't being opened for some reason then all the commands inside that conditional will not be run (because in that case the return of FileOpen is -1), and so the value of paaridearv or its GlobalVariable will not be changed. There does not seem to be any error reporting to highlight times when the file is not opened correctly. Your program would just continue on merrily without mentioning the error.

Also we can not tell from the code what value avatud is before the conditional "if(avatud<1)" is run for the first time, or even what datatype it is. If avatud is >= 1 then the conditional will never even trigger once, so your Kirjuta() function will never run and paaridearv or its GlobalVariable will never be changed during the loop.

Reason: