Announcement

Collapse
No announcement yet.

Windows error using &CRLF

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

  • Windows error using &CRLF

    As a newbie experimenting with PB, I was comparing how arrays behaved compared with VB and as part of this wanted to display a message box with each element on a separate line.
    Being unsure of the concatenation character I stared off using "&" but got a windows error with the following two lines of code. The error appeared about 2 seconds after code completed, indicating some sort of cleanup routine failed.
    sMessage= Ians(0) & $CRLF & Ians(1) & $CRLF & Ians(2) & $CRLF & Ians(3) & $CRLF & Ians(4)
    MSGBOX sMessage
    Message was:
    "Array.exe has encountered a problem and needs to close. We are sorry for the inconvenience" etc etc
    If I reduced the incidence of $CRLF thus:
    sMessage= Ians(0) & $CRLF & Ians(1) & $CRLF & Ians(2) & $CRLF & Ians(3)
    No error.
    I changed the "&" to a "+" to see if this changed the result.

    It did, It rebooted my PC!!

    Scary stuff - What am I doing wrong.

    TIA

    Ian B

  • #2
    Most likely an array subscript out of bounds issue.
    Try this code.
    Code:
    #DEBUG ERROR ON                  ' NB
    #INCLUDE "WIN32API.INC"
    Function PbMain()
     Local count As Long, sMessage, sArr As String 
     Dim Ians() As String        
     ON ERROR GOTO ErrorTrap
     Redim Ians(3)                        ' change to(4) to avoid out of bounds * 
      For count = 0 To 4                                '* <- goes out of bounds!
       Ians(count) = "Ians(" + format$(count) + ")"        
      Next
      sMessage = Ians(0) & $CRLF & Ians(1) + $CRLF + Ians(2) + $CRLF + Ians(3) _
                 + $CRLF + Ians(4)                      '* <- out of bounds!
      MsgBox sMessage
     Exit Function
     ErrorTrap:
       MsgBox "Error! " + STR$(ERR) +" "+ ERROR$
       ERR=0
       Resume Next                        ' continue execution at line after error
    End Function
    '------------------/PBMain
    #DEBUG ERROR option specifies whether the compiler should generate code that
    checks for array boundary and null-pointer errors wherever they may occur.
    The default setting is OFF.
    When #DEBUG ERROR mode is ON, any attempt to access an array outside of its
    boundaries, or attempting to use a null-pointer will generate a
    run-time Error 9 ("Subscript/Pointer out of range"),
    and the statement itself is not executed.
    Good luck
    Rgds, Dave

    Comment


    • #3
      Did you [RE]DIM Ians() BEFORE you built 'sMessage?'

      And, are you using #DEBUG ERROR ON?

      I will guarantee there is nothing wrong with the compiler for the code shown.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Woops MCM and I were posting at the same time!

        BTW either concatenation character '&' or '+' can be used as in my example.
        Rgds, Dave

        Comment


        • #5
          Thanks for your help - I think I have the arrays sorted enough fro my need but I will apply the techniques you suggest
          It may answer some questions if I post the complete code below.
          #COMPILE EXE
          #DIM ALL

          FUNCTION PBMAIN () AS LONG
          DIM sMessage AS STRING


          DIM words(1,2) AS LONG
          DIM iI AS INTEGER
          DIM lL AS LONG
          words(0,0) = 1
          words(0,1) = 2
          words(0,2) = 3
          REDIM PRESERVE WORDS(1,3)
          words(0,3) = 4
          MSGBOX STR$(Words(0,1))
          DO WHILE iI < 5
          Words(1,iI)=10 + iI
          iI=Ii+1
          LOOP
          lL=MSGBOX(STR$(Words(1,4)))

          REDIM Ians(5) AS STRING
          iI=0
          DO WHILE iI <= 5
          Ians(iI)=CHR$(64+iI)
          iI=Ii+1
          LOOP
          sMessage= Ians(0) & $CRLF & Ians(1) & $CRLF & Ians(2) & $CRLF & Ians(3) & $CRLF & Ians(4)
          MSGBOX sMessage
          'ARRAY SORT Ians(), DESCEND
          'Msgbox Ians(0) + $CRLF + Ians(1) + $CRLF +Ians(2) + $CRLF + Ians(3) + $CRLF + Ians(4)
          END FUNCTION

          Comment


          • #6
            Originally posted by Ian Bayly View Post
            Code:
            REDIM PRESERVE WORDS(1,[B]3[/B])[B] '<-- Dimmed to 3[/B]
            words(0,3) = 4
            MSGBOX STR$(Words(0,1))
            DO WHILE [B]iI < 5[/B]
            Words(1,iI)=10 + iI '[B]<-- When iI =  4 creates a BOUNDS ERROR[/B]
            =========================================
            "The man who goes alone can start today;
            but he who travels with another
            must wait till that other is ready."
            Henry David Thoreau (1817-1862)
            =========================================
            It's a pretty day. I hope you enjoy it.

            Gösta

            JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
            LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

            Comment


            • #7
              but I will apply the techniques you suggest...
              It may answer some questions if I post the complete code below.
              Missing from your program:
              Code:
              #DEBUG ERROR ON 
              .....
              
                ON ERROR GOTO ERRORTRAP
              ...
              ResumePoint: 
              
              ...
                  EXIT FUNCTION
              
              ERRORTRAP:
               MSGBOX USING$ ("Oops_! Error # &", ERR, ERROR$(ERR)), %MB_ICONHAND, "Programmer Error" 
               RESUME ResumePoint
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                I'll give you credit for using ...
                Code:
                #DIM ALL
                .. everyone should acquire this habit.

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

                Comment


                • #9
                  It should be pointed out that there is no error because of the use of $CRLF as the thread topic suggests.

                  Rod
                  Rod
                  In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                  Comment


                  • #10
                    I'd like a nickel for every 'error' posted here that wasn't.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Lighten up fellows, he did say newbie, we all had to learn and I thought this forum was about helping people learn the power of PB

                      Comment


                      • #12
                        >and I thought this forum was about helping people learn the power of PB

                        And I thought it was about helping people learn the power within themselves.
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Careless, careless careless!!
                          Thanks for all your time & tips

                          Comment


                          • #14
                            John

                            Lighten up fellows, he did say newbie, we all had to learn and I thought this forum was about helping people learn the power of PB
                            I posted that so that six months down the road when I(or anyone else) have forgotten about this thread and I create some code where it appears the $CRLF is causing problems and I do a search for a cure-all and end up in this thread, I'll know that I won't find the answer to my problem here, and I can move on to the next thread.

                            Rod
                            Rod
                            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                            Comment

                            Working...
                            X