Reading a Value from a .txt file and display in operator comment

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

  • Reading a Value from a .txt file and display in operator comment

    Having some trouble figuring this out. I have a .txt file with a number 1-9 in it and I want PcDmis to read the file, read the number and use it an an assignment V2. If the number is greater than 5 go to a operator comment and if its not true, go to another operator comment.

    The code works but my if_goto isn't working. Also when I highlight over the variables, my cursor shows 0 (zero). So if the value is 6 it should say display the true operator comment and if its 4 it should display the not true operator comment but it always says true even though the number is less than 5.

    Code:
                ASSIGN/DATA1="C:\USERS\RENEGADE PRECISION\DESKTOP\TEST REPORTS\TEST.TXT"
    FPTR       =FILE/OPEN,DATA1,READ
    V1         =FILE/READ_BLOCK,FPTR,2
                FILE/CLOSE,FPTR,KEEP
                ASSIGN/V2=V1
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                "value is "+V2[COLOR=#0000FF]<------op comment pops up with the correct value in the .txt file. I enter the value and save it manually in the file so this part works.[/COLOR]
                IF_GOTO/V2>5,GOTO = TRUE
    TRUE       =LABEL/
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                true
                GOTO/END
    NOT_TRUE   =LABEL/
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                not true
    END        =LABEL/

  • #2
    Code-->

    I would do this
    Code:
    ASSIGN/V2=V1
                ASSIGN/V1=C1.INPUT
                IF/V1>=5
                  GOTO/TRUE
                END_IF/
                ELSE/
                  GOTO/NOT_TRUE
                END_ELSE/
    TRUE       =LABEL/
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                It is true!
    NOT_TRUE   =LABEL/
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                It is NOT true!
    Hghlighting and seeing variable-->
    Is usually incorrect. Execute the program and type your number and run it offline to troubleshoot
    Last edited by DAN_M; 01-07-2020, 11:45 AM.

    Comment


    • #3
      DAN_M , yes your code works but I need the input to come from a .txt file. txt file contains any number between 1-9

      Comment


      • #4
        It's probably seeing V2 as a string and not a number, perhaps if there's a space or something or a second empty line in the text file.

        Try
        ASSIGN/V2=INT(V1)
        Applications Engineer
        Hexagon UK

        Comment


        • #5
          NinjaBadger , that worked. Thanks for the help.

          Comment


          • #6
            I would try this, depends on how the file is written, maybe with NinjaBadger solution in addition :
            Code:
            FPTR       =FILE/OPEN,C:\USERS\RENEGADE PRECISION\DESKTOP\TEST REPORTS\TEST.TXT,READ
            V1         =FILE/READLINE,FPTR,{V2}
                        FILE/CLOSE,FPTR,KEEP
                        IF_GOTO/V2<6,GOTO = NOT_TRUE
            TRUE       =LABEL/
                        COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                        true
                        GOTO/END
            NOT_TRUE   =LABEL/
                        COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                        not true
            END        =LABEL/

            Comment

            Related Topics

            Collapse

            Working...
            X