Need another approach for program

Post your Gambas programming questions here.
User avatar
sadams54
Posts: 166
Joined: Monday 9th July 2018 3:43am
Contact:

Need another approach for program

Post by sadams54 »

I am in need of adding to a project. What happens with this program is that it reads an instruction file. It recursively executes what is in the file. This is working nice but needs a new feature. This sub would be defined as follows...

MakeTmr(Cmpr as string, TimeInt as integer, CompareType as string, CompareValue as string, TShell as string, FShell as string)

Cmpr is a name of a shell script that will return a value. This is run when the timer triggers.
TimeInt is the delay for the timer in milliseconds (it will execute the Cmpr script every TimeInt)
CompareType is the way comparison is done (not relevant for this)
CompareValue is what the result is compared to (not relevant for this)
TShell is another shell script that is run if the condition is true
FShell is another shell script that is run if the condition is false or if not present will reset the timer delay and repeat

The timers will be created as needed. so there could be 2 of these running, none running or 50 of them running. I can create the timers on the fly as needed but the issue is when they go off, I can't tell which one is triggered so the correct shell scripts can execute. I have buttons made this way but I can control the name and tag of the buttons and use them to figure out what to do. The timer has no name or tag when I create it so I have no way of telling what to run when it triggers nor any of the information from when it was created. I am considering using Settings= to store information just never execute the settings.save so nothing is written to disk and setting are only used in the program then lost. Since more than one copy of the program can be running at a time this should keep information to the individual running programs without cross contamination. But I still can't tell which information to grab for each timer because I can't differentiate them from each other yet.

I could use some ideas on how to make this happen.
User avatar
sadams54
Posts: 166
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Need another approach for program

Post by sadams54 »

wow, did I stump everybody? cool....

I had an idea but not sure it can be done. Is it possible to wrap a control like the timer control in Gambas? The purpose would be to attach and expose the name and tag properties for a timer so I can detect which one is triggered and the tag to tell me what should be run.

So any info anywhere on how to do this?
User avatar
cogier
Site Admin
Posts: 1158
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Need another approach for program

Post by cogier »

I don't know if I fully understand your request, but have a look at the attached program.
Timers-0.0.1.tar.gz
(7.76 KiB) Downloaded 238 times
User avatar
BruceSteers
Posts: 1831
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Need another approach for program

Post by BruceSteers »

You could just add .Tag to Timer.class

Simply save this as Timer.class in your project .src folder. then hTimer.Tag will be present

' Gambas class file

Export

Property Tag As Variant Use $vTag




Then all timers can trigger the same event and you can use Last.Tag to get the timer info.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
sadams54
Posts: 166
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Need another approach for program

Post by sadams54 »

BruceSteers wrote: Friday 6th September 2024 4:58pm You could just add .Tag to Timer.class

Simply save this as Timer.class in your project .src folder. then hTimer.Tag will be present

' Gambas class file

Export

Property Tag As Variant Use $vTag




Then all timers can trigger the same event and you can use Last.Tag to get the timer info.
You are on the right track for what I need. I tried to put this in the main class up in the beginning but the tag property is not added and the export word causes an error. "unexpected export" so I do not think I have the quite right but yes adding the tag to the timer would solve the issue entirely. I know I need to put this into its own class but the export still fouls me up.
Last edited by sadams54 on Monday 9th September 2024 7:48pm, edited 1 time in total.
User avatar
sadams54
Posts: 166
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Need another approach for program

Post by sadams54 »

cogier wrote: Friday 6th September 2024 2:28pm I don't know if I fully understand your request, but have a look at the attached program.

Timers-0.0.1.tar.gz
Off topic on that reply. I am looking to create multiple timers programatically. each with different times and each needs to be able to be identified when it triggers so proper code can execute. There can be 2 timers running or 102 timers running concurrently. If the name and tag properties were available it would work perfect. However they are not.
User avatar
BruceSteers
Posts: 1831
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Need another approach for program

Post by BruceSteers »

No save that text as a separate file called Timer.class

Then it auto inherits Timer.class and adds the Tag property to all timers.

Check this s post out...
https://forum.gambas.one/viewtopic.php?t=1369

In the first comment I explain it all and show how to also show Tag in the IDE property list 😎
If at first you don't succeed , try doing something differently.
BruceS
User avatar
sadams54
Posts: 166
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Need another approach for program

Post by sadams54 »

got things working. That is a great thing to be able to add properties. I notice that in the example you set the tag property to $vtag, is that a constant or something? If I added a name property also, what would it be set to?
User avatar
BruceSteers
Posts: 1831
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Need another approach for program

Post by BruceSteers »

It's a naming convention for variables

$ because it is a global Private variable
v because it's a Variant type
Tag is the name
So $vTag

Following the convention (it's Benoits not mine) you would use
$sName for a string type property called Name

But you can use whatever you like

The Use keyword just makes the property use that variable so you don't need the property read and write methods
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1831
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Need another approach for program

Post by BruceSteers »

In my IDE (I'm not sure if it's Benoits code or mine) if I type the following...

Property Name As String

And with the cursor at the end of the line I press LeftAlt-Shift-Return and it automatically adds Use $sName to the line :)
If at first you don't succeed , try doing something differently.
BruceS
Post Reply