B4J Question Ignore SelectedChange True at first runtime cycle [SOLVED]

ThRuST

Well-Known Member
Licensed User
Longtime User
Since I am implementing sound themes to events, the sound is played automatically once the application runs - if SelectedChange is set to True.

Sound is played each time it is changed. Any clever advice how to prevent sound to play at first runtime cycle?

EDIT I've made an example that illustrates the problem.

Note that state.dat is saved to drive D:\ in v1.0

v1.0 is the first example that doesn't have any Bool checking.
v1.1 implements bool check but the sound does not play at first click (when state is Disabled)
v1.2 I finally nailed it, it works yay :)
 

Attachments

  • SelectionChange v1.zip
    413.2 KB · Views: 189
  • SelectionChange v1.1.zip
    413.9 KB · Views: 185
  • SelectionChange v1.2.zip
    452.2 KB · Views: 179
Last edited:

ThRuST

Well-Known Member
Licensed User
Longtime User
Ok I see your point, but I've allready a step ahead even though I didn't mention it initiallity :)

This is a mess, but you'll get the idea what I am trying to achieve. It works (almost) except that sound is never played the first time the button toggles from false to true, in that case the selection is turned off. So this makes it slightly more complicated, so I need to think about this some more. Perhaps a Boolean will be enough? The storestate is a boolean to save my confusion state :)

B4X:
Private StoreState1 As Boolean = Selected
   
If TempStopSound = 0 Then
        TempStopSound = TempStopSound + 1
        'restore state
        BtnFilterSQL.Selected = StoreState1
        Return
End If

'If BtnFilterSQL.Selected = False Then
        'TempStopSound = TempStopSound + 1
'        Return
'End If
   
    If TempStopSound >=1 Then
        TempStopSound = 1
   
            If Selected = True Then
                PlaySound.Filter_enabledSnd
       
                else if Selected = False Then
                    PlaySound.Filter_disabledSnd
           
   
            Log ("Tempstopsound main sub : " & TempStopSound)
   
        End If
       
    End If
   

    'SaveFilterSelection
    SQLite.SQLite_StoreSetting_SaveFilterSelection
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
I'll put together a source code example to illustrate the problem. Here's the two sound files I generated in case you want to try it yourself.

And of course it uses a ToggleButton
 

Attachments

  • Speech.zip
    15.5 KB · Views: 190
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Ok, I've made an example. SelectionChange v1.0 Drop it like it's hot :cool:

Oh and I almost forgot.. Switch to Enabled state and restart the program.
She's talking, when she shouldn't. Any programmer teach her a lesson ASAP :D
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
btw what values do you get from running the source code v1.0? Here's what I got (Release mode)

upload_2019-7-4_17-55-6.png
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Mashiane I have now successfully implemented the structure into my project Athena and it works as expected.

All together now : say YAY, say Hooh, Say YAY, Say Hooh :)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Advice for anyone who will use the SelectedChange solution in v1.2. My advice is to set ToggleButton.Tag = "Enabled" or "Disabled" directly after the selection value has been loaded. This way you can use a materialize icon on the button instead of depend on text. I learned this from a tutorial by Erel, and it works extremely well :)

Here's my own solution to this

SQLite
B4X:
Sub SQLite_LoadSetting_LoadFilterSelection
   
    Try
        Private Logic As Byte
        Dim ReadData As ResultSet = SQLiteSettings.ExecQuery("SELECT * FROM Settings where Id = 16")
        Logic = ReadData.GetString("Data")
       
        If Logic = 0 Then
            Main.BtnFilterSQL.Selected = False
            Main.BtnFilterSQL.Tag = "Disabled"
        End If
       
        If Logic = 1 Then
            Main.BtnFilterSQL.Selected = True
            Main.BtnFilterSQL.Tag = "Enabled"
        End If
       
    Catch
        Log(LastException)
    End Try
       
End Sub
 
Upvote 0
Top