Testing if a variable has been declared

Results 1 to 2 of 2

Thread: Testing if a variable has been declared

  1. #1
    J-P Guest

    Default Testing if a variable has been declared

    How can I check that a variable has been declared? I know using Option<BR>Explicit will throw an error if a variable hasn&#039t been declared but this<BR>isn&#039t what I need. I&#039ve tried using isEmpty but that will only tell me if a<BR>variable has been declared and is empty. I need to check whether a variable<BR>has been declared and if it hasn&#039t, then declare it.<BR><BR>Many Thanks<BR>J-P<BR><BR>P.S. I have played around with Cold Fusion a little, this has a tag called CFPARAM, if anyone has come across it, this is the sort of functionality I am looking for.

  2. #2
    peterjl@austec.net.au Guest

    Default RE: Testing if a variable has been declared

    You could probably use the construct<BR><BR>if TypeOf objectname Is objecttype then<BR>..<BR>end if<BR><BR>However I feel that if you are running into this kind of problem, you would probably be best to organise your script into subroutines, and then the variable that you need would be local to the subroutine and errors would not result from trying to declare a variable that is already declared.<BR><BR>Alternatively, you could move all your dim statements to the top of your script, and declare all the variables here. I assume that in your script you have mutliple places where you declare variable. You will find that having a common area where you do all dims, will be easier to maintain. This approach would be okay as long as you don&#039t have a huge number of variable. Even if you are going to use them for objects they won&#039t take up much memory until they actually get used.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts