Variable may not have been initialized

Navigation:  Messages > Macro Compiler Messages > Warnings >

Variable may not have been initialized

Previous pageReturn to chapter overviewNext page

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 refered to is undefined.

 

In the case of and if-else 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 updated on 05-Jul-2003.
Topic URL: http://www.qppstudio.net/webhelp/index.html?variablemaynothavebeeninitiali.htm