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

Discussion in 'B4J Questions' started by ThRuST, Jul 4, 2019.

  1. ThRuST

    ThRuST Well-Known Member Licensed 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 :)
     

    Attached Files:

    Last edited: Jul 4, 2019
  2. Mashiane

    Mashiane Expert Licensed User

    Code:
    Process_Globals
    Private bLoading As Boolean
    Code:
    Sub Initialize
    bLoading = 
    True

    blah blah blah
    blah blah blah.

    bLoading = 
    False
    End Sub
    Code:
    Sub SelectChange
    if bLoading = True then Return
    #JustAthought
     
  3. ThRuST

    ThRuST Well-Known Member Licensed 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 :)

    Code:
    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
     
  4. Mashiane

    Mashiane Expert Licensed User

    Tip: I have learned the hard way never to set variable assignments in Process / Class Globals unless they are constants.

    I will check this stuff out...
     
  5. ThRuST

    ThRuST Well-Known Member Licensed 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
     

    Attached Files:

  6. ThRuST

    ThRuST Well-Known Member Licensed 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
     
  7. ThRuST

    ThRuST Well-Known Member Licensed 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
     
  8. ThRuST

    ThRuST Well-Known Member Licensed User

    It's done, download v1.2 and behold the poetry in motion... :cool:
     
  9. ThRuST

    ThRuST Well-Known Member Licensed 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 :)
     
  10. ThRuST

    ThRuST Well-Known Member Licensed 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice