Loading ...
Sorry, an error occurred while loading the content.
 

Super cool bug/feature?

Expand Messages
  • Richard
    During a recent half asleep/psychotic episode I wrote something similar to this: Print Freaky automatic handle$ for idx = 1 to 5 f$ = test + str$(idx) open
    Message 1 of 4 , Jun 15, 2013
      During a recent half asleep/psychotic episode I wrote something similar to this:

      Print "Freaky automatic handle$"
      for idx = 1 to 5
      f$ = "test" + str$(idx)
      open f$ for append as #hndl$
      h$ = hndl$
      print h$
      close#h$
      next

      AND IT WORKED!!!

      I haven't seen any docs or code using this anywhere, so I assume I may have found something new.

      It would be SWEET to have the automatic naming feature in a usable form, but If you try to use the same open statement again without closing the file you get an error saying handle$ is already in use

      Print "Freaky automatic handle$"
      for idx = 1 to 5
      f$ = "test" + str$(idx)
      open f$(idx) for append as #hndl$
      h$(idx) = hndl$
      print h$(idx)
      for idx = 1 to 5
      j$ = h$(idx)
      close#j$
      next

      Of course, maphandle makes it all moot, but it's still kinda cool
    • Stefan Pendl
      ... It works, but is it correct? Have you checked the contents of the variables in the debugger? Using handle variables when creating an object is not
      Message 2 of 4 , Jun 15, 2013
        Am 15.06.2013 12:42, schrieb Richard:
        > During a recent half asleep/psychotic episode I wrote something similar to this:
        >
        > Print "Freaky automatic handle$"
        > for idx = 1 to 5
        > f$ = "test" + str$(idx)
        > open f$ for append as #hndl$
        > h$ = hndl$
        > print h$
        > close#h$
        > next
        >
        > AND IT WORKED!!!
        >

        It works, but is it correct?

        Have you checked the contents of the variables in the debugger?

        Using handle variables when creating an object is not supported.

        Doing it anyways results in undefined behavior.

        I don't think you would use an application that relays on undefined
        behavior.


        --
        Stefan Pendl
        http://stefanpendl.runbasichosting.com/

        LB 4.04 Pro ... http://www.libertybasic.com/assist.html
        LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

        LB Community Wiki .............. http://basic.wikispaces.com/
        LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
        LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

        Books at http://www.lulu.com/ and http://www.amazon.com/
        Alyce Watson ... APIs for Liberty BASIC
        Carl Gundel .... Beginning Programming with Liberty BASIC

        Windows 7 Home Premium 64-bit SP1
        AMD Turion X2 RM-70 2GHz, 4GB RAM
      • Richard
        ... I m quite certain it is NOT correct. You are right that this shouldn t be used. It s useless anyway, since it errors out at runtime if you try to open two
        Message 3 of 4 , Jun 15, 2013
          --- In libertybasic@yahoogroups.com, Stefan Pendl <pendl2megabit@...> wrote:
          > It works, but is it correct?

          I'm quite certain it is NOT correct. You are right that this shouldn't be used. It's useless anyway, since it errors out at runtime if you try to open two files at the same time. (Note my example carefully closes each file before opening another..Imagine trying to figure this one out in a large application!)

          I've always been very impressed with the quality of LB. It's why I've been using it for decades. This is the only time I've ever personally seen a hole in the syntax checking. Just thought it should be seen!

          Having said that, and not wanting to mislead anyone, here is a way this could be done correctly:



          'This does what I was trying to do but in a correct way.
          'I can have all 6 files open at the same time now!
          Print "Correct way to automatically assign file handles."
          for idx = 1 to 6
          hnarray$(idx) = "#autofile" + str$(idx)
          file$ = "File"+str$(idx)
          open file$ for append as #noname 'NEVER put the $ on the end here
          maphandle #noname, hnarray$(idx) 'This assigns my generated handle to the file
          Print file$;" as handle ";hnarray$(idx)
          next
          print
          print "Now close the files"
          for idx = 1 to 6
          hn$ = hnarray$(idx)
          close #hn$ 'Can't directly use an array in a close statement
          print "Closed ";hn$
          next
          end
        • Sarmed N.
          Have you a way to build a string variable from two strings variables? If you have, it will be very useful indeed. I try but failed. ---code AB$= 3000 C$= A
          Message 4 of 4 , Jun 15, 2013
            Have you a way to build a string variable from two strings variables?
            If you have, it will be very useful indeed.
            I try but failed.

            '---code
            AB$="3000"
            C$="A"
            R$="B$"
            '----------
            print AB$
            print C$;R$
            wait
            '---code

            Thank you



            ________________________________
            From: Richard <glitz486@...>
            To: libertybasic@yahoogroups.com
            Sent: Sunday, June 16, 2013 12:13 AM
            Subject: [libertybasic] Re: Super cool bug/feature?



             


            --- In libertybasic@yahoogroups.com, Stefan Pendl <pendl2megabit@...> wrote:
            > It works, but is it correct?

            I'm quite certain it is NOT correct. You are right that this shouldn't be used. It's useless anyway, since it errors out at runtime if you try to open two files at the same time. (Note my example carefully closes each file before opening another..Imagine trying to figure this one out in a large application!)

            I've always been very impressed with the quality of LB. It's why I've been using it for decades. This is the only time I've ever personally seen a hole in the syntax checking. Just thought it should be seen!

            Having said that, and not wanting to mislead anyone, here is a way this could be done correctly:

            'This does what I was trying to do but in a correct way.
            'I can have all 6 files open at the same time now!
            Print "Correct way to automatically assign file handles."
            for idx = 1 to 6
            hnarray$(idx) = "#autofile" + str$(idx)
            file$ = "File"+str$(idx)
            open file$ for append as #noname 'NEVER put the $ on the end here
            maphandle #noname, hnarray$(idx) 'This assigns my generated handle to the file
            Print file$;" as handle ";hnarray$(idx)
            next
            print
            print "Now close the files"
            for idx = 1 to 6
            hn$ = hnarray$(idx)
            close #hn$ 'Can't directly use an array in a close statement
            print "Closed ";hn$
            next
            end




            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.