Results 1 to 8 of 8

Thread: Declare Variable name from variable value

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    8

    Declare Variable name from variable value

    Hi

    Can anyone tell me if/how it's possible to declare a variable whose name is the value of another variable ?

    e.g.

    Var1 = "CC203" then

    "Dim Var1" - which would dim a variable of name CC203

    Cheers
    GavinB.

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Declare Variable name from variable value

    It is possible but quite complex - what is the ultimate aim of this?

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    8

    Re: Declare Variable name from variable value

    Hi

    I need to create a number of variables to use within a crystal report - the number of variables depends on the number of items in a field in a database. If I declare the variables statically then I have to amend the code each time a new record is entered into the database. So being able to do this programmatically is much more ideal.

    Cheers
    GavinB.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Declare Variable name from variable value

    Why not use an array?

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    8

    Re: Declare Variable name from variable value

    I'm not sure if I could do it that way, but I will look into it. I'd still appreciate some pointers as to how to do the variable declaration bit though !

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Declare Variable name from variable value

    I was going to suggest using reflection but that is for creating .Net classes (and thereby variables) not crystal reports.

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    8

    Re: Declare Variable name from variable value

    That is ok - some of the variables are passed to the report as parameters others are used within the .aspx page to perform a number of calculations.

  8. #8
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Declare Variable name from variable value

    I think that you can use dynamically resized arrays to acomplish what you want to do...

    Still, if you need to create a variable with a specific name you should use the VBCodeProvider Class and check out ICodeCompiler. Basically, you can use that to compile something (a property or public variable) that uses a given variable name and then you need to use reflection to get a hold of that and then use that to pass the variable around. Pretty tedious - like mendhak has already indicated try to steer clear of all that unless it's absolutely necessary.
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

Posting Permissions

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



Click Here to Expand Forum to Full Width