Please enable JavaScript to view this site.

 

Navigation: Macros > Macro Language > Compiler Messages > Warnings

Variable may not have been initialized

Scroll Prev Up Next More

This compiler warning means that, at the line where it occurs, the value of a variable is used that may not have been initialized (ie. nothing in the code above that line specifies what its value should be).

 

This often happens when your code has a branch before, and in one of these branches the variable referred to is undefined.

 

In the case of an if branch it usually occurs if no value is assigned to the variable in the else branch (or if there is no else branch).

 

In the example below, if WeekdayOf(Today()) is not equal to 2, then the value of nTemp is undefined.

var
   nTemp
begin
   if WeekdayOf(Today()) == 2
      nTemp = 1
   else
      // what happens to nTemp here ???
   endif
   bRESULT = (nTemp == 2// nTemp may be undefined
end

This warning can also be caused by a missing else statement in a switch statement.

var
   nTemp sTemp
begin
   nTemp = n_TokenDate mod 3
   switch nTemp
      case 1
         sTemp = 'hryerg'
      case 2
         sTemp = 'fasdfad'
      else
         // what happens for all other cases ???
   endswitch
   bRESULT = (sTemp == 'h'// sTemp may be undefined
end

This warning can usually always be addressed by adding code to determine what happens in the else branch of a code branch.

 

See also: variable is not initialized.

 


Topic 109011, last updated on 18-Apr-2020