Passing a variable to a module ?

Post

Posted
Rating:
#1 (In Topic #633)
Regular
Doctor Watson is in the usergroup ‘Regular’
Hi.
Just so you know : I have been back to square 1 with everything on my computer. A very huge power surge played havoc on numerous things electric in our neighbourhood, including my computer, its HD and external backup HD that happened just then to be connected. And yes, in spite of an apparently useless surge protector. Had to spend every free second to recover what still could be recovered. Back to business.

Question : How can I pass a variable to a module?

Some of you will remember my post on how to store data within an application (programme?) and building on a suggestion from Bruce, I put my data in a module like this :

Code (gambas)

  1. ' Module DataCloset
  2. NamesStr$ As String
  3.  
  4. ' Receive a value for x from Button1_Click() ???
  5.  x = 2   'just an example
  6.  
  7.   NamesStr$ = "John,Michael,Harry,Liam,William,Oliver,James,Peter"
  8.   NamesStr$ = "Isabelle,Yvonne,Mary,Patricia,Olivia,Emma,Eve,Amalia,Petra,Fleur"
  9.   NamesStr$ = "Fido,Tiger,Bella,Ginger,Momo,Chibi"
  10.  
  11. Return NamesStr$
  12.  

In Fmain I have a Button that should retrieve the list I want (just for now, later to be replaced by a proper choose routine.)

Code (gambas)

  1. Public Sub Button1_Click()
  2.  
  3. 'Here I would like to send the list number to module DataCloset
  4. ‘before it returns the data.
  5.  
  6.   NamesList = Split(DataCloset.Data(), ",", " ", True)
  7.   ‘followed by the rest of the code
  8.    

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

Doctor Watson said

…Question : How can I pass a variable to a module?


I'm not totally clear on how you want to implement this, but one approach is to create a Public variable in your module.

So maybe:-

Code (gambas)

  1. ' Module DataCloset
  2.  
  3. Public intListNimber as Integer
  4.  
  5. NamesStr$ As String
  6.  
  7. ' Receive a value for x from Button1_Click() ???
  8.  
  9. Select Case intListNumber
  10.   NamesStr$ = "John,Michael,Harry,Liam,William,Oliver,James,Peter"
  11.   NamesStr$ = "Isabelle,Yvonne,Mary,Patricia,Olivia,Emma,Eve,Amalia,Petra,Fleur"
  12.   NamesStr$ = "Fido,Tiger,Bella,Ginger,Momo,Chibi"
  13.  
  14. Return NamesStr$
  15.    

…and then in FMain:-

Code (gambas)

  1. Public Sub Button1_Click()
  2.  
  3. 'Here I would like to send the list number to module DataCloset
  4. 'before it returns the data.
  5.   DataCloset.intListNumber = 3
  6.  
  7.   NamesList = Split(DataCloset.Data(), ",", " ", True)
  8.   'followed by the rest of the code
  9.    

…or instead of declaring a Public variable, maybe pass the list number as an argument to the Data function, something like this:-

Code (gambas)

  1. 'Receive a value for x from...
  2. ...
  3.  

Code (gambas)

  1. Public Sub Button1_Click()
  2.  
  3. 'Here I would like to send the list number to module DataCloset
  4. 'before it returns the data.
  5.  
  6.   NamesList = Split(DataCloset.Data(3), ",", " ", True)
  7.   'followed by the rest of the code
  8.      

I hope that is clear.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
Doctor Watson is in the usergroup ‘Regular’
 Thanks Steve !
The first solution does exactly what I'm looking for.
I just forgot about about the Public declaration. Oh dear …

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top
1 guest and 0 members have just viewed this.