1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. Fanuc Robot Forum
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

KAREL programming variables file

  • nerd484
  • September 28, 2017 at 8:29 PM
  • Thread is Resolved
  • nerd484
    Trophies
    3
    Posts
    21
    • September 28, 2017 at 8:29 PM
    • #1

    I am rather new to KAREL and I was advised by fanuc that a good approach to a more complex karel program is to split the program into separate files. One file is the main program with references to the other project files, one program for routines & functions, and one program for variables. The issue I am having is when I try to create a new karel program for just the variable declaration. When I try to compile a program file with only variable declarations I get a compilation error stating that the program must have a begin statement. If add in a begin statement with no code or just simple variable initializations, it will compile ok; but, when I reference the variable program from another project file with %include K_variables, I get an error that says there is an error with the VAR command in the variable file and that an ID is expected. Should I even be compiling the program for variable declaration? What is the proper way to create and reference a file for just variables?

    My variable file is something like:
    Program K_Vars
    VAR
    int1:INTEGER
    int2:INTEGER
    END K_Vars

    The main program would look like this:
    Program k_Main
    %INCLUDE K_Vars
    Begin
    do stuff here...
    if(int1 = 0) THEN
    do more stuff...
    ENDIF
    END K_Main

  • DPKG
    Reactions Received
    3
    Trophies
    3
    Posts
    18
    • September 28, 2017 at 8:52 PM
    • #2

    When you %INCLUDE something, the contents of the included file will be merged with the main file, replacing the %INCLUDE directive.

    Your K_Vars.kl should become:

    Code
    VAR
     int1:INTEGER
     int2:INTEGER

    Then your k_Main.kl will compile correctly.

    Beware the %INCLUDE order and position, global variables declarations are on top, routines must be defined before beeing used and so on.

  • nerd484
    Trophies
    3
    Posts
    21
    • September 28, 2017 at 9:02 PM
    • #3

    Great! I got it now. Thanks for the help! :yesyesyes: :dance2: :bravo:

  • Tran21
    Trophies
    2
    Posts
    24
    • June 15, 2022 at 5:53 AM
    • #4

    Hello,

    I tried the codes above with no sucess, can someone please explain.

    PROGRAM k_Main

    %INCLUDE K_Vars

    BEGIN

    --do stuff here...

    IF(int1 = 0) THEN

    --do more stuff...

    ENDIF

    END K_Main


    File name K_Vars.kl as below:

    VAR

    int1:INTEGER

    int2:INTEGER


    Robogiude V9(Rev N)

    Errors after build all:

    Set Extra Includes

    pasted-from-clipboard.png

    \TestInclude\SubProgs\k_vars.kl(1)

    1 VAR "PROGRAM" expected

    1 VAR Id expected

    2 int1:INTEGER "BEGIN" expected.

    2 int1:INTEGER ";" or new line expected.

    2 int1:INTEGER Invalid statement or "ENDxxx" or "UNTIL" expected.

    3 int2:INTEGER Invalid statement. ";" or new line expected.

    3 int2:INTEGER Invalid statement. ";" or new line expected

  • Tran21
    Trophies
    2
    Posts
    24
    • June 15, 2022 at 2:26 PM
    • #5

    Correction.

    %INCLUDE SUBPROGS\K_Vars

    pasted-from-clipboard.png

    Still having same errors after build all

  • Tran21
    Trophies
    2
    Posts
    24
    • June 15, 2022 at 2:36 PM
    • #6

    Summary: All files built successfully as settings below.

    pasted-from-clipboard.png

    Same errors if K_Vars.kl is checked along with k_main.kl.

    Which is correct?

  • Tran21
    Trophies
    2
    Posts
    24
    • June 15, 2022 at 2:43 PM
    • #7

    Ran k_Main,kl and got:

    (K_Main,5) Uninitialized data.

  • hermann
    Reactions Received
    407
    Trophies
    9
    Posts
    2,615
    • June 15, 2022 at 9:36 PM
    • #8
    Quote from Tran21

    --do stuff here...

    Here is the problem, but nobody can tell you what exact, because we don't know what stuff is done. :winking_face:

  • Tran21
    Trophies
    2
    Posts
    24
    • June 15, 2022 at 10:57 PM
    • #9

    Okay, thanks very much.

  • Tran21
    Trophies
    2
    Posts
    24
    • June 16, 2022 at 6:14 PM
    • #10

    Hermann,

    My apology, I found my problems.

    In general, the sequence of creating and building Karel using %INCLUDE files in robogiude confused me.

    After trials and errors, learning the software, I got my codes working.

    Thanks.

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download