LB Booster
Programming >> Liberty BASIC language >> Display calculated value
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1430325489

Display calculated value
Post by RNBW on Apr 29th, 2015, 4:38pm

The program I am developing calculates bending moments and shear forces at points along the length of a beam. The user inputs data (loading, area of loading, its position on the beam and the length of the load). The Total Load is then calculated and is printed in the last column (column 9) of the table.

I have carried out checks and all of the user input is being accepted and I am printing them out as a check on the main window and in the texteditor on the form, but for the life of me I can't get the Total Load to be displayed in column 9. It always displays as 0.00.

I've been looking at this for hours trying to sort it and now I think I am brain dead! Can anyone help with a solution. This is P Code:
 
art 1, Part 2 will follow and will have to be pasted to Part 1

Code:
INPUT "Number of loads on the beam (1 to 8): "; NumLoads

INPUT "SPAN OF BEAM (metres): ";span

PRINT
PRINT "ENTER NUMBER OF SECTIONS ALONG THE BEAM TO BE USED:"
PRINT "MOST PROGRAMS LIMIT THE NUMBER OF SECTIONS TO 21, BUT ON LARGER"
PRINT "SPANS THIS CAN BE INACCURATE.  THERE ARE SIMPLE RULES TO DECIDE:"
PRINT "NUMBER OF SECTIONS MUST ALWAYS BE AN ODD NUMBER.  THE (NUMBER - 1) MUST"
PRINT "ALSO BE DIVIDABLE BY 10 (eg. 21, 51, 101, 201, 301, 401, 501, etc"
PRINT
INPUT "NUMBER OF SECTIONS: "; NumOfSect
StepNo = (NoOfSect-1)/10   


'DIM v$(NoOfSect+1), m$(NoOfSect+1), s(NoOfSect+1), d$(NoOfSect+1)
'DIM SFatSect(NoOfSect+1), mSect(NoOfSect+1), DefSect(NoOfSect+1), Dist(NoOfSect+1)

'Dist(1) = 0
'Dist(NoOfSect) = Span
'LoadType = 0
DIM DorI$(NumLoads+1), WC(NumLoads+1), WD(NumLoads+1), LoadDescrip$(NumLoads+1)
DIM ld(NumLoads+1), wi(NumLoads+1), Cover(NumLoads+1), LoadType(NumLoads+1)


'NOMAINWIN     

[WindowSetup]
WindowWidth = 1032 : WindowHeight = 650
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)

childWide=1400 : childHigh=1000 'child window dimensions


OPEN "SIMPLE BEAM ANALYSIS" FOR WINDOW AS #main

