# Converting well structure VBA code, with multiple sub-routine call, to Julia

**URL:** <https://discourse.julialang.org/t/converting-well-structure-vba-code-with-multiple-sub-routine-call-to-julia/50031>\
**Category:** New to Julia\
**Created:** [November 12, 2020, 8:00am UTC](https://discourse.julialang.org/t/converting-well-structure-vba-code-with-multiple-sub-routine-call-to-julia/50031 "2020-11-12T08:00:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter-Jolly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter-jolly/32/19371_2.png) [@Peter-Jolly](https://discourse.julialang.org/u/Peter-Jolly)\
**Post date:** [November 12, 2020, 8:00am UTC](https://discourse.julialang.org/t/converting-well-structure-vba-code-with-multiple-sub-routine-call-to-julia/50031/1 "2020-11-12T08:00:50Z")

</div>

I have been using Julia for about a week using Vscode as my IDE. Simple examples not problems. My task at hand it to convert well structure code (in VBA) to Julia - I am solving a system of 130 ODE’s (initial value problem) with the solution taking way too long in VBA. My VBA code uses 100’s of global parameters (Private a, b, c … as Single (or Double or String or Integer) that are used in multiple subroutines in the VBA. Very convenient method for sharing parameters and keeping code tightly contained in sub-routine structures without the need to pass great long strings of arguments. I am lost as how to do this in Julia - I haven’t been able to find anything on structuring Julia programs. Can anyone help? Peter

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [November 12, 2020, 9:05am UTC](https://discourse.julialang.org/t/converting-well-structure-vba-code-with-multiple-sub-routine-call-to-julia/50031/2 "2020-11-12T09:05:34Z")

</div>

Don’t use globals, they say… I’d wrap the parameters in a struct (or named tuple), you can then pass that as a single parameter to the functions. There are a bunch of helpers around to make things a bit easier. Have a look at `Base.@kwdef`, [https://github.com/mauro3/UnPack.jl](https://github.com/mauro3/UnPack.jl), and/or [https://github.com/mauro3/Parameters.jl](https://github.com/mauro3/Parameters.jl).

---

<div class="post-metadata">

**Author:** ![Huite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/huite/32/14034_2.png) [@Huite](https://discourse.julialang.org/u/Huite)\
**Post date:** [November 12, 2020, 9:13am UTC](https://discourse.julialang.org/t/converting-well-structure-vba-code-with-multiple-sub-routine-call-to-julia/50031/3 "2020-11-12T09:13:24Z")

</div>

Received wisdom is that global state is “evil” (googling it will give many entries). You mention it’s a well structured VBA code, but where’s the structure if there are hundreds of global parameters?

You probably want to define your own data structures, which is quite straightforward.

So instead of many arguments:

```julia
function f(a, b, c)
    return a + b + c
end

```

You can group it in a struct (or e.g. a namedtuple):

```julia
struct MyData
    a
    b
    c
end

function f(data)
    return data.a + data.b + data.c
end

```

The documentation can be found here:  
[https://docs.julialang.org/en/v1/manual/types/#Composite-Types](https://docs.julialang.org/en/v1/manual/types/#Composite-Types)

---

<div class="post-metadata">

**Author:** ![Peter-Jolly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter-jolly/32/19371_2.png) [@Peter-Jolly](https://discourse.julialang.org/u/Peter-Jolly)\
**Post date:** [November 12, 2020, 10:13am UTC](https://discourse.julialang.org/t/converting-well-structure-vba-code-with-multiple-sub-routine-call-to-julia/50031/4 "2020-11-12T10:13:07Z")

</div>

Hi,

Many thanks – that looks really interesting. I will investigate further. Yes, I was scared off by using Global

---

<div class="post-metadata">

**Author:** ![Peter-Jolly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter-jolly/32/19371_2.png) [@Peter-Jolly](https://discourse.julialang.org/u/Peter-Jolly)\
**Post date:** [November 12, 2020, 10:17am UTC](https://discourse.julialang.org/t/converting-well-structure-vba-code-with-multiple-sub-routine-call-to-julia/50031/5 "2020-11-12T10:17:18Z")

</div>

Thank you. I will take a look. Regards Peter Brisbane Australia
