# Unable to run or debug when using VSCode

**URL:** https://discourse.julialang.org/t/unable-to-run-or-debug-when-using-vscode/127325
**Category:** New to Julia
**Tags:** vscode
**Created:** [March 24, 2025, 11:31pm UTC](https://discourse.julialang.org/t/unable-to-run-or-debug-when-using-vscode/127325 "2025-03-24T23:31:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ThermionicsGuy](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@ThermionicsGuy](https://discourse.julialang.org/u/ThermionicsGuy)
#### Post date: [March 24, 2025, 11:31pm UTC](https://discourse.julialang.org/t/unable-to-run-or-debug-when-using-vscode/127325/1 "2025-03-24T23:31:38Z")

</div>

Using:  
Windows 11  
Julia 1.11.4  
Visual Studio Code 1.98.2  
julialang extension 1.127.2

I get an error message whenever I try to run any code from VSCode if it contains a user-defined function. Here’s an example I threw together:

````julia
println(x1,x2)

function quadratic_formula(a, b, c)
	discrim = b^2 - 4.0*a*c
	if discrim >= 0.0
		x1 = (-b + sqrt(discrim))/(2.0*a)
		x2 = (-b - sqrt(discrim))/(2.0*a)
	else
		return nothing
	end
	return (x1, x2)
end```

Using CTRL-F5 gives this error message:

ERROR: LoadError: UndefVarError: `quadratic_formula` not defined in `Main`
Stacktrace:
 [1] top-level scope
   @ c:\Users\xxxxx\OneDrive\Documents\xxxxx\Examples\quadratic.jl:1
 [2] include(fname::String)
   @ Main .\sysimg.jl:38
 [3] run(debug_session::VSCodeDebugger.DebugAdapter.DebugSession, error_handler::VSCodeDebugger.var"#3#4"{String})
   @ VSCodeDebugger.DebugAdapter c:\Users\xxxxx\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\DebugAdapter\src\packagedef.jl:122
 [4] startdebugger()
   @ VSCodeDebugger c:\Users\xxxxx\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeDebugger\src\VSCodeDebugger.jl:45
 [5] top-level scope
   @ c:\Users\xxxxx\.vscode\extensions\julialang.language-julia-1.127.2\scripts\debugger\run_debugger.jl:12
 [6] include(mod::Module, _path::String)
   @ Base .\Base.jl:557
 [7] exec_options(opts::Base.JLOptions)
   @ Base .\client.jl:323
 [8] _start()
   @ Base .\client.jl:531
in expression starting at c:\Users\xxxxx\OneDrive\Documents\xxxxx\Examples\quadratic.jl:1

Using F5 gives this message:

Exception has occurred: UndefVarError
UndefVarError: `quadratic_formula` not defined in `Main`

Stacktrace:
 [1] top-level scope
   @ c:\Users\jbmcv\OneDrive\Documents\MasterPC\Examples\quadratic.jl:1

I'm able to evaluate the quadratic_formula function by putting my cursor on the final line and executing "Shift Enter", but this doesn't fix the issue. I've searched the available resources and can't find anything that seems helpful. I'm in the process of porting an old Fortran 77 code of mine and will need to be able to run it in the debugger. Any help would be appreciated!
````

---

<div class="post-metadata">

### Author: ![Boris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/boris/32/3306_2.png) [@Boris](https://discourse.julialang.org/u/Boris)
#### Post date: [March 25, 2025, 7:27am UTC](https://discourse.julialang.org/t/unable-to-run-or-debug-when-using-vscode/127325/2 "2025-03-25T07:27:18Z")

</div>

The message “xxx is not defined in Main” means that Julia does not see the function.

You need to compile it first. You didn’t provide a full Minimal working example (MWE) with your full code but try the following:

- Put the function in a file, e.g. myfuncs.jl
- in another file, write `include("myfuncs.jl")`. Depending on where you put the file you might need to add the path, e.g. If it is in a subfolder “functions” it should be `include("functions/myfuncs.jl")`
- Evaluate it/Send it to the REPL. You should see first a round arrow while julia compiles the function. If there is no error in your function you will see a tick mark on vs code on the line

Now julia should sees the function and you can call it.

This workflow is a bit dependent on how exactly you use VS code.

Consider using Revise if you want to change the function, then you use `includet()` instead of `include()`

---

<div class="post-metadata">

### Author: ![ThermionicsGuy](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@ThermionicsGuy](https://discourse.julialang.org/u/ThermionicsGuy)
#### Post date: [March 25, 2025, 5:01pm UTC](https://discourse.julialang.org/t/unable-to-run-or-debug-when-using-vscode/127325/3 "2025-03-25T17:01:51Z")

</div>

Boris, thank you so much for taking the time to respond to my issue. The fix turned out to be something very simple. I had been putting my calls to the Main function at the very beginning of my files. My previous experience has been primarily in Matlab, Fortran, and Basic, where that is a natural thing to do. Following the project structure suggested in:

> **[Julia programming notes](https://ufechner7.github.io/2022/08/16/julia-projects.html)**
>
> Introduction When you start to use Julia you might ask yourself: How shall I structure my code? There are different approaches for different use cases.

seems to enable the debugger to function properly in VSCode. Again, thank you for your time.