PRINT #main, "trapclose [quit]"
PRINT #main, "resizehandler [resize]"

    hMain = hwnd(#main) 'main window handle

    CALLDLL #user32, "GetWindowLongA",_
        hMain AS ULONG,_         'handle of window
        _GWl_HINSTANCE AS LONG,_ 'flag for instance handle
        hInstance AS ULONG       'returns instance handle of window

    dwStyle=_WS_CLIPCHILDREN OR _WS_CHILD OR _WS_VISIBLE OR _
        _WS_BORDER or _WS_VSCROLL OR _WS_HSCROLL

    'create an MDI Client Control
    CALLDLL #user32, "CreateWindowExA",_
        0 AS LONG,_             'extended class style
        "MDICLIENT" AS PTR,_    'class name
        "" AS PTR,_             'title or string
        dwStyle AS LONG,_       'window style
        2 AS LONG,_             'x org
        2 AS LONG,_             'y org
        1021 AS LONG,_           'width
        602 AS LONG,_           'height
        hMain AS ULONG,_        'parent window
        0 AS ULONG,_            'handle to menu = 0 for class menu
        hInstance AS ULONG,_    'instance handle of parent window
        "" AS PTR,_             'always NULL
        hMDI AS ULONG           'returns handle of MDI Client


vpos = 10: sp = 20: TopOfTable = vpos+sp*15: colWide = 65
BMSF = TopOfTable + ((NumLoads+1)*sp) + sp

MENU #m, "&File" , "E&xit", [quit]
WindowWidth=childWide: WindowHeight=childHigh


[ControlSetup]
TextboxColor$ = "White"
STYLEBITS   #m.textbox5, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX     #m.textbox5, 10+150+10, vpos-10+sp*14, 70, 20  
STYLEBITS   #m.textbox6, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX     #m.textbox6, 10+150+10+70+200, vpos-10+sp*14, 70, 20  
STYLEBITS   #m.textbox7, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX     #m.textbox7, 10+150+10+70+20+250+40+200, vpos-10+sp*14, 70, 20
STYLEBITS   #m.textbox8, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX     #m.textbox8, 330, 100, 70, 20


FOR row = 1 TO 1
  FOR col = 1 TO 9
    TextboxColor$ = "255 135 0"
    SELECT CASE col
      CASE 1: xpos = 10 : width = 65
      CASE 2: xpos = 75 : width = 380
      CASE 3,4,5,6,7,8: xpos = col*65+(455-65*3) : width = 65
      CASE 9: xpos = (10+65+380)+(col-3)*65 : width = 75
    END SELECT

    SELECT CASE col
        CASE 1, 3, 4, 5, 6, 7, 8, 9
            STYLEBITS #m.top, _ES_CENTER OR _ES_READONLY, _WS_BORDER, 0, 0
        CASE 2
            STYLEBITS #m.top, _ES_LEFT OR _ES_READONLY, _WS_BORDER, 0, 0
    END SELECT
    TEXTBOX #m.top, xpos, TopOfTable, width, 20
    MAPHANDLE #m.top, "#m.top";row;col
  NEXT col
NEXT row



FOR row = 1 TO NumLoads
  FOR col = 1 TO 9
    TextboxColor$ = "white"
    SELECT CASE col
      CASE 1: xpos = 10 : width = 65    
              TextboxColor$ = "255 135 0"
      CASE 2: xpos = 75 : width = 380   
      CASE 3,4,5,6,7,8: xpos = col*65+(455-65*3) : width = 65 
      CASE 9: xpos = (10+65+380)+(col-3)*65 : width = 75   
    END SELECT

    SELECT CASE col
        CASE 1, 3, 4:  STYLEBITS #m.tb, _ES_CENTER, _WS_BORDER OR _ES_AUTOHSCROLL OR _ES_AUTOVSCROLL, 0, 0
        CASE 2:  STYLEBITS #m.tb, _ES_LEFT, _WS_BORDER OR _ES_AUTOHSCROLL OR _ES_AUTOVSCROLL, 0, 0
        CASE 5, 6, 7, 8, 9:   STYLEBITS #m.tb, _ES_RIGHT, _WS_BORDER, 0, 0
    END SELECT

    TEXTBOX #m.tb, xpos, TopOfTable + row*20, width, 20
    MAPHANDLE #m.tb, "#m.tb";row;col
  NEXT col
NEXT row


posBelow = TopOfTable + (9-1)*sp + sp + 15
STATICTEXT  #m.lbl1 "BENDING MOMENTS and SHEAR FORCES", 10, BMSF, 300, 20
STATICTEXT  #m.lbl2 "BM (KNm)               SF (KN)", 50, BMSF+sp, 140, 20
STATICTEXT  #m.lbl3 "PRESS CALC TO FORMAT DATA ENTRY AND CALCULATE", 350, BMSF+sp, 300, 20
STATICTEXT  #m.lbl4 "BENDING MOMENTS and SHEAR FORCES", 350, BMSF+sp*2, 300, 20
STATICTEXT  #m.lbl5 "OUTPUT RESULTS TO PRINTER", 350, BMSF+sp*4, 300, 20
TEXTEDITOR  #m.txtEd1 10, BMSF+sp*2, 300, 300
BUTTON      #m.btn1, "CALC", [calc], UL, 680, BMSF+sp, 75, 20
BUTTON      #m.btn2, "PRINT", [PrintToPrinter], UL, 680, BMSF+sp*4, 75, 20



'  OPEN CHILD WINDOW 
OPEN "" FOR WINDOW_POPUP AS #m
BackgroundColor$ = "cyan"
PRINT #m, "trapclose [quit]"

    hChild = hwnd(#m) 'handle of popup window

    CALLDLL #user32, "SetParent",_
        hChild AS ULONG,_    'make popup the child
        hMDI AS ULONG,_      'make MDI the parent
        result AS LONG

    'use MoveWindow to force window resize
    'so scrollbars will show
    CALLDLL #user32, "MoveWindow",hMain AS ULONG,_
         11 AS LONG, 11 AS LONG,_
         1015 AS LONG, 633 AS LONG,_
         1 AS BOOLEAN, r AS BOOLEAN

'-------------

' Enter headings in header row
#m.top11, "Load No."
#m.top12, "Description"
#m.top13, "DL or LL"
#m.top14, "Type"
#m.top15, "W/Ldg"
#m.top16, "W or H"
#m.top17, "A"
#m.top18, "C"
#m.top19, "TOTAL LOAD"


for row = 1 to NumLoads+1
  h$ = "#m.tb";row;"1"
  #h$ "Load ";row
next row

#m.textbox5, (USING("###.###", span))
#m.textbox6, NumLoads
#m.textbox7, NumOfSect

WAIT

'-------------



[calc]

'Extract the data typed into table
FOR row = 1 TO NumLoads
   'Load description column
   h2$ = "#m.tb";row;2
   #h2$ "!contents? amt$"
   LoadDescrip$(row) = amt$
   #m.txtEd1, LoadDescrip$(row)

   'Dead or Live Load column
   h3$ = "#m.tb";row;3
   #h3$ "!contents? amt$"
   DorI$(row) = amt$
   #m.txtEd1, DorI$(row)

   'Load type column (PL,UDL,TPR)
   h4$ = "#m.tb";row;4
   #h4$ "!contents? amt$"
   LoadType$(row) = amt$
   #m.txtEd1, LoadType$(row)
NEXT

' Set up formatting and numeric check for cols 5 to 8
FOR row = 1 TO NumLoads
   FOR col = 5 TO 9
      h1$ = "#m.tb";row;col
      #h1$ "!contents? amt$"
      GOSUB [DoFormatCheck]
   NEXT col
      
      ' LOAD or Loading
      h5$ = "m.tb"; row;col
      #h5$ "!contents? amt$"
      GOSUB [DoFormatCheck]
      ld(row) = num(row,5)
      #m.txtEd1, (USING("###.##", num(row,5)))
    
      'Height of wall or width of loaded area
      h6$ = "m.tb"; row;col
      #h6$ "!contents? amt$"
      wi(row) = num(row,6)
      GOSUB [DoFormatCheck]
      #m.txtEd1, (USING("###.##", num(row,6)))

      'Starting point of load measured
      'from left support
      h7$ = "m.tb"; row;col
      #h7$ "!contents? amt$"
      GOSUB [DoFormatCheck]
      StartTo(row) = num(row,7)
      #m.txtEd1, (USING("###.##", num(row,7)))

      'Length of load
      h8$ = "m.tb"; row;col
      #h8$ "!contents? amt$"
      GOSUB [DoFormatCheck]
      Cover(row) = num(row,8)
      #m.txtEd1, (USING("###.##", num(row,8)))
NEXT

FOR row = 1 TO NumLoads
   For col = 9 TO 9
      'Filter loading conditions by types of load
      SELECT CASE LoadType$(row)
         CASE "PL"
            WC(row) = ld(row)
			PRINT "ld(row) = ";ld(row)
         CASE "UDL"
            WC(row) = ld(row) * wi(row) * Cover(row)
			PRINT "ld(row) = ";ld(row); " "; "wi(row) = ";wi(row); " "; "Cover(row) = ";Cover(row)
         CASE "TPR L"
            WC(row) = ld(row) * wi(row) * Cover(row)/2
			PRINT "ld(row) = ";ld(row); " "; "wi(row) = ";wi(row); " "; "Cover(row) = ";Cover(row)
         CASE "TPR R"
            WC(row) = ld(row) * wi(row) * Cover(row)/2
			PRINT "ld(row) = ";ld(row); " "; "wi(row) = ";wi(row); " "; "Cover(row) = ";Cover(row)
      END SELECT
      
      PRINT "WC(row) = ";WC(row)  ' TEMPORARY CHECK CODE
      
      h9$ = "m.tb"; row; col
      WC = WC(row)
      PRINT WC       ' TEMPORARY CHECK CODE

      #h9$, WC 

#m.txtEd1, (USING("###.##", WC(row))) 'this comes out correct so variables are working.

   NEXT col
NEXT row


WAIT

[PrintToPrinter]

DUMP

' TEMPORARY WAIT - TO BE DELETED
WAIT

GOSUB [CalcSFBM]   


WAIT

[resize]
    newWide = WindowWidth - 4
    newHigh = WindowHeight - 4
    ret = MoveWindow(hMDI, 2, 2, newWide, newHigh)
    ret = MoveWindow(hChild, 0, 0, childWide, childHigh)
    WAIT

WAIT

[quit]
CLOSE #m
END

 

Re: Display calculated value
Post by RNBW on Apr 29th, 2015, 4:41pm

Part 2 of the code: Functions and subroutines:

Code:


' FUNCTIONS AND SUBROUTINES


FUNCTION MoveWindow(hWnd,x,y,wide,high)
    CALLDLL #user32, "MoveWindow",_
        hWnd AS ULONG,_         'handle
        x AS LONG, y AS LONG,_  'x,y pos
        wide AS LONG,_          'width
        high AS LONG,_          'height
        1 AS LONG,_             'repaint flag
        MoveWindow AS LONG
    END FUNCTION

' Function courtesy of RobM LB Conforums
FUNCTION GetContent$(row,column)
    handle=VAL(WORD$(TbHandles$(row),column))
    CALLDLL #user32, "GetWindowTextLengthA",_
      handle AS ULONG,_    'handle of control
      numChars AS LONG     'number of characters
    GetContent$=SPACE$(numChars)+CHR$(0)
    lenEntry= LEN(GetContent$)
    CALLDLL #user32, "GetWindowTextA",_
      handle AS ULONG,_
      GetContent$ AS PTR,_
      lenEntry AS LONG,_
      ret AS LONG
    GetContent$=TRIM$(GetContent$)
END FUNCTION


'Number check
FUNCTION NumberOnly(in$)                            '
[Start]
FOR i = 1 TO LEN(in$)
    t$ = MID$(in$, i, 1)
    SELECT CASE
                
        CASE ASC(t$) = 46 OR (ASC(t$) > 47) AND (ASC(t$) < 58)
                
        CASE ASC(t$) = 45 AND i = 1
                
        CASE ELSE
            in$ = LEFT$(in$, i - 1) + RIGHT$(in$, LEN(in$) - i)
            GOTO [Start]
    END SELECT
NEXT
NumberOnly = VAL(in$)
END FUNCTION
'-----------------------------------------------

[DoFormatCheck]
   
   amt = NumberOnly(amt$)      ' Make the conversion

   num(row,col) = amt          

   #h1$, (USING("###.##", num(row,col)))       

RETURN


REM ***SUBROUTINE TO CALCULATE SHEAR FORCES AND MOMENTS

[CalcSFBM]

RETURN
                    
 



Sorry I've had to do the code in two bits and I've also had to remove most of the comments. If anyone has any queries as to what bits of the code do, I'm happy to oblige with clarification.
Re: Display calculated value
Post by Richard Russell on Apr 29th, 2015, 4:55pm

on Apr 29th, 2015, 4:38pm, RNBW wrote:
I've been looking at this for hours trying to sort it and now I think I am brain dead! Can anyone help with a solution.

On a very quick glance, I would worry about the fact that some of these statements include the '#' in the string (which they should) but some don't:

Code:
   h2$ = "#m.tb";row;2
   h3$ = "#m.tb";row;3
   h4$ = "#m.tb";row;4
      h1$ = "#m.tb";row;col
      h5$ = "m.tb"; row;col
      h6$ = "m.tb"; row;col
      h7$ = "m.tb"; row;col
      h8$ = "m.tb"; row;col
      h9$ = "m.tb"; row;col 

I would expect that h1$ to h4$ would work, but that h5$ to h9$ (which are missing the #) would not work. Does that explain what you are seeing?

This is another example where adding more checking at run-time would help in debugging, but would slow down execution slightly. As I've said before, it's a difficult call, but I'll make a note that maybe checking for the # would be worthwhile.

Richard.

Re: Display calculated value
Post by RNBW on Apr 29th, 2015, 5:36pm

Richard

Thank you for commenting so quickly and with the solution! It's amazing how you can look at something and not see the obvious.

Everything worked except for h9$, where I'd missed out the # from "#m.tb". It now works.

Thank you very much. I can get on with the rest of the program.

Ray