Help with Procedure

You need conditional statements ( if...then..else) to display your logic. This tutorial Programming Your App to Make Decisions should help you to develop the appropriate logic.

Experiment. if you still have issues, share your new blocks and someone should provide specific advice

By the way, you have another issue procedureIssue . What you coded will always be false. You have to specify a specific response code ( like 200) and if that is true the trailing code will be execudted).

Perhaps if call CheckResponseCode = 200 will work.

1 Like

Here is the thing I would like to do. Before any of Firebase component stores / gets value , I would like to test the internet connection.

InternetCheck calls the Web1.get in order to just test the internet connection. call CheckResponseCode has a condition which checks if the Response code = 200 or not. and then I would like to vary the Firebase Store/get accordingly. Is it Possible?

and the basis/variable for setting the Firebase Store value ? Where does that come in ?

See there are like 5 to 6 times , all at different places in code , where I call the Firebase components to store value or to retrieve values. All I need is to check for internet connection before any of FirebaseDB.store or FirebaseDB.get is called. You can link this topic with Help for Firebase store value and get value that is the trouble I have with FirebaseDB.. So I have decided to check the internet every time before FirebaseDB.store or FirebaseDB.get is called.

Do you still need help with this, if so, explain further the help you need....

Ok , Sorry for not clearly mentioning what I want to do. I hope this post clearly mentions what exactly I want to do

For that I am using this


If you can see the set of blocks encircled in red , they are repeating over and over again , at different instances (only 2 such instances are mentioned). Wherein The then conditions are varying according to the requirement. The main Aim is to check for an internet connection before calling a firebase component. (Rest blocks cleared to avoid unnecessary confusion)
What I want is not to repeat the blocks encircled with red , create a function ( or procedure) for those 3 blocks , Where my input in each case will be different i.e condition in then part.

I hope this clearly explains what I want to do. If not , I am sorry I would present it in a better way.

Thank You ,
Regards
Kunj

Your workflow logic is incorrect, you are checking the output of reponseCode before it has had a chance to return.

Suggest you do something like this:
Check for internet, then in the Web1.GotText event, select an action based upon a variable set:

If you don't like the if-tree approach of @TimAI2, here is another approach.
(You may not like it, but it would get the job done.)

Think of those Middle Eastern beaded curtain doorways, where
to pass through the doorway you have to part the hanging chains of beads to your right and left to open a path through the doorway.

Now imagine that every one of those vertical hanging chains of beads (probably a better word) has at its top one of your buttons that requires a sequence of online actions, checks, and events, one per bead along that chain. Each bead on that chain would be a separate component devoted to that phase of that chain. Each event in your chain of events would initiate only the action whose completion event appears next in line down that chain.

This approach multiplies your number of components (web, FirebaseDB, file, anything asynchronous) considerably, and you have to be fussy about your naming of those components in the Designer to identify the process and phase they serve.

In the Blocks Editor, you could organize these control flows in columns, with the initiating controls (Button Click?) at the top, and the chains of corresponding event blocks leading downwards, like a beaded curtain doorway.

When @kunj_thakker kunj says "but I have 200 tags to set and call" then we need a different approach, at the moment, it is indicated there are only six calls required....

KISS

Here is an alternative approach that separates the internet check asynchronicity from your FirebaseDb work flow ...

Devote a Clock clkInternetCheck and Web component WebInternetCheck and a global variable InternetIsUp (true/false) to checking every second if the Internet connection is up, as discussed at https://www.imagnity.com/tutorials/app-inventor/check-internet-connection-in-app-inventor/, setting the global variable InternetIsUp for reference by other work flows synchronously. If the Internet goes down in the second between checks, tough luck.
Have your procedure check the global variable and not try anything asynchronous.

Thanks @TIMAI2 !
And extremely sorry :worried: , for double posting things
Looks The perfect way to deal with my problem
Approach seems proper , And should work. I will try and see if everything goes fine or not, It would take a good effort though.
Thanks again!

@ABG , Your approach does sound interesting , very well explained , all those beads and stuff.

So that would mean multiple components and well I am trying to cut down on repetition of blocks , and I am doing that because the project I had worked on before this one , both serve the same purpose but the previous one is all messed up (real messed up having 100s of blocks) ,and finding a bug in 100s of blocks that becomes difficult. So I had to start off all over again , A new project , scraping the old one. So trying to keep down the blocks.

Thanks for coming up with such a wonderful Idea

Here is an article discussion the various tradeoffs of different organizational approaches to code ...

My concerns about if/then trees in component events are based on the increase in the coupling of the component events to different work flows within the app.

On the other hand, my beaded curtain approach loses a lot of cohesion, and needs strict naming discipline and block positioning to make up for that.

1 Like

Working perfectly when Internet is running , But When I turn off the internet , (on purpose for testing) this is the thing I get.

I don't wish to see this , when there is no internet , This is placed under Web1.GotText


The part Highlighted in red is the one I would like to see In case there is no Internet

I wish to see

and probably Else part doesn't run (That is what I think)
Thank you

Look back at Saj Duttal's example:
https://www.imagnity.com/tutorials/app-inventor/check-internet-connection-in-app-inventor/

You need to use the Screen1.ErrorOccurred Event block to capture error 1101

There is an event block under Screen1 to catch errors.
That might hide this and offer an opportunity to set a global variable with Internet status.

Hello. I have quite a complicated program in which there is a clock that countdowns and it is supposed to countdown all the way to zero and then a new vertical arrangement should show.
Inside the procedure, I originally used a while test but my program kept crashing. Now I have two if blocks but the program goes to the else and only counts down once. How can I make it repeatable so that it goes and does the code in else all the way until the if becomes true?

Thanks,
Parsa

I recommend you study this sample app, which uses only one Clock but has multiple deadlines in global variables, to allow simultaneous tracking of deadlines.

1 Like

Thanks! I will check it out.

Hello,

I tried using one clock and it worked. But I have one more question:

I am making this app for the AP Computer Science Principles exam project and the requirements state that I must have a procedure in my program that has a parameter and contains an algorithm inside of it which uses selection, sequencing, and iteration. Does my procedure satisfy all of these? Does enabling a clock count as iteration?

Thanks,
Parsa