# HELP! Using Shared Code between Desktop and Web

**URL:** <https://forum.xojo.com/t/help-using-shared-code-between-desktop-and-web/51206>\
**Category:** Web\
**Created:** [November 19, 2019, 2:29pm UTC](https://forum.xojo.com/t/help-using-shared-code-between-desktop-and-web/51206 "2019-11-19T14:29:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Albrecht](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_albrecht/32/817_2.png) [@Richard\_Albrecht](https://forum.xojo.com/u/Richard_Albrecht)\
**Post date:** [November 19, 2019, 2:29pm UTC](https://forum.xojo.com/t/help-using-shared-code-between-desktop-and-web/51206/1 "2019-11-19T14:29:53Z")

</div>

Hi,

I have shared (External) code and on the Desktop that I use on Web.

The desktop has a function:

MigrateAllUsers( lsAction as String, Prog as ProgressBar = Nil, lbl as Label = Nil)

The problem is ProgressBar is only in Desktop. This function is only used in Desktop App.

Is there a way to make this code Disappear if the external code is used in a web app? Like with a Compiler directive?

I hope this is clear.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [November 19, 2019, 2:33pm UTC](https://forum.xojo.com/t/help-using-shared-code-between-desktop-and-web/51206/2 "2019-11-19T14:33:59Z")

</div>

you make 2 methods with the same name, one with progressbar, the other with webprogressbar (or nothing) as parameter  
then in the second page of the inspector, you uncheck web or desktop to compile only for the needed paltform.

---

<div class="post-metadata">

**Author:** ![Richard\_Albrecht](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_albrecht/32/817_2.png) [@Richard\_Albrecht](https://forum.xojo.com/u/Richard_Albrecht)\
**Post date:** [November 19, 2019, 4:07pm UTC](https://forum.xojo.com/t/help-using-shared-code-between-desktop-and-web/51206/3 "2019-11-19T16:07:47Z")

</div>

I unchecked the web option In inspector and now it doesn’t compiles in the web option.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [November 19, 2019, 4:10pm UTC](https://forum.xojo.com/t/help-using-shared-code-between-desktop-and-web/51206/4 "2019-11-19T16:10:08Z")

</div>

A few ways to handle this:

- make two methods with different signatures (you can then set the Insepector/Gear Icon/Attributes/Include In flags to choose only Web or Desktop for each method)
- one method that uses Variants, then internally switches on type:

```auto
MigrateAllUsers(iSAction as String, ProgV as Variant = nil, lblV as Variant = nil)
#if TargetWeb
  dim prog as WebProgressBar = progV
#else
  dim prog as ProgressBar = progV
#end if
 prog.value = 32
  [...]
```

---

<div class="post-metadata">

**Author:** ![Louis\_D](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/cab0a1/32.png) [@Louis\_D](https://forum.xojo.com/u/Louis_D)\
**Post date:** [November 19, 2019, 4:12pm UTC](https://forum.xojo.com/t/help-using-shared-code-between-desktop-and-web/51206/5 "2019-11-19T16:12:21Z")

</div>

Perhaps use a compiler directive to define the correct object?

oh… @Michael Diehr beat me to the line. +1 on his suggestion.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:10pm UTC](https://forum.xojo.com/t/help-using-shared-code-between-desktop-and-web/51206/6 "2021-04-29T16:10:35Z")

</div>


