Announcement

Collapse
No announcement yet.

GRAPHIC PRINT , prnts numbers not just strings ?

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

  • GRAPHIC PRINT , prnts numbers not just strings ?

    Trying to figure out why a large test program that I am testing gives error when printing a number with GRAPHICS PRINT. It does work one time when I have only nn1(I) but when I do something like nn21(I)=nn1(I) and then print nn1(2) then get error? Those are numbers not strings.

    Have not yet been able to duplicate that error in this small sample code, but this sample code does not have any problem printing numbers.

    Will continue to try to duplicate error in this sample code.

    Code:
    #COMPILE EXE
    #DIM ALL
    #DEBUG DISPLAY ON
    
    GLOBAL TEST1(), TEST2() , gWIN AS LONG
    
    FUNCTION PBMAIN () AS LONG
    LOCAL fnt, i AS LONG
    DIM TEST1(2), TEST2(2) AS LONG
    
    FONT NEW "Arial", 12, 1 TO fnt
    
    GRAPHIC WINDOW NEW "", 100,100,500,500 TO gWin
    GRAPHIC SET FONT fnt
    
    TEST1(1) = 400
    TEST2(1) = TEST1(1)-50
    
    GRAPHIC PRINT
    
    GRAPHIC PRINT POS(10) TEST1(1)
    GRAPHIC PRINT POS(10) TEST2(1)
    GRAPHIC PRINT POS(10) 100
    
    GRAPHIC WAITKEY$
    GRAPHIC WINDOW END
    
    END FUNCTION
    Robert

  • #2
    What error are you getting?
    Rod
    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

    Comment


    • #3
      Well at one time I was getting error. Now when I ran the program it starts to display graphic and it exits the program without an error message.

      That is one thing that I am puzzled in the graphic test program. When arrays are not done right in the graphic program it just exits the program without an error message. Look for problem and it is just something that I forgot with the array. Fix it and it works.
      Robert

      Comment


      • #4
        What you describe, is very often arrays out of bound behavior,
        Double check your arrays DIM/REDIM and your loops to make sure you are not out of bound.
        are you using zero based array or one based, when you loop are you looping 0 based of 1 based.
        Make sure you use during testing
        #DEBUG DISPLAY ON
        #DEBUG ERROR ON




        Comment


        • #5
          got the sample test program updated trying to duplicate original error and getting an error in this sample program that I have not seen before.

          ******
          untrapped error #9 (subscript/pointr out of range)
          has occurred following execution of CHART1

          press ok to continue, cancel to terminate
          ******

          Code:
          #COMPILE EXE
          #DIM ALL
          #DEBUG DISPLAY ON
          #INCLUDE "WIN32API.INC"
          
          GLOBAL TEST1(), TEST2() , hDlg AS LONG
          
          CALLBACK FUNCTION CHARTDATA() AS LONG
          DIM TEST1(5) AS LONG: DIM TEST2(5) AS LONG
          
          TEST1(1) = 400
          TEST2(1) = TEST1(1)-50
          
          CONTROL SEND hDlg, 100, %BM_CLICK, 0, 0
          END FUNCTION
          
          CALLBACK FUNCTION CHART1() AS LONG
          LOCAL fnt, i AS LONG
          
          GRAPHIC ATTACH hDlg, 200
          GRAPHIC CLEAR
          FONT NEW "Arial", 12, 1 TO fnt
          GRAPHIC SET FONT fnt
          
          GRAPHIC PRINT
          
          GRAPHIC PRINT POS(10) TEST1(1) '<--- get error here
          'GRAPHIC PRINT POS(10) TEST2(1)
          GRAPHIC PRINT POS(10) 100
          
          END FUNCTION
          
          
          FUNCTION PBMAIN () AS LONG
          DIALOG NEW PIXELS, 0, "Networth Graphic Chart 1",,,941,720, %WS_SYSMENU, 0 TO hDlg
          
          CONTROL ADD GRAPHIC, hDlg, 200,"" , 10,10,816,690, %WS_BORDER
          CONTROL ADD BUTTON , hDlg, 100,"&SET TEXT" , 836,20,80,26, CALL CHART1
          DIALOG SHOW MODAL hDlg
          END FUNCTION
          Robert

          Comment


          • #6
            even if you are using globals for TEST1(), TEST2() you are only DIMing them in the other callback function. "CALLBACK FUNCTION CHARTDATA()"
            So when Callback Chart1 gets called you still haven't DIMED the array so you are out of bound.

            Since you are using a Global why not Dim them in PBMain

            FUNCTION PBMAIN () AS LONG
            DIM TEST1(5) AS LONG: DIM TEST2(5) AS LONG
            DIALOG NEW PIXELS, 0, "Networth Graphic Chart 1",,,941,720, %WS_SYSMENU, 0 TO hDlg

            Comment


            • #7
              What Rod said plus -
              The other callback is never called because DIALOG SHOW line is incomplete. So DIMs are never called.

              If you DIALOG SHOW MODAL hDlg CALL CHARTDATA, then that code will run many times because the callbacks are not filtered with IF THENs or SELECT CASEs.

              Cheers,
              Dale

              Comment


              • #8
                As identified in another thead, it's not a good idea to DIm an array AS .... if it has previously been declared. It can confuse the compiler.
                WIth GLOBAL test1() as LONG,just keep it to

                Code:
                DIM test1(5): DIM test2(5).
                In fact it's a good idea to always use REDIM in this situation to avoid other potential problems.

                Comment


                • #9
                  ok put it on program
                  Robert

                  Comment


                  • #10
                    One sample for "fix up" '
                    Code:
                    #compile exe
                    #dim all
                    #debug display on
                    #include "WIN32API.INC"
                    
                    global TEST1(), TEST2() , hDlg as long
                    
                    callback function CHARTDATA() as long
                      if cb.msg = %wm_initdialog then
                        dim TEST1(5)
                        dim TEST2(5)
                    
                        TEST1(1) = 400
                        TEST2(1) = TEST1(1)-50
                    
                        graphic attach hDlg, 200 'move to here allows to "see" multiple clicks
                        graphic clear
                    
                      end if
                      'CONTROL SEND hDlg, 100, %BM_CLICK, 0, 0
                    end function
                    
                    callback function CHART1() as long
                      local fnt, i as long
                      if cb.ctlmsg = %bn_clicked then
                        font new "Arial", 12, 1 to fnt
                        graphic set font fnt
                    
                        graphic print
                    
                        graphic print pos(10) TEST1(1) '<--- get error here NOT NOW
                        'GRAPHIC PRINT POS(10) TEST2(1)
                        graphic print pos(10) 100
                        font end fnt
                      end if
                    end function
                    
                    function pbmain () as long
                      dialog new pixels, 0, "Networth Graphic Chart 1",,,941,720, %ws_sysmenu, 0 to hDlg
                    
                      control add graphic, hDlg, 200,"" , 10,10,816,690, %ws_border
                      control add button , hDlg, 100,"&SET TEXT" , 836,20,80,26, call CHART1
                      dialog show modal hDlg call CHARTDATA
                    end function '
                    Dale

                    Comment


                    • #11
                      When arrays are not done right in the graphic program it just exits the program without an error message
                      Based on rest of thread, that's the behavior you would expect. The program kept running after an error which may have corrupted anything. While the error you have shown (subscript out of range) will "usually" result in a GPF and whatever your system does under those conditions, it may simply corrupt the stack or even the instruction pointer.

                      Error checking of some kind - here #DEBUG ERROR ON suggested - is something you should develop as a habit.

                      From help...
                      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.
                      You might just want to reread thru the who help section under #DEBUG.

                      Regardless what the help says, I have used #DEBUG ERROR ON all the time, even in my production software UNLESS I HAD A SPECIFIC REASON TO LEAVE IT OFF. Works here!
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Found my answer about graphic print , printing numbers.

                        *****
                        EXPRLIST
                        NUMERIC and/or STRING expression(s) to be written to the graphic target. A semicolon can be used as separator between multiple expressions in the same statement. Upon completion, the POS is moved to the left margin of the next line.
                        *****

                        As to my bug in my test program found a tmp array not dim.
                        Still have other bugs to debug but this get me going. Was on hold when program was exiting.

                        Thank everyone for your help and comments.
                        Robert

                        Comment

                        Working...
                        X