Announcement

Collapse
No announcement yet.

Display variables in code?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Display variables in code?

    What I am trying to do is allow a user to type in the name
    of a variable and then display the value. For instance,
    if X is 10 and the user types in X I want the program to be able
    to go into memory where X is and display 10.

    I have PB 3.1 so I don't have pointers.

    PEEK and VARPTR/STRPTR don't seem to be enough.

    Thanks!
    Chris

    ------------------

  • #2
    Although what you want is possible, doing it directly really
    isn't feasable. What I would do is create a special subroutine
    and define a single hot key. When the hot key is pressed, the
    program will jump to that routine and display the names and
    current values of whatever you chose to have displayed.


    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      Chris --

      You would have to "simulate" that type of thing, because when a PowerBASIC program is compiled all of the variable names are removed. They are replaced by internal symbols that are not human-readable.

      So you would have to hard-code strings that contain the names of your variables, like sMyVarName(1) = "lResult%", compare what the user types to the list of variables, and then display the appropriate value.

      -- Eric

      ------------------
      Perfect Sync: Perfect Sync Development Tools
      Email: mailto:[email protected][email protected]</A>

      [This message has been edited by Eric Pearson (edited February 01, 2001).]
      "Not my circus, not my monkeys."

      Comment


      • #4
        Thanks for the tips. Although the program is over 2500 lines
        of code and there are hundreds of variables I can try
        just showing the values of the most important ones that way.

        Still, I think if I had pointers I could do it!

        -Chris

        ------------------

        Comment


        • #5
          Still, I think if I had pointers I could do it!
          I don't.

          (Except by the painstaking method shown earlier, creating literals for all your datanames)

          MCM

          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            I think PBD lets you watch variables by name so if you really wanted
            to dig it out I suspect you could generate the exe with PBDdebug
            info on and save the map file .. from there you may be able to get
            what you want.

            I don't know if anyone has done that and I have no idea how
            daunting the task may be but I suspect it would be considerable.

            Mike


            ------------------

            Comment


            • #7
              MM-

              I believe with pointers you could do it, just not sure how.

              I understand that this is a hard thing to do though, so I more
              than understand your thoughts!

              Thanks, and I'll keep trying
              Chris

              ------------------

              Comment


              • #8
                Chris, can you tell us the reason behind the question? Firstly, I'm interested to know what type of program would need this feature.

                The only easy solution to display variables at runtime would require you to work purely in the debugger, but the debugger (PB.EXE, PBD.EXE, PBC.EXE) are not redistributable without purchasing a special license ($$$$$$$).

                I note this because the type of solution you are looking for is not directly achievable in compiled PowerBASIC code. Using the MAP file to dynamically query variables on an adhoc basis is likely to be a bigger job than it warrants. Pointers would probably help, but they would not be essential for this purpose, since you still have the use of PEEK, PEEKI, etc, in PB3.1/3.2.

                Finally, and I'm hesitant to suggest this, but if the need for this solution is that important, and the intensive coding required is too complex, you may need to use an _interpreted_ Basic that supports that type of feature instead of PowerBASIC. Afterall, no single compiler or language can possibly be the best tool for *every* possible task.


                ------------------
                Lance
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment


                • #9
                  Chris --

                  > I believe with pointers you could do it

                  The original names of the variables simply do not exist in the compiled EXE, so I don't see how pointers could possibly help you.

                  You could use pointers to access the memory where variable values are stored, but you could do that with PEEK just as easily. Or just use the variables themselves, as in PRINT X%. There's no reason (that I can see) to use pointers or PEEK.

                  -- Eric

                  ------------------
                  Perfect Sync: Perfect Sync Development Tools
                  Email: mailto:[email protected][email protected]</A>
                  "Not my circus, not my monkeys."

                  Comment


                  • #10
                    MM-
                    I believe with pointers you could do it, just not sure how.

                    I understand that this is a hard thing to do though, so I more
                    than understand your thoughts!

                    Thanks, and I'll keep trying
                    You are not listening, Chris. This cannot be done! (except as stated before).

                    You don't have to take my word for it. Mr Pearson said the same thing, and he's been programming a while.

                    Me? I wrote my first computer program in 1967, when - I'll guess - you were pretty young.

                    Free advice: Don't waste your time trying to find datanames - because they do not exist in the compiled program. Period.

                    MCM

                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Michael --

                      > 1967

                      You've got me beat, but not by much. Not counting some primitive programmable calculators, I wrote my first FORTRAN program in 1971.

                      -- Eric


                      ------------------
                      Perfect Sync: Perfect Sync Development Tools
                      Email: mailto:[email protected][email protected]</A>
                      "Not my circus, not my monkeys."

                      Comment


                      • #12
                        Well guys, considering I was born in '79 you got me beat!

                        Once again thanks for the advice. I guess it just isn't worth
                        it. If I do ever figure it out though, I'll let you know.

                        Chris

                        ------------------

                        Comment


                        • #13
                          Please do!

                          ------------------
                          Perfect Sync: Perfect Sync Development Tools
                          Email: mailto:[email protected][email protected]</A>
                          "Not my circus, not my monkeys."

                          Comment


                          • #14
                            Eric

                            Thanks for the help! I know that I am
                            outgunned here as far as programming experience (thats
                            why I asked the question here in the first place) but
                            remember how many times someone told you that
                            what you wanted to do was impossible.... and you did
                            it anyway!

                            I think this would be a very cool feature
                            to help debug large programs while they are running.
                            (The program I am working on has a UEVENT keyboard
                            handler so you can't break out of it and then continue
                            or the keyboard stops responding.)

                            Have a great weekend everyone!

                            Chris

                            ------------------

                            Comment


                            • #15
                              Now let's try that again......

                              what about using a case within a subroutine each element of the case being the name of the variables (sorry this is going to be long winded)

                              so if you want to find out the contents of the variable x and you have told the program this by entering it into the variable c$

                              then ....

                              call printit(c$)
                              ......

                              sub printit(d$)
                              select case d$
                              case "x"
                              add&=varptr(x)
                              print peeki(add&)
                              case "c%" etc.....
                              end select
                              end sub



                              ------------------

                              Comment


                              • #16
                                Good idea, but I was looking something like this:

                                Type in name of variable
                                Code gets name, looks up var in memory
                                Displays value on screen


                                I wanted to do it for any var in the program, as there are
                                hundreds of them.
                                The SELECT statement would be huge using that method with
                                that many variables, but it is a good idea for a smaller program!




                                Thanks
                                Chris


                                ------------------

                                Comment


                                • #17
                                  I tried to get pb to print out the peeki of the address of the variable named in the peeki of the string variable , but it didn't work

                                  so I thought of this case, I like the problem, so may mull over it a bit more.

                                  mike



                                  ------------------

                                  Comment


                                  • #18
                                    Michael, at runtime, there are NO (zero, zip, nada, nil) variable names in the compiled PowerBASIC code, so there is absolutely NO way to query a variable by its name.

                                    Unless your code is hard-coded to do this, of course:
                                    Code:
                                    LINE INPUT "enter the variable name", A$
                                    IF A$ = "A$" THEN PRINT A$
                                    IF A$ = "B$" THEN PRINT B$
                                    ' [i]ad infinitum...[/i]
                                    ------------------
                                    Lance
                                    PowerBASIC Support
                                    mailto:[email protected][email protected]</A>
                                    Lance
                                    mailto:[email protected]

                                    Comment


                                    • #19
                                      Hi,

                                      just a thought... what exactly do the addresses mean in the .MAP file, generated
                                      by the compiler when using the $DEBUG MAP directive?

                                      There is a section that looks like this:

                                      Address Publics

                                      2292:3F3C PLATFORMTYPE
                                      2292:5B12 PUTATTRIBS
                                      2292:59DE PUTFILENAME
                                      2292:3CB2 CHECKTEXTFILE

                                      It contains both public routines, and global and main variables. But I cannot find
                                      any useful information on the corresponding addresses.

                                      (Btw, why is HTML always off in messages? )

                                      Regards,

                                      ------------------
                                      Sebastian Groeneveld
                                      mailto:[email protected][email protected]</A>


                                      [This message has been edited by Sebastian Groeneveld (edited February 15, 2001).]
                                      Sebastian Groeneveld
                                      mailto:[email protected][email protected]</A>

                                      Comment


                                      • #20
                                        Sebastian has a point here, we can get the variable name (don't know about the type yet) from the map file, the variabless are named in this file together with the hex value of their address, so the program could open this file up loop for the variables and print out the peeki of the address voila!

                                        mike


                                        ------------------

                                        Comment

                                        Working...
                                        X