Unsure how to do this
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Unsure how to do this
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.
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.
Re: Unsure how to do this
Have a look at this code snippet
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 </>
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
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9678
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Unsure how to do this
Hi to both of you.
@Andy.
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
@Andy.
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:...it asks for an account name..
Code: Select all
if the text of me is in fld "myAccounts" then --not "among the words of"
@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
-
- VIP Livecode Opensource Backer
- Posts: 9678
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Unsure how to do this
Andy.
I should have said:
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
I should have said:
Code: Select all
if the text of me is among the lines of fld "myaccounts" then
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9678
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Unsure how to do this
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
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
Re: Unsure how to do this
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9678
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Unsure how to do this
oldDummy.
Do please enclose code snippets within the code tags "</>":
Why are you setting a custom property if you do not use it? And a word of advice:
Never seen anything quite like this.
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
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
Code: Select all
set the it of this card to cr&it&cr&me
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
Re: Unsure how to do this
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
-
- VIP Livecode Opensource Backer
- Posts: 9678
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Unsure how to do this
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
The good news is that in general code snippets are copied directly from the Script Editor, so they are indented already.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7241
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Unsure how to do this
If the original handler was as written above, I suspect the reason it couldn't get past line 4 was because this line:
If the line was added later for our benefit then never mind.
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.Puts x in scriptline and cannot save script.
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
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9678
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Unsure how to do this
Jacque.
I saw this at once and commented it out. From its content it is certainly a comment.
Craig
I saw this at once and commented it out. From its content it is certainly a comment.
Craig