Search and Scrolling List field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 3
- Joined: Sun Jan 13, 2019 11:30 am
Search and Scrolling List field
Right so in the stock app I'm making, I'm trying to make a search bar that, when certain keywords are into the search field and the search button is pressed, it will store the keyword into a variable before substituting it into a search API that will return a .csv file that contains a list of companies and certain details of them and put that into a scrolling list field, with each company and their details returned as individual options. When one of these options are pressed it should substitute the first item of each choice (the company's stock symbol). However, when I enter something a keyword of a company I know exists(in this case its symbol) then it returns nothing into the scrolling list field. Even entering in a single letter, or the company's exact name won't do anything when I try to use the variable of the text of the search field. However when entering a keyword directly into the API through the script instead of using a variable, it returns the .csv file with each line as a choice. I'm pretty sure it's not the API's fault but something to do with language. Could you please tell me whats wrong with it.
My script for the search button where searchField is where the user enters the keyword and choiceField is the scrolling list field.:
global theKeyword
global x
on mouseUp
put the text of field "searchField" into theKeyword
put url(this is where the api would go but forum won't let me put it here.) into x
delete line 1 of x
delete the last char of x
put x into field "choiceField"
end mouseUp
The other problem is I don't know how to select the first item of the selected choice in the scrolling list field. I want to be able to select the first item of whatever option I choose and substitute it into a function. But I get a compilation error at the line where I use 'clickLine' What's wrong with it?
Code for scrolling list field:
on mouseUp
local y
local z
put clickLine of field "choiceField" into z
put item 1 of z into y
call getStock(y) . (function declared in stack so I should be able to call it)
end mouseUp
My script for the search button where searchField is where the user enters the keyword and choiceField is the scrolling list field.:
global theKeyword
global x
on mouseUp
put the text of field "searchField" into theKeyword
put url(this is where the api would go but forum won't let me put it here.) into x
delete line 1 of x
delete the last char of x
put x into field "choiceField"
end mouseUp
The other problem is I don't know how to select the first item of the selected choice in the scrolling list field. I want to be able to select the first item of whatever option I choose and substitute it into a function. But I get a compilation error at the line where I use 'clickLine' What's wrong with it?
Code for scrolling list field:
on mouseUp
local y
local z
put clickLine of field "choiceField" into z
put item 1 of z into y
call getStock(y) . (function declared in stack so I should be able to call it)
end mouseUp
Re: Search and Scrolling List field
Hi MechWithoutTech,
welcome to the forum!
Due to problems with spamming here, you need to have at least 10 postings before you can post links etc.
Do this:
Hint:
Unless you selected "Variable checking", there is no need to declare local (to the handler) variables.
Best
Klaus
P.S.
Little personal note: A little "Hello" or something will not hurt for the first posting!
welcome to the forum!
Due to problems with spamming here, you need to have at least 10 postings before you can post links etc.
Do this:
Code: Select all
on mouseUp
local y
local z
## This is the list field, so we can us ...OF ME
put the selectedtext OF ME into z
## clickline is a FUNCTION, please read up "clickline" in the dictionary!
put item 1 of z into y
## call getStock(y)
## Not sure if CALL is the correct command here, since this is a function I would use this syntax.
## From the dictionary about CALL -> Executes the specified HANDLER in any object's script.
put getStocky(y) into dummy
end mouseUp
Unless you selected "Variable checking", there is no need to declare local (to the handler) variables.
Best
Klaus
P.S.
Little personal note: A little "Hello" or something will not hurt for the first posting!
-
- Posts: 3
- Joined: Sun Jan 13, 2019 11:30 am
Re: Search and Scrolling List field
Thank you so much Klaus, and sorry that I missed it in my original post, hello forums . The code worked like a charm when I tested it with a sample keyword.
That just leaves the search problem which I still have no idea how to fix. What would you(or any experienced coders reading this) suggest I do to fix that problem?
Cheers,
MechWithoutTech
That just leaves the search problem which I still have no idea how to fix. What would you(or any experienced coders reading this) suggest I do to fix that problem?
Cheers,
MechWithoutTech
Re: Search and Scrolling List field
Hello MechWithoutTech,
Looks like you might be new to Lc so I thought this line of Klaus's help ~
When writing scripts, there are more than one place where you might declare a variable, and local variables can be 'script' local or local to the handler.
A script local variable would be written outside of the handlers, and would then be required to have the 'local' keyword pre variable, like so -
Variables used this way remain filled with the data you put into them while other handlers (that may need access to that data) run. in the above example, on the mouseDown we put data into tNum, and then move that data to tX in the mouseUp.
Inside of handlers, where the variable will only be used during the time the handler will run, no such declaration is needed -
In this version of the code, 3 is put into tNum in the mouseDown event, but in the mouseUp event tNum will be 0, because it is handler local.
I hope this helps, it confused me a lot when I started looking at this language. This lesson may also be of some guidance.
Looks like you might be new to Lc so I thought this line of Klaus's help ~
~ could use a bit more depth as it were.
When writing scripts, there are more than one place where you might declare a variable, and local variables can be 'script' local or local to the handler.
A script local variable would be written outside of the handlers, and would then be required to have the 'local' keyword pre variable, like so -
Code: Select all
// script local variable...
local tNum, tX
on mouseDown
put 3 into tNum
end mouseDown
on mouseUp
put tNum into tX
end mouseUp
Variables used this way remain filled with the data you put into them while other handlers (that may need access to that data) run. in the above example, on the mouseDown we put data into tNum, and then move that data to tX in the mouseUp.
Inside of handlers, where the variable will only be used during the time the handler will run, no such declaration is needed -
Code: Select all
on mouseDown
put 3 into tNum
end mouseDown
on mouseUp
put tNum into tX
end mouseUp
In this version of the code, 3 is put into tNum in the mouseDown event, but in the mouseUp event tNum will be 0, because it is handler local.
I hope this helps, it confused me a lot when I started looking at this language. This lesson may also be of some guidance.
Re: Search and Scrolling List field
Hi,
or
would work better.
Your user may have clicked somewhere meanwhile, resulting in a corrupted ClickLine. So I'd make sure that field "choiceField" has its "listBehavior" set (and "multipleHilite" NOT set), and work with "the hilitedLine" (it returns a line number only):
This way you save the use of z, additionally ;-)
Have fun!
It's a function - "the clickline" or "clickline()". It should result in something like "line 4 of field 5" ...
Since you haven't defined another Itemdelimiter, it's comma, and you'll get "line 4 of field 5" in y.
Code: Select all
put word 2 of z into y
Code: Select all
set itemdel to space
put item 2 of z into y
Your user may have clicked somewhere meanwhile, resulting in a corrupted ClickLine. So I'd make sure that field "choiceField" has its "listBehavior" set (and "multipleHilite" NOT set), and work with "the hilitedLine" (it returns a line number only):
Code: Select all
put the hilitedLine of field "choiceField" into y
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!