Unsure how to do this

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

Unsure how to do this

Post by oldummy » Thu Dec 07, 2023 12:47 am

I'm making a little password manager stack for myself.
I have a button that generates a strong password. It is sent to a field.
When I click the field, it asks for an account name, and then sets a customproperty by that name with the generated password and puts the account
name into a field that will eventually list all accounts.
This all works great to this point. The issue I am having is how to edit the password of an account name without duplicating the account name in
the accounts field.
I simply regenerate another password, and enter the already existing account name when asked.

My problem is I don't seem to know enough to prevent it from adding another instance of the account name to the accounts field.

I am simply using aaa as my account name in this script.
I have tried a few if statements but I cannot get past line 4


on mouseUp --- password is in the contents of this field.
ask"Which account?"
set the it of this card to cr&it&cr&me -- sets the account name and password as a cp. works ok
-- if "aaa" is in fld "myaccounts" --this to catch and maybe prevent duplication of the account name in the myaccounts field. DOES NOT work.
Puts x in scriptline and cannot save script.
put it&cr after fld "myaccounts"
if "aaa" is in fld "myaccounts" then put aaa -- just to test. This works
end mouseUp

I'm assuming that this is something simple that I cannot see. At least, I'm hoping so, so all help is appreciated.

AndyP
Posts: 615
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Unsure how to do this

Post by AndyP » Thu Dec 07, 2023 10:20 am

Have a look at this code snippet

Code: Select all

-- this checks to see if the text being typed is already stored as a word in another field (myaccounts)

on textChanged -- catches the characters as they are being typed

   if the text of me is among the words of fld "myaccounts" then
      answer "Account name used!"
      delete char -1 of me -- this deletes the last character
   end if
   
end textChanged
This should point you in the right direction.
Also note the first line comment on what the code does. Adding explanatory comments like this will help you understand what's happening when you revisit the code at a later date, always good practice.
Also note the use of white space to make the code easier to read.

Also for readability, please enclose code using the Code Display button </>
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9678
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Unsure how to do this

Post by dunbarx » Thu Dec 07, 2023 3:09 pm

Hi to both of you.

@Andy.
...it asks for an account name..
I assume oldDummy is entering the account name in an "ask" dialog. If so, then no handler will work while the dialog is open, that is, no messages are sent, since such dialogs are blocking. And just as an aside, assuming we eventually get to some more "open" method of entering the new account, it would be better to:

Code: Select all

 if the text of me is in fld "myAccounts" then  --not "among the words of"
because if an existing account was, say, "aaa XXX" then your handler would not catch "aaa XXX" as it was being typed, however that is done.

@oldDummy. Is it true that you are trying to catch an existing account using an "ask" dialog? I would, but then only when hitting "OK" can you check for an existing account. The good news is that this is simple to do.

But if you really want to catch an existing account as the user is typing, then you have to use some other entry means than a dialog. Is that true?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9678
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Unsure how to do this

Post by dunbarx » Thu Dec 07, 2023 3:38 pm

Andy.

I should have said:

Code: Select all

 if the text of me is among the lines of fld "myaccounts" then
Because that will not fire with partial entries that appear to be on the right track while typing but may change as subsequent chars are typed.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9678
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Unsure how to do this

Post by dunbarx » Thu Dec 07, 2023 3:40 pm

oldDummy.

If you are following this, you see that you can check for an existing account while the user is typing if you use a field instead of a dialog. This is what Andy was getting at.

But is this OK?

Craig

oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

Re: Unsure how to do this

Post by oldummy » Thu Dec 07, 2023 4:30 pm

Many thanks to all for your input!
I did however get it to work. Not elegant, not ever a little bit pretty. As a mater of fact I will probably try several of your suggestions. I've been away from this for quite a while, and I was having trouble with my "if" statements.
This is what I wound up with, and it does work.

on mouseUp
ask"Which account?"
set the it of this card to cr&it&cr&me -- sets the account name and password as a cp. works ok
if it is in fld "myaccounts" then
put cr&it&cr&me after fld "mylist"
else
put cr&it&cr&me after fld "mylist"
put it &cr after fld "myaccounts"
end if
end mouseUp

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9678
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Unsure how to do this

Post by dunbarx » Thu Dec 07, 2023 4:38 pm

oldDummy.

Do please enclose code snippets within the code tags "</>":

Code: Select all

on mouseUp
ask"Which account?"
set the it of this card to cr&it&cr&me -- sets the account name and password as a cp. works ok
if it is in fld "myaccounts" then
put cr&it&cr&me after fld "mylist"
else
put cr&it&cr&me after fld "mylist"
put it &cr after fld "myaccounts"
end if
end mouseUp
Why are you setting a custom property if you do not use it? And a word of advice:

Code: Select all

set the it of this card to cr&it&cr&me
Never seen anything quite like this. :D

Do NOT use "it" any longer than you absolutely have to, as, er, "it" changes often all on its own as LC does its thing.

Craig

Klaus
Posts: 13836
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Unsure how to do this

Post by Klaus » Thu Dec 07, 2023 5:46 pm

If code tags, then please with indentings.

Code: Select all

on mouseUp
   ask"Which account?"
   set the it of this card to cr&it&cr&me -- sets the account name and password as a cp. works ok
   if it is in fld "myaccounts" then
      put cr&it&cr&me after fld "mylist"
   else
      put cr&it&cr&me after fld "mylist"
      put it &cr after fld "myaccounts"
   end if
end mouseUp

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9678
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Unsure how to do this

Post by dunbarx » Thu Dec 07, 2023 7:14 pm

What Klaus said.

The good news is that in general code snippets are copied directly from the Script Editor, so they are indented already.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7241
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Unsure how to do this

Post by jacque » Thu Dec 07, 2023 7:34 pm

If the original handler was as written above, I suspect the reason it couldn't get past line 4 was because this line:
Puts x in scriptline and cannot save script.
was supposed to be a comment but was being treated as a syntax error because it was on its own line in the handler. That's usually why a script can't be saved.

If the line was added later for our benefit then never mind.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9678
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Unsure how to do this

Post by dunbarx » Thu Dec 07, 2023 8:43 pm

Jacque.

I saw this at once and commented it out. From its content it is certainly a comment.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”