Page 1 of 1

How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 4:15 am
by kiseki

Code: Select all

on writehtmlfile fileTowrite,dataTowrite
   set the defaultFolder to (specialFolderPath("Documents") &"/Contents")
   put dataTowrite into URL (("file:"&fileTowrite&".html"))
end writehtmlfile

on mouseUp
   if the environment = "development" then touchEnd 1
   local tURL, tFile
        get url "http(:)//mywebsite.php" 
        put it into url
        replace"[" with "" in url
        replace "]" with "" in url
        set itemdelimiter to ","
        put item 1 of urlA into myvalue1
        get char 2 of myvalue1
        put it into thevalue
     put "p" & thevalue  into thefile
     replace "," with "" in thefile
     put "http(:)//mywebsite.php?=pg" & thevalue into updated
     put url updated into thehtml
     writehtmlfile thefile,thehtml
    
   answer "Updated"
   
end mouseUp
Hi! I'm completely new to this and I am trying to know how to create a loop for this code~

The website only gives a text of an array ----> ["1", "2"]

So, I was able to get the value 1 and 2 out into a variable but I'm afraid that it would give me even more numbers, therefore I need to make a loop for it.

However, I am unable to think of a way of how to make the loop have their own variables to get the number to update the files.

Any help? Thanks!! :D

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 5:39 am
by kiseki
This was taken from one of the posts here, but I tried doing it. Is there a way to get the different item numbers using a loop? Because I would only have about 10 to 20 numbers to take care of. THANKS FOR HELPING IF THERE ARE ANY KIND SOULS! :)

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 6:04 am
by Simon
Hi kiseki,
Welcome to the forum.

I'll start off by mentioning "repeat" in the Dictionary.

The information you have provided is insufficient for me to understand what you are trying to do.
an array with 1 and 2 in it?
10 to 20 numbers??? Where did they come in?

Simon

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 6:14 am
by kiseki
Hmm, I meant that the website only gives a text and nothing else which contains the array ---> ["4","8"] or maybe even ["3,"8","9","13"] and or even more numbers. I am not sure how to get two digits too, as I can only get the one character from each number~ Let me try taking a look at the repeat in dictionary ^^ Thanks!

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 6:38 am
by Simon
Ok still not sure but.

With a new stack with 1 button and 1 field
Type ["3,"8","9","13"] into the field
Put this into the button script

Code: Select all

on mouseUp
   put fld 1 into tNums
   replace "[" with "" in tNums
   replace "]" with "" in tNums
   replace quote with "" in tNums
   repeat with x = 1 to the number of items in tNums
      put item x of tNums into myWorkingVariable
      ---do your stuff
      breakpoint
   end repeat
end mouseUp
Most of that is just to get rid of the non numerical data (probably there are better ways).

Simon

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 7:14 am
by kiseki
Hi there Simon! I got it to work. But there's only one problem left. The first number was working perfectly but the subsequent ones were having something like an extra space which is important for me to omit it.

The array is being get from a website that's why I couldn't change it. Therefore, I would need to ask of you to enlighten me with your knowledge on LiveCode about how to get about omitting that troublesome spacebar. Haha!

As you know, the array goes like this ---> ["4", "8"]

Therefore, when I take the first number, it gives me a "4"(Bravo). But when it goes to the second item number, it gives me a "(spacebar)8", which is like this " 8". Is it possible to omit the spacebar from there? :O Thanks with love! :)

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 7:16 am
by kiseki
Voila Simon! I got to work already! Thanks dude! :D Cya around LC!

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 8:10 am
by kiseki
Hi again Simon, I just want to make my interface look more interesting! :) Is there any websites or what to help me with interface and more importantly putting a background image of my own into my app? :) Thanks again!

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 8:25 am
by Simon
Hi kiseki,
For the UI here is a good resource;
https://www.iconfinder.com/
Background is easy, just import an image and move it to the bottom layer.

Simon

Re: How do I create a loop with these codes?

Posted: Thu Jan 09, 2014 1:03 pm
by Klaus
Hi kiseki,

some general hints:
1. Avoid using IT unless necessary (which will also save you one line of typing):
...
## get url "http(:)//mywebsite.php"
## put it into tVar
put url "http(:)//mywebsite.php" into tVar
...

2. URL is a reserved word, you should not use this as a name for your variable:
...
## Bad:
## put whatever into url
## Good:
put whatever into tUrl
...


Best

Klaus