Announcement

Collapse
No announcement yet.

PBDLL 7 Item wish (bet you're getting fed up with these :)

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

  • PBDLL 7 Item wish (bet you're getting fed up with these :)

    I would like to see a function in PBDLL7 that lets you create a
    name using string manipulation and then Zap it with this new function
    which will convert it into a powerbasic control name,,,
    erm.. perhaps I can best illustrate this with an example
    (by the way, the new 'zap' function would need an error checking part as well)

    Zap = "FOR"
    If ZapErr THEN EXIT FUNCTION 'Does this control name exist?

    Zap a& = 1 to 10
    'do stuff
    NEXT

    Another example
    a$ = "mid$left$right$"
    b$ = "Hello there"
    Zap = mid$(a$, 5, 5) 'Left$
    IF ZapErr THEN EXIT FUNCTION
    c$ = Zap(b$, 5)
    [/code]

    Now you're going to ask me why aren't you

    Well I remember needing to do this a few times but I can't remember the
    explicit instances, can anyone think of any?

    Still being able to programatically calculate functions is bound to be
    a useful thing isn't it? (I'll bet no other programming language has it...)

    Ian


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

  • #2
    Oh yeah, and another thing,,
    I have always been irritated by the STR$ function inserting a space
    at the beginning,,, Just now I've had to quickly knock up a CC program
    so that I could remember if it puts the space before or after
    and I've found out again that it puts the space before,,,

    a$="1234" & str$(567) & "890"
    print a$

    will produce 1234 567890

    I am forever using TRIM$(STR$(567)) to overcome my inability to remember
    this 'feature'

    Surely tho' if we as programmers wanted to insert a space we'd do it???

    Maybe its some sort of age old standard but can't we break with 'standards'
    just this once to remove this nuisance? please?

    There,, I feel much better now

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

    Comment


    • #3
      Originally posted by ian mcallister:
      Oh yeah, and another thing,,
      I have always been irritated by the STR$ function inserting a space
      at the beginning,,,
      Str$(x&) has a companion Format$(x&)
      If you need a space before the number use Str$
      If you dont need the space use Format$


      ------------------
      Fred
      mailto:[email protected][email protected]</A>
      http://www.oxenby.se

      Fred
      mailto:[email protected][email protected]</A>
      http://www.oxenby.se

      Comment


      • #4
        Ah, right,,, sorry I didn't know that, just looked at the help,,
        so I can use FORMAT$(123) instead and it won't put in that pesky space.

        Thanks Fred

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

        Comment


        • #5
          I'm just programming something where I could use the Zap function,,,
          Using the Freebie EasyGUI DDT designer I need to read some controls.

          I have to do this at the moment:
          Code:
          SUB GetControlValues
          DIM Start$(7), Break$(7), Finish$(7), Totals$(7)
          
             CONTROL GET TEXT hForm1&, %FORM1_START1 TO Start$(1)
             CONTROL GET TEXT hForm1&, %FORM1_START2 TO Start$(2)
             CONTROL GET TEXT hForm1&, %FORM1_START3 TO Start$(3)
             CONTROL GET TEXT hForm1&, %FORM1_START4 TO Start$(4)
             CONTROL GET TEXT hForm1&, %FORM1_START5 TO Start$(5)
             CONTROL GET TEXT hForm1&, %FORM1_START6 TO Start$(6)
             CONTROL GET TEXT hForm1&, %FORM1_START7 TO Start$(7)
          
             CONTROL GET TEXT hForm1&, %FORM1_BREAK1 TO Break$(1)
             CONTROL GET TEXT hForm1&, %FORM1_BREAK2 TO Break$(2)
             CONTROL GET TEXT hForm1&, %FORM1_BREAK3 TO Break$(3)
             CONTROL GET TEXT hForm1&, %FORM1_BREAK4 TO Break$(4)
             CONTROL GET TEXT hForm1&, %FORM1_BREAK5 TO Break$(5)
             CONTROL GET TEXT hForm1&, %FORM1_BREAK6 TO Break$(6)
             CONTROL GET TEXT hForm1&, %FORM1_BREAK7 TO Break$(7)
             
             CONTROL GET TEXT hForm1&, %FORM1_FINISH1 TO Finish$(1)
             CONTROL GET TEXT hForm1&, %FORM1_FINISH2 TO Finish$(2)
             CONTROL GET TEXT hForm1&, %FORM1_FINISH3 TO Finish$(3)
             CONTROL GET TEXT hForm1&, %FORM1_FINISH4 TO Finish$(4)
             CONTROL GET TEXT hForm1&, %FORM1_FINISH5 TO Finish$(5)
             CONTROL GET TEXT hForm1&, %FORM1_FINISH6 TO Finish$(6)
             CONTROL GET TEXT hForm1&, %FORM1_FINISH7 TO Finish$(7)
             
             CONTROL GET TEXT hForm1&, %FORM1_TOTALS1 TO Totals$(1)
             CONTROL GET TEXT hForm1&, %FORM1_TOTALS2 TO Totals$(2)
             CONTROL GET TEXT hForm1&, %FORM1_TOTALS3 TO Totals$(3)
             CONTROL GET TEXT hForm1&, %FORM1_TOTALS4 TO Totals$(4)
             CONTROL GET TEXT hForm1&, %FORM1_TOTALS5 TO Totals$(5)
             CONTROL GET TEXT hForm1&, %FORM1_TOTALS6 TO Totals$(6)
             CONTROL GET TEXT hForm1&, %FORM1_TOTALS7 TO Totals$(7)
             
          END SUB
          (the %FORM1_..... variables are constants)
          Using the Zap function I could do this:
          Code:
          SUB GetControlValues
          DIM Start$(7), Break$(7), Finish$(7), Totals$(7)
          
          FOR a&=1 TO 4
              IF a&=1 THEN a$ = "Start"
              IF a&=2 THEN a$ = "Break"
              IF a&=3 THEN a$ = "Finish"
              IF a&=3 THEN a$ = "Total"
              FOR b&=1 to 7
                  Zap1 = "%FORM1_" & a$ & FORMAT$(a&) 'Thanks Fred  
                  Zap2 = a$ & "(" & FORMAT$(a&) & ")"
                  CONTROL GET TEXT hForm1&, Zap1 TO Zap2
              NEXT
          NEXT
          END SUB
          Give or take a bit of upper/lowercaseness...
          Notice that I've increased the Zap function to Zap1, Zap2 etc.

          Ian

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

          Comment


          • #6
            It does look a little like a macro (of sorts), and I know macro's are already on the wish list. Still, I'll pass the idea along to R&D.

            Taking your last example, you can do that specific task with the existing tools anyway (assuming your equates are sequentially numbered, and you ensure the arrays use the appropriate subscript range):
            Code:
            FOR b&=0 TO 6
              CONTROL GET TEXT hForm1&, %FORM1_START1 + b& TO Start$(b& + 1)
            NEXT
            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment


            • #7
              >FOR b&=0 TO 6
              >CONTROL GET TEXT hForm1&, %FORM1_START1 + b& TO Start$(b& + 1)
              >NEXT

              What about %FORM1_START2, %FORM1_START3 etc. ?

              The equates are not in sequential order.

              Ian


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

              Comment


              • #8
                Then make them into sequential order...

                Afterall, your equate names are in sequential order, why not their numeric values too? Seems logical to me...

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

                Comment


                • #9
                  Here they are:
                  Code:
                  %FORM1_LABEL13            = 100
                  %FORM1_LABEL12            = 105
                  %FORM1_LABEL11            = 110
                  %FORM1_LABEL10            = 115
                  %FORM1_LABEL9             = 120
                  %FORM1_LABEL8             = 125
                  %FORM1_LABEL7             = 130
                  %FORM1_LABEL6             = 135
                  %FORM1_LABEL5             = 140
                  %FORM1_LABEL4             = 145
                  %FORM1_LABEL3             = 150
                  %FORM1_LABEL2             = 155
                  %FORM1_LABEL1             = 160
                  %FORM1_START1             = 165
                  %FORM1_BREAK1             = 170
                  %FORM1_FINISH1            = 175
                  %FORM1_TOTALS1            = 180
                  %FORM1_START2             = 185
                  %FORM1_BREAK2             = 190
                  %FORM1_FINISH2            = 195
                  %FORM1_TOTALS2            = 200
                  %FORM1_START3             = 205
                  %FORM1_BREAK3             = 210
                  %FORM1_FINISH3            = 215
                  %FORM1_TOTALS3            = 220
                  %FORM1_START4             = 225
                  %FORM1_BREAK4             = 230
                  %FORM1_FINISH4            = 235
                  %FORM1_TOTALS4            = 240
                  %FORM1_START5             = 245
                  %FORM1_BREAK5             = 250
                  %FORM1_FINISH5            = 255
                  %FORM1_TOTALS5            = 260
                  %FORM1_START6             = 265
                  %FORM1_BREAK6             = 270
                  %FORM1_FINISH6            = 275
                  %FORM1_TOTALS6            = 280
                  %FORM1_START7             = 285
                  %FORM1_BREAK7             = 290
                  %FORM1_FINISH7            = 295
                  %FORM1_TOTALS7            = 300
                  %FORM1_TOTAL              = 305
                  %FORM1_RESET              = 310
                  A bit fiddly to change em all don't you think?
                  What with tab order etc. to consider.

                  Besides I only gave this as ONE example of where the function I described
                  would come in handy, you took this example to demonstrate to me how I
                  could change my programming so that I wouldn't need the function that I describe
                  in this particular instance, how many instances should I come up with before
                  it might be deemed a useful function?

                  I'm only asking as I could 'double-bluff' you into helping me with all my
                  other crappy programming techniques


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

                  Comment


                  • #10
                    Ian ;

                    Here a simple fix to Lances suggestion:

                    The control IDs are incremented by 20, which make it match up
                    with the IDs you are using.

                    Code:
                    FOR b&=0 TO 6
                      CONTROL GET TEXT hForm1&, %FORM1_START1 + (b&*20) TO Start$(b& + 1)
                    NEXT b&
                    Programming Lesson: Always look for patterns in a numbering sequence !



                    ------------------
                    Chris Boss
                    Computer Workshop
                    Developer of "EZGUI"
                    http://cwsof.com
                    http://twitter.com/EZGUIProGuy

                    Comment


                    • #11
                      erm,,,, are we missing the point here or what?

                      Come on all you readers of this forum, I need your help.

                      Has anyone got any instances of where it would be handy to programmatically
                      calculate a PB function name which could then be used in a program.

                      Zap = "MSGBOX"

                      Zap "Hello"

                      etc. etc. etc.

                      I believe it would be a very useful function, does anyone agree with me?

                      Thanks

                      Ian

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

                      Comment


                      • #12
                        Ian --

                        If you are talking about compile-time Macros, like this:

                        Code:
                        Zap = "MSGBOX"
                        Zap "Hello"
                        ...then sure, I agree that Macros would be an excellent addition to the PowerBASIC languages. That would not be a practical syntax, but the idea is workable.

                        But if you mean the actual runtime calculation of things like this:

                        Code:
                        MyString$ = "MSGBOX"
                        Zap = MyString$
                        Zap "Hello"
                        ...then No. That type of thing is relatively easy to do in an interpreted language, but the overhead required to do it in a compiled language would far outweigh the benefits. Keep in mind that PowerBASIC-produced EXE and DLL files have very "granular" runtime libraries. They only contain the functions that are necessary for the program. If you don't use MSGBOX, the code for MSGBOX is not included in the EXE or DLL.

                        Consider this:

                        Code:
                        LINE INPUT MyString$
                        Zap = MyString$
                        Zap "Hello"
                        In order to accomplish that, your EXE or DLL would have to contain every possible PB runtime function, plus the names of all of the functions, plus all of the calling conventions... You have basically changed PowerBASIC from a compiler to an interpreter.

                        And if Zap returned a value (as the MSGBOX function can do), what would happen if MyString$ contained the name of a function that returned a string value, as opposed to a numeric 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 16, 2001).]
                        "Not my circus, not my monkeys."

                        Comment


                        • #13
                          I see, so it would be very difficult to implement if the user
                          wished to use it to calculate the command because the program has
                          already been compiled.

                          Yep I see what you mean,,

                          If its just used at compile time then is that what you mean by a macro?

                          like in my source code I might have a variable

                          Zap = "MSGBOX" and during compile the compiler could pick this up and
                          insert MSGBOX instead of Zap but while the code was running then
                          if I'd coded:

                          Zap = "%FORM1_FINISH" & "4"

                          then this wouldn't work because the code had already been compiled.

                          I think I understand now.

                          Thanks

                          Ian



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

                          Comment

                          Working...
                          X