Announcement

Collapse
No announcement yet.

Help to understand the code

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

  • Guilherme Calabria
    replied
    ...

    thank you for the tips Fred Buffington and the manual Simon Morgan
    I will check there...
    Michael Mattias did you see the full code at:
    http://guilherme.plotag.com.br/hpgl.bas

    the missing things will be a problem to convert the function HPGL to another language?

    Leave a comment:


  • Michael Mattias
    replied
    >check just before the do you will see where TMP is appended to command

    I added indents and found it. (also found code is prematurely truncated, it's missing at least an 'end if' and an 'end sub'). .

    BTW you CAN 'edit' your own posts to insert the code tags.

    MCM

    Leave a comment:


  • Ralph Bing
    replied
    you have to look at the full program

    check just before the do you will see where TMP is appended to command

    Leave a comment:


  • Michael Mattias
    replied
    After you look up the stuff in the manual, you will still have a problem because as written the LOCAL variable 'command' never has anything assigned to it... it's null.

    Leave a comment:


  • Simon Morgan
    replied
    Even if you don't have PowerBASIC, you can look up the commands and what they do in the on-line manual: PB/Win 9.01 manual

    Leave a comment:


  • Fred Buffington
    replied
    st$=LEFT$(Command,2)
    puts the first 2 characters as the variable st$ (i think you had tpi or something. so if command="PUT IT HERE" then ST$ would be PU after.



    command = REMOVE$(Command,"PU")
    This would remove the letters 'PU' from the command variable so,
    if COMMAND="PUT IT HERE" originally then it would be 'T IT HERE' after.


    BTW, code is much easier to read if you use
    {CODE}
    before the code
    and
    {/CODE} after
    (but use the square brackets instead of the squiggly brackets)

    You should be aware that COMMAND$ is a reserved word and is used to pass information from the command line. This may make the variable command illegal.
    Last edited by Fred Buffington; 27 Apr 2009, 06:01 PM.

    Leave a comment:


  • Guilherme Calabria
    started a topic Help to understand the code

    Help to understand the code

    Hi... I have the code bellow, and I need to understand it... I know this script read a file, a hpgl file, it is generates a vector map.
    I need to know what some things like 'tp1 = LEFT$(Command,2)' or 'command = REMOVE$(Command,"PU")'

    does... I understand C, Java, PHP, Pascal...
    thank you for every help!

    http://guilherme.plotag.com.br/hpgl.bas

    SUB HPGL (Hdlg AS DOUBLE,filename AS STRING)
    LOCAL MAXX AS LONG
    LOCAL MINX AS LONG
    LOCAL MAXY AS LONG
    LOCAL MINY AS LONG
    LOCAL MX AS LONG
    LOCAL MY AS LONG
    LOCAL I AS INTEGER,J AS INTEGER
    LOCAL FileLen AS LONG
    LOCAL tmp AS STRING
    LOCAL tp1 AS STRING
    LOCAL command AS STRING
    LOCAL Crd AS STRING
    LOCAL rot AS STRING 'rotation angle
    LOCAL sca AS LONG
    LOCAL CL AS LONG
    LOCAL CPX AS LONG
    LOCAL CPY AS LONG



    LOCAL pg()AS LONG 'array for page sizes
    DIM PG(20,1)
    COMBOBOX RESET hDlg, %IDC_COMBOBOX1
    COMBOBOX ADD hDlg, %IDC_COMBOBOX1, "0.025"
    COMBOBOX ADD hDlg, %IDC_COMBOBOX1, "0.0254"
    COMBOBOX SELECT hDlg, %IDC_COMBOBOX1, 1

    OPEN filename FOR BINARY AS #1
    FileLen = LOF(1)
    cl=0
    DO
    GET$ #1,1,tmp

    fileLen=fileLen-1
    IF filelen=0 THEN EXIT LOOP
    IF tmp=CHR$(&H0A) THEN tmp=""
    IF tmp=CHR$(&H0D) THEN tmp=""

    IF tmp = ";" THEN 'Command complete
    'parse command
    tp1 = LEFT$(Command,2)

    SELECT CASE tp1
    CASE "IN" 'Init
    Crd="A":Rot="0"
    CASE "PU" ' Pen up
    command = REMOVE$(Command,"PU")
    IF Crd = "A" THEN
    'ignore
    ELSE
    I = PARSECOUNT(command)
    FOR J=1 TO I STEP 2
    MX = VAL(PARSE$(command,J))
    MY = VAL(PARSE$(command,J+1))
    CPX=CPX+MX
    CPY=CPY+MY
    IF CPX > maxX THEN MaxX = CPX
    IF CPX < minX THEN MinX = CPX
    IF CPY > MaxY THEN MaxY = CPY
    IF CPY < MinY THEN MinY = CPY

    NEXT
    END IF
    CASE "PD" ' Pen Down
    command = REMOVE$(Command,"PD")
    IF Crd="A" THEN
    I = PARSECOUNT(command)
    FOR J=1 TO I STEP 2
    MX = VAL(PARSE$(command,J))
    MY = VAL(PARSE$(command,J+1))
    IF mx > maxX THEN MaxX = MX
    IF my > maxY THEN MaxY = MY
    IF MX < minX THEN MinX = MX
    IF MY < MinY THEN MinY = MY
    NEXT
    ELSEIF Crd="R" THEN
    I = PARSECOUNT(command)
    FOR J=1 TO I STEP 2
    MX = VAL(PARSE$(command,J))
    MY = VAL(PARSE$(command,J+1))
    CPX=CPX+MX
    CPY=CPY+MY
    IF CPX > maxX THEN MaxX = CPX
    IF CPX < minX THEN MinX = CPX
    IF CPY > MaxY THEN MaxY = CPY
    IF CPY < MinY THEN MinY = CPY

    NEXT


    END IF
    CASE "PA" ' Plot Absolute
    Crd="A"
    CASE "PR" ' Plot relative
    Crd="R"
    CASE "CI" 'circle command
    CASE "AA" ' Arc Absolute
    CASE "AR" ' Arc Relative
    CASE "SP" ' Select Pen
    CASE "SC" ' Scale factor
    command = REMOVE$(Command,"SC")
    sca = VAL(command)
    CASE "PG" 'page break
    'older plotters Zeros X and Y at and allows continious plotting
    'Save current length (Width is a plotter function - ignore)
    'add to any stored if required
    ' should work in both abs and rel cases
    MX=Maxx-minx
    pg(cl,0)= MX
    pg(CL,1)= MaxY-MinY
    cl=cl+1
    maxx=0
    minx=0
    maxY=0
    minY=0

    CASE "RO" 'rotation
    command = REMOVE$(Command,"RO")
    rot = command
    CASE ELSE
    'ignore anything else like retangles wedges etc.
    END SELECT

    command =""
    ELSE
    command=command + tmp
    END IF

    LOOP


    IF CL=0 THEN 'no pg command
    MX=(MaxX-MinX)' use calculated
    MY=(MaxY-MinY)
    ELSE
    mx=0
    my=0
    FOR I=0 TO CL

    MX=MX+pg(I,0)
    IF MY < PG(I,1) THEN MY=PG(I,1)
    NEXT
    'add any bits left
    mx=mx+(MaxX-MinX)
    IF MY < (MaxY-MinY) THEN MY=(MaxY-MinY)
Working...
X