I apologize for being so new to PB... and I am sure this is a rather simple resolve for those who have been working with PB. This is only me second attempt at a project and I have found that the help file that is attached to the IDE is handy but less than helpful in learning to actually implement certain aspects of the programming.
I am trying to find a method to compare the input of a string gadget to a known list.
As an example, let's assume I have a two lists... one for fruit and one for vegetables. The user selects to enter the vegetable window and inputs "apple" into the string gadget to search the data base. They are obviously not in the correct window to do that specific search, but because both data bases are open it will find and display the data for "apple" although it should not be ale to.
I am trying to segregate the ability to search from a list of specific items for a defined string gadget and only allow it to find what should be within that list of items for that gadgets. Or to link the specific string gadget to the specific data base so it can only search in that db for the result of the input from a specific string gadget.
Any thoughts?
Comparing string gadget input
Comparing string gadget input
"Occasionally stumped.... But never defeated!"
Re: Comparing string gadget input
Hi,
there are many solutions:
First you need to get the text of the StringGadget() with GetGadgetText().
Then you can...
search inside an array
search through a list
search for it in a map
use a sql SELECT in a database table
depending on the used StringGadget.
For two different gadgets with two different possibilities you need two of them.
Bernd
there are many solutions:
First you need to get the text of the StringGadget() with GetGadgetText().
Then you can...
search inside an array
search through a list
search for it in a map
use a sql SELECT in a database table
depending on the used StringGadget.
For two different gadgets with two different possibilities you need two of them.
Bernd
Re: Comparing string gadget input
I appreciate the advice. I'll look up "array" in the help file and see how I can implement that because it seems to be the option to use in this scenario.
I have the project almost completed at this point. All functions are working, with the StringGadget() and GetGadgetText(). The biggest issue I have is using 2 data bases and not being able to have the either of the two string gadgets only select from its own db or a list so it knows it is ok to display the search result or to display the message requester if the items being search is not within the list or db for that window.
example:
I am using a single procedure to do the specific search, so I have declared each StringGadget separate from the other during the the "Case" set up for each button used to call the procedure.
"Case" setup
Button setup:
The Vegetable "Case" and Button setup is the same as above but declared as its own.
In using a list or an array would be best in this scenario I think.
Would it be possible to give a small example of how to use a List or an array correctly in structure? Not looking for the code to be written for me... just a hint would be helpful for me to look at and see what and how it is doing its function. I am looking at the example provided in the "Help" menu of the IDE as well.... very vague example on how to use such an array, and there is NO example of the list function.
Again...thank you for any hints and knowledge passed along.
**DT2000**
I have the project almost completed at this point. All functions are working, with the StringGadget() and GetGadgetText(). The biggest issue I have is using 2 data bases and not being able to have the either of the two string gadgets only select from its own db or a list so it knows it is ok to display the search result or to display the message requester if the items being search is not within the list or db for that window.
example:
Code: Select all
If srch$ = "Fruit"
input = Trim(GetGadgetText(#Get1))
ElseIf srch$ = "Vegetable"
input = Trim(GetGadgetText(#Get2))
EndIf
"Case" setup
Code: Select all
Case #Fruit
srch$ = "Fruit"
item1.s = Trim(GetGadgetText(#Get1))
stripSpaces(item1.s)
result$ = stripSpaces(item1) ;strip out any spaces from item1
item1= result$ ;get item1 after stripping out unwanted spaces.
If item1 And DatabaseQuery(#dbaseID, "SELECT * FROM '"+ item1 + "' LIMIT 1")
displaylogo()
HideWindow(#FruitWindow, 1)
HideWindow(#ItemWindow, 0)
Else
MessageRequester("Database", "Please enter a valid item.")
SetActiveGadget(#Get1) ; places the cursor in the input box again
SetGadgetState(#Item, imgID1)
EndIf
Code: Select all
Case #Fruitbutton2
srch$ = "Fruit"
item1.s = Trim(GetGadgetText(#Get1))
stripSpaces(item1.s)
result$ = stripSpaces(item1) ;strip out any spaces from item1
item1= result$ ;get item1 after stripping out unwanted spaces.
If item1 And DatabaseQuery(#dbaseID, "SELECT * FROM '"+ item1 + "' LIMIT 1")
displaylogo()
HideWindow(#FruitWindow, 1)
HideWindow(#ItemWindow, 0)
Else
MessageRequester("Database", "Please enter a valid item.")
SetActiveGadget(#Get1) ; places the cursor in the input box again
EndIf
In using a list or an array would be best in this scenario I think.
Would it be possible to give a small example of how to use a List or an array correctly in structure? Not looking for the code to be written for me... just a hint would be helpful for me to look at and see what and how it is doing its function. I am looking at the example provided in the "Help" menu of the IDE as well.... very vague example on how to use such an array, and there is NO example of the list function.
Again...thank you for any hints and knowledge passed along.
**DT2000**
"Occasionally stumped.... But never defeated!"
Re: Comparing string gadget input
Hi,
if the code above are complete snippets, then you have a few mistakes inside:
Trim() already removes all spaces from head and tail of a string.
So stripSpaces() is not needed.
Or if you mean all spaces, also inside the string, then you can use RemoveString()
instead of Trim().
If you use DatabaseQuery(), where is the rest? At least FinishDatabaseQuery().
If you store the strings in an array or a list, then you have to run through them and compare each member with your string.
List:
Array:
Map:
An array needs to know how many elements.
Map looks easier and is fast, but it needs more resources and in this case only the key is used and not the content.
So maybe the list is what you want.
But it always depends on your needs...
Bernd
if the code above are complete snippets, then you have a few mistakes inside:
Trim() already removes all spaces from head and tail of a string.
So stripSpaces() is not needed.
Or if you mean all spaces, also inside the string, then you can use RemoveString()
instead of Trim().
If you use DatabaseQuery(), where is the rest? At least FinishDatabaseQuery().
If you store the strings in an array or a list, then you have to run through them and compare each member with your string.
List:
Code: Select all
NewList FruitList.s()
AddElement(FruitList())
FruitList() = "apple"
AddElement(FruitList())
FruitList() = "orange"
ForEach FruitList()
If FruitList() = item$
Debug "found"
Break ; to leave the loop
EndIf
Next
Code: Select all
Dim FruitArray.s(1)
FruitArray(0) = "apple"
FruitArray(1) = "orange"
For i = 0 To ArraySize(FruitArray())
If FruitArray(i) = item$
Debug "found"
Break
EndIf
Next i
Code: Select all
NewMap FruitMap.i()
FruitMap("apple")
FruitMap("orange")
If FindMapElement(FruitMap(), item$)
Debug "found"
EndIf
Map looks easier and is fast, but it needs more resources and in this case only the key is used and not the content.
So maybe the list is what you want.
But it always depends on your needs...
Bernd
Re: Comparing string gadget input
I will look at all the examples and use the best solution. I greatly appreciate the helpful snippets to learn from.
In my coding I have all data base queries set, finished and closes. As I mentioned the project works properly, however while doing a search for an "item" from either gadget the result would display no matter which window or gadget was being used. This is why I have been trying to make a list or an array to handle the result of the search in a specific gadget. I do not want the gadget to display anything other than the information it should be handling from that specific windows gadget.... fruit search showing only a fruit results from the fruit window.... vegetable showing only a veg search result within their own windows gadget use.
As it works now... it doesn't matter which window or gadget is used, either "Get1" or "Get2"... it would display the result of a veg search done while using the fruit gadget and vise versa. So by using one of your recommended methods this will restrict the displayed result to only those items that are within the list, array or map. (depending on which is used)
I greatly appreciate your help....
**DT2000**
In my coding I have all data base queries set, finished and closes. As I mentioned the project works properly, however while doing a search for an "item" from either gadget the result would display no matter which window or gadget was being used. This is why I have been trying to make a list or an array to handle the result of the search in a specific gadget. I do not want the gadget to display anything other than the information it should be handling from that specific windows gadget.... fruit search showing only a fruit results from the fruit window.... vegetable showing only a veg search result within their own windows gadget use.
As it works now... it doesn't matter which window or gadget is used, either "Get1" or "Get2"... it would display the result of a veg search done while using the fruit gadget and vise versa. So by using one of your recommended methods this will restrict the displayed result to only those items that are within the list, array or map. (depending on which is used)
I greatly appreciate your help....
**DT2000**
"Occasionally stumped.... But never defeated!"