Announcement

Collapse
No announcement yet.

Comm.bas example I declare!

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

  • Comm.bas example I declare!

    ..or rather there are NO declares for functions or subs.

    I've been away for awhile, and was back doing some programming. I was reviewing the code from the provided comm.bas code in the samples.

    I noticed there are no declares for subs or functions that I can find. No .inc files other than the win32api.inc. Yet this program compiles! I can even add a function without declaring it, and it compiles! (Yes, I still have PBWin 8.04)

    Ok, I've searched the forums, and stared at the code, and I can't figure out why this works.

    It's not a big deal, just curiosity is getting the best of me...

    Anyone care to slap me upside the head, and give me the simple answer?!
    "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
    "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

  • #2
    No .inc files other than the win32api.inc. Yet this program compiles!
    Of course. It only uses statements built-in in the compiler. If it was not for the equates, you won't even need win32api.inc.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      http://www.powerbasic.com/support/pb...ad.php?t=40197
      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


      • #4
        Originally posted by José Roca View Post
        Of course. It only uses statements built-in in the compiler. If it was not for the equates, you won't even need win32api.inc.
        Uh, I don't think that is true.... Anyway, as I said, I can add a dummy sub, which I KNOW is not built in, and it still compiles without a declare of my dummy sub.

        Thanks, Mel, but I'm using PBwin 8.04, which still requires (AFAIK) everything to be declared. (I'll soon have ver 9, but not yet I don't)

        What am I missing here?
        "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
        "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

        Comment


        • #5
          Oh, and Jose, if I cut and paste into a new file any of the functions from comm.bas into a new program...the compiler asks them to be declared....
          "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
          "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

          Comment


          • #6
            Uh, I don't think that is true.... Anyway, as I said, I can add a dummy sub, which I KNOW is not built in, and it still compiles without a declare of my dummy sub.
            You don't need a declare if the code that is going to use the function or procedure is located AFTER it, or if you use CALL.
            Forum: http://www.jose.it-berater.org/smfforum/index.php

            Comment


            • #7
              I can add this function...

              function doug() as long
              local x as INTEGER
              for x=1 to 5
              next x
              END function

              and call it PREVIOUSLY in code

              Call Doug()

              Still doesn't require a declaration...
              "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
              "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

              Comment


              • #8
                Oh, and Jose, if I cut and paste into a new file any of the functions from comm.bas into a new program...the compiler asks them to be declared....
                Any? I have cut and pasted this one and the compiler does not complain.

                Code:
                #COMPILE EXE
                #DIM ALL
                #INCLUDE "Win32API.inc"
                
                SUB AddLine (BYVAL hWnd AS DWORD, BYVAL nID AS LONG, SendText AS ASCIIZ)
                
                    LOCAL ListCount AS LONG
                
                    ' find the current listbox count
                    CONTROL SEND hWnd, nID, %LB_GETCOUNT, 0, 0 TO ListCount
                
                    ' update the listbox
                    CONTROL SEND hWnd, nID, %LB_ADDSTRING, 0, VARPTR(SendText)
                
                    ' scroll the new item into view
                    CONTROL SEND hWnd, nID, %LB_SETCURSEL, ListCount, 0
                
                END SUB
                
                
                FUNCTION PBMAIN () AS LONG
                
                    MSGBOX "ok"
                
                END FUNCTION
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  Originally posted by Doug Hitchens View Post
                  I can add this function...

                  function doug() as long
                  local x as INTEGER
                  for x=1 to 5
                  next x
                  END function

                  and call it PREVIOUSLY in code

                  Call Doug()

                  Still doesn't require a declaration...
                  I have said "You don't need a declare if the code that is going to use the function or procedure is located AFTER it, or if you use CALL. "
                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                  Comment


                  • #10
                    Maybe I wasn't clear enough, I DID forward reference it, actually, I referenced the function before and after. Still compiled.

                    I guess "any" was a poor choice of words, I didn't realize I'd be taken that literally. I meant to only say that I'd cut and pasted much of the code to work with a test program, and then the functions/subs required declaration. Maybe not all of them would have, if there were no forward references, I didn't get that nuts about it....

                    Got any other ideas....

                    Really, it's not that big of a deal, I was just curious as to what I was missing here....
                    "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
                    "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

                    Comment


                    • #11
                      ....and by what you say...shouldn't the following code require a declaration of "Addline"?

                      Note, I rem'ed out the .inc, and changed the equates to values just to make sure Addline wasn't already declared. Then I moved PBmain ahead of the procedure, and called the function as a forward reference...

                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      '#INCLUDE "Win32API.inc"
                      
                      FUNCTION PBMAIN () AS LONG
                         local txt as asciiz*12
                          MSGBOX "ok"
                           call addline(0,0,txt)
                      END FUNCTION
                      
                      SUB AddLine (BYVAL hWnd AS DWORD, BYVAL nID AS LONG, SendText AS ASCIIZ)
                      
                          LOCAL ListCount AS LONG
                      
                          ' find the current listbox count
                          'CONTROL SEND hWnd, nID, 1, 0, 0 TO ListCount
                      
                          ' update the listbox
                          'CONTROL SEND hWnd, nID, 2, 0, VARPTR(SendText)
                      
                          ' scroll the new item into view
                          'CONTROL SEND hWnd, nID, 3, ListCount, 0
                      
                      END SUB
                      "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
                      "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

                      Comment


                      • #12
                        :dang:

                        OH...I said I'd been away from programming for awhile. I see using "Call" must tell the compiler to find the reference and define it at that time....

                        I knew it was something silly I was missing...

                        Thanks!
                        "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
                        "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

                        Comment


                        • #13
                          Well, CALL obviates the need for the DECLARE, but so does using PBCC 5+ or PBWIN 9+.

                          Forward-referencing of procedures was an added new feature of those versions.

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

                          Comment


                          • #14
                            well tonight I found a use for forwarding (bad VB habits) but came in handy to hurriedly test an idea.

                            Bad part is to not forget and go back to declare each piece, and then later run into problems because I forgot to get each nut in its place and each bolt in the right screw....."Wait...why is there a bolt where the screw should be????" GAHHHHHHHH

                            Its all in the details, and my own preference is to make sure all details are handled if I can handle it so years down the line I am not troubleshooting a simple oversight
                            Engineer's Motto: If it aint broke take it apart and fix it

                            "If at 1st you don't succeed... call it version 1.0"

                            "Half of Programming is coding"....."The other 90% is DEBUGGING"

                            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                            Comment

                            Working...
                            X