Easy question for Sunday;)

parijs

Active Member
Licensed User
Longtime User
How to send to a Sub with a Dim(String)

And is there a way to use a sub in another module
 

Cableguy

Expert
Licensed User
Longtime User
Yes there are a few..

If the sub is in another module, you must precede the sub's name with the module name...
In some situations you can use CallSub(...)

In either of then you can pass a value:

Sub MySub
Dim a as string
a="myString"
SecondSub(a)
End Sub

Sub SecondSub(b As String)
ToastMessageShow(b,True)
End Sub

This will show a toast message with the text "myString"
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
Hi Cableguy,

I've tried a few things, but it did not work.
Little explanation:
I'm in module (project)
and I would pick some variable in the module Latin, which are in Sub Parnasse.
I use CallSub (Latin, "Parnasse") but I am not on the spot

Greetings from Holland
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
variables are usually only acessible inside the module they were created, unless they are DIMed in the sub ProcessGlobals...

Then to access them all you would need would be this:

Parnase.latin

Just after typing the dot after the module's name, a list of the available vars and subs is displayed
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
They are DIMed in the sub ProcessGlobals from the main.

So I need a sub
My variables are filed in Parnasse.

Sub Parnasse
main.FotoUrl="http://maps.google.nl/mapsxxxxxxx,296.96,,0,12.19"
main.MapNaam="Cimetière du Montparnasse"
main.lat = 48.8381
main.lon= 2.3260
main.pic="begmontparnasse.jpg"
main.textpage="begmontparnasse"
main.textpage2="begmontparnasse2"
main.ster ="3"
main.wijk="Montparnasse"
End Sub

oops ... and so there are still another 250 Subs, which I need in Sub Project
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Then you have a job cut out for you!!!!:sign0188::wav::sign0188:
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
Smile the job is almost done.
Only it is now in the project module.
But I would like to get the information from another module.

Thanks for your time.
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
by the way ;)

Parnase.latin does not work and give me the next error

Error description: Undeclared variable 'parnase' is used before it was assigned any value.

And parnase give nothing after the dot
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I don't understand exactly what you want to do.
If you have variables declared in the Process_Globals routine in the Main module
B4X:
Sub Process_Globals
 Dim Lat as Double
End Sub
these variables can be used in any other module with the prefix of the Main module.
Main.Lat

You can access subroutines only in other 'code' modules, not in other Activity modules.
To call a subroutine in a code module you must put the module name as a prefix. To see how this works you could have a look at the Charts module.

Best regards.
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
Hi Klaus,

There are two things I would like

1: to call a sub, by a dim (string), because the sub I call depends on the dim.

2: And I want to go to another module, run a sub what fill variables and return to my work module what's making use of those variables
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
1. From my knowledge you cannot do this.
You can Dim variables and objects but no Subroutines.
Sorry, but I still don't understand what you want to with this dim, do you have a concrete example ?

2. No problem, the example in your post #5 is OK.
If the module name is 'General' you must call the Sub with General.Parnasse, as already mentioned it must be a code module.

Best regards.
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
Hi Klaus,

1: example

In een module I have a Sub MySub.
I can cal this Sub just by typing

Mysub

But what I whant is this

Dim a As String : a="MySub"
and call the sub by a
but thats not working
By just typing a it's says me to visit the doctor

I want to use Dim because I have several variables through the same routine
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Why do you want to call the routine with 'a' and not with MySub ?
I want to use Dim because I have several variables through the same routine.
What do you mean with 'several variables through the same routine' ?

I still don't understand what you want to do, you explain how you want to call a routine, but that way is not possible in B4A. But you don't explain the basics of what you want to do. What is in the routine, what do you do in the routine with what variables, why is it in another module etc.

I prefer understanding the whole problem to give an advice.

Best regards.
 
Last edited:
Upvote 0

parijs

Active Member
Licensed User
Longtime User
Thanks for the second "my" problem.
I did not know it must in a code module.
This is working :sign0142:
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
Hi Klaus,

I have this Sub's and 250 more like this.

Sub Parnasse
main.FotoUrl="http://maps.google.nl/maps.19"
main.MapNaam="Cimetière du Montparnasse"
main.lat = 48.8381
main.lon= 2.3260
main.pic="begmontparnasse.jpg"
main.textpage="begmontparnasse"
main.textpage2="begmontparnasse2"
main.ster ="3"
main.wijk="Montparnasse"
End Sub
Sub pontdesarts
main.FotoUrl="http://maps.google.nl,,0,4.93"
main.MapNaam="Pont des Arts"
main.lat = 48.858468
main.lon= 2.337556
main.pic="pontdesarts.jpg"
main.textpage="pontdesarts"
main.textpage2="pontdesarts2"
main.ster ="3"
main.wijk="Saint Germain"
End Sub
Sub pierredemontmartre
main.FotoUrl="http://maps.google.nl/ &cbp=12,77.96,,0,-1.68"
main.MapNaam="St. Pierre de Montmartre"
main.lat = 48.886616
main.lon= 2.341585
main.pic="pierredemontmartre.jpg"
main.textpage="pierredemontmartre"
main.textpage2="pierredemontmartre2"
main.ster ="3"
main.wijk="Montmartre"
End Sub

I use it in a webbase app.
Because webbase always filled by the same variable names but with different values I like calling a Sub with a string, the easiest solution.
I press the button from a ListView with the value or Dim I go to the webbase module but there he needs the variables from 1 of those Subs

I do believe that I'm not quite on the right track, but I'm too far to change.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You could use something like this:
B4X:
Sub SelectSite(Site As String)
    Select Site
    Case "Parnasse"
        main.FotoUrl="http://maps.google.nl/maps.19"
        main.MapNaam="Cimetière du Montparnasse"
        main.lat = 48.8381
        main.lon= 2.3260
        main.pic="begmontparnasse.jpg"
        main.textpage="begmontparnasse"
        main.textpage2="begmontparnasse2"
        main.ster ="3"
        main.wijk="Montparnasse"
    Case "pontdesarts"
        main.FotoUrl="http://maps.google.nl,,0,4.93"
        main.MapNaam="Pont des Arts"
        main.lat = 48.858468
        main.lon= 2.337556
        main.pic="pontdesarts.jpg"
        main.textpage="pontdesarts"
        main.textpage2="pontdesarts2"
        main.ster ="3"
        main.wijk="Saint Germain"
    Case "pierredemontmartre"
        main.FotoUrl="http://maps.google.nl/ &cbp=12,77.96,,0,-1.68"
        main.MapNaam="St. Pierre de Montmartre"
        main.lat = 48.886616
        main.lon= 2.341585
        main.pic="pierredemontmartre.jpg"
        main.textpage="pierredemontmartre"
        main.textpage2="pierredemontmartre2"
        main.ster ="3"
        main.wijk="Montmartre"
    End Select
End Sub
And to call the routine:
B4X:
MyModule.SelectSite("Parnasse")
MyModule.SelectSite("pierredemontmartre")
You could also use a database.

Best regards.
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
I know now a database was better.
But i'm on 75% off the app and the knowledge to make it with a database is missing me a little.

Your solution works perfectly, thank you
Even with a var ;) Kode.SelectSite(main.keuze)
 
Upvote 0
Top