CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2001
    Location
    Halifax, Nova Scotia Canada
    Posts
    5

    vb variable macros

    In clipper you could macro your variables. so a variable could be called peanut&a where "a" could be either butter or oil. peanutbutter and peanutoil would have seperate values anyone know a vb way of doing the same?


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: vb variable macros

    Something like this?

    a = "oil"
    '....
    b = "peanut" & a




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Jul 2001
    Location
    Halifax, Nova Scotia Canada
    Posts
    5

    Re: vb variable macros

    more so like
    a=1
    period&a = 1
    a=a+1
    Period&a = 2

    results

    period1=1
    period2=2



  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: vb variable macros

    Oh, that isn't really possible in VB, what is possible is to create an array, and address it via it's index, like this:

    Dim peanut(1 to 3)
    a = 1
    peanut(a) = 1
    a = 2
    peanut(a) = 2
    a = 2
    peanut(a) = 3
    ' results in
    peanut(1) = 1
    peanut(2) = 2
    peanut(3) = 3





    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  5. #5
    Join Date
    Jul 2001
    Location
    Halifax, Nova Scotia Canada
    Posts
    5

    Re: vb variable macros

    Thanks, I'm very familier with arrays.



  6. #6
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: vb variable macros

    Or you could use a Collection class and key it thus:



    Dim Peanut as Collection

    set Peanut = new Collection

    Peanut.Add "£3.10","Oil"
    Peanut.Add "£2.50","Butter"

    Debug.print Peanut("Oil")




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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

Featured