# LoadError: UndefVarError: @defVar not defined

**URL:** <https://discourse.julialang.org/t/loaderror-undefvarerror-defvar-not-defined/66022>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [August 8, 2021, 3:24pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-defvar-not-defined/66022 "2021-08-08T15:24:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangsanle](https://avatars.discourse-cdn.com/v4/letter/z/e274bd/32.png) [@zhangsanle](https://discourse.julialang.org/u/zhangsanle)\
**Post date:** [August 8, 2021, 3:24pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-defvar-not-defined/66022/1 "2021-08-08T15:24:46Z")

</div>

I have a piece of code about JuMP. When I run it ,it says that LoadError: UndefVarError: @defVar not defined. I have tried using global forward or backward but both fails.

See:

```julia
function T1(w_func,grid_b,β,u,z)
            # objective for each grid point
                for j in 1:cp.Nb
                b = grid_b[j]
                choice1 = Model(solver=GLPKSolverLP()) 
                @defVar (choice1, a >= 0)
                @setObjective(choice1, Max, u(a) + cp.β * (w_func.((b*(1+cp.r)+cp.w-a) .* cp.z[i])))
                results1 = solve(choice1)
                Tw1 = getObjectiveValue(choice1)
                c_choice1 = getValue(x)
                return Tw, σ
                end
            end      

LoadError: UndefVarError: @defVar not defined
in expression starting at In[44]:37

Stacktrace:
 [1] top-level scope
   @ :0
 [2] eval
   @ ./boot.jl:360 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1094

thanks

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [August 8, 2021, 4:55pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-defvar-not-defined/66022/2 "2021-08-08T16:55:23Z")

</div>

First of all, welcome to our community! 🎊

From where `@defVar` comes? `JuMP` uses `@variable` to define variables, not `@defVar`. Is this code wrote in a very old version of `JuMP`?

> I have tried using global forward or backward but both fails.

I have no idea of what you mean by this.

---

<div class="post-metadata">

**Author:** ![zhangsanle](https://avatars.discourse-cdn.com/v4/letter/z/e274bd/32.png) [@zhangsanle](https://discourse.julialang.org/u/zhangsanle)\
**Post date:** [August 9, 2021, 6:21am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-defvar-not-defined/66022/3 "2021-08-09T06:21:53Z")

</div>

Thank you very much. I did use the old version of the jump command.Thanks again

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [August 9, 2021, 7:22am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-defvar-not-defined/66022/4 "2021-08-09T07:22:45Z")

</div>

I haven’t seen `@defVar` in years! Where did you get the old code from? We’ve tried to excise old tutorials and documentation from the internet.

---

<div class="post-metadata">

**Author:** ![zhangsanle](https://avatars.discourse-cdn.com/v4/letter/z/e274bd/32.png) [@zhangsanle](https://discourse.julialang.org/u/zhangsanle)\
**Post date:** [August 9, 2021, 10:50am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-defvar-not-defined/66022/5 "2021-08-09T10:50:21Z")

</div>

That’s great! I get the old code from: [JuliaOpt - Optimization packages for the Julia language](https://www.juliaopt.org/notebooks/Shuvomoy%20-%20Getting%20started%20with%20JuMP.html)  
Thank you for your work
