Home

Cardbox Talk

 

CardboxForumsCardbox Talk > "First macro: Await user input on search"

First macro: Await user input on search

How to pause a search, and await user to input value

Current user: [none]
Register / Log In · Help

Posted By Post

cristoayre

2-Feb-2015 11:50

This is my first post / first macro, (so be kind to me!)

I'm creating a database a novice can use, so I'm simplifying actions down to button presses. Here is what I have so far:

dim x
If SelectionLevel>0 then SelectionLevel=0 else SelectionLevel=0

Function InputBoxOrHalt()
x=InputBox("Enter any data about student","Student Search")
If x="" Then Halt
InputBoxOrHalt=Trim(x)
End Function

ActiveWindow.Select "",x

If the user has already searched for one student, the above will return them to the top level so they can search the entire database again, (rather than a sub set of previous search) The next part will then open a message box, and wait for them to enter their data. That data will be returned to variable "x", (added the dim so that X is global (??) )

(NB: for some reason, simply entering "SelectionLevel=0" on its own didn't seem to work)?

IN THEORY, this should then pass the data to the Select option ... but that's the point it fouls up. (I've a feeling it's something to do with converting x to a string as latter command works fine with ActiveWindow.Select "","Brown"

For what I'm trying to do with Cardbox, I may be a regular visitor to these pages.

My next task is something similar: Click a button, AND WAIT FOR A BARCODE TO BE SCANNED, and then completing a search action on a specific field. Got a feeling that's gonna involve a While routine to loop around awaiting for scanner to set a variable, and then jumping into search.

Another task: A VBScript initiated at startup to loop around checking the contents of a folder. (Hot folder) When a photo appears inside it, branching off to add a photo to a place holder in a format (template), then send it to print.

Seeing as I've had program less than 2wks, I don't half jump in at the deep end don't I???

bert

2-Feb-2015 12:57

Hi,
Your on the way! However, do not make it too difficult.
A function you use mostly when you want to repeat same action using other variables.
So that is how I do this:

SelectionLevel = 0 '"if" is here not needed: you can set the selectionlevel directly.

Input box:
A space in an inputbox line can frustrate if x = "" then...

So, please use this:
x=trim(InputBox("Enter any data about student","Student Search"))
If x="" Then Halt

I understand that you want to search in all fields? Otherwise to have to add a field name like this:
ActiveWindow.Select "FIELDNAME",x

Then there is another thing: if you search on "bert stortenbeker" in this macro (two terms), Cardbox searches on Bert as well as Stortenbeker. The space will function as OR. If you want to search using AND you have to replace the space to a space with a +.
Something like this:
x=trim(InputBox("Enter any data about student","Student Search"))
If x="" Then Halt
First to be sure, remove all double spaces :
x = Replace(x," ", " ") (of course, can also by while loop)
Then replace one space by a space and a +:
x = Replace(x," " +")
ActiveWindow.Select "FIELDNAME",x

Al alternative is search exact on what you type. If entered Bert Stortenbeker you can find this by putting quotes around it (just like Google) "Bert Stortenbeker". Do't like to explain this to a user? Write the quotes in your macro:

x=trim(InputBox("Enter any data about student","Student Search"))
If x="" Then Halt
x = """" & x & """"

The your Barcode:
Perhaps you can use the simple way by the Cardbox Macro Command
Pause "infotext",300,300.
The number are coordinates where the message is showed.
After it you can push the continue (or stop) button. This command gives you total back to Cardbox interface, you can continue the macro when you want.
Perhaps this can solve it?

The Photo: I advise you to download the electronic Vbs reference (or buy the advised book VBScript in a Nutshell):
http://www.microsoft.com/en-us/download/details.aspx?id=2764
There you can find how to read a folder content.
It is possible to add a photo in a record which you can print.
Read the (Macro) Help file of Cardbox. You can find most of your questions. It is detailed.
No problem!
Success
Bert

bert

2-Feb-2015 18:25

type error:
x = Replace(x," " +")

has to be
x = Replace(x," "," +")
regards
bert

cristoayre

4-Feb-2015 19:03

As it was my first macro, I copied the mid part "lock, stock and barrel" as they say from Cardbox manual. By using the apostrophe to remove things, I managed to discover that the Function wasn't needed. It was effectively jumping to Halt and ending macro as soon as it started. Also, the IF statement. For some reason, (probably a spelling error) it didn't run first time I input "SelectionLevel=0". But then I looked again, and thought "that statement's giving the same result whatever happens". So retyped it ... and it worked!

On my format layout, I've got one search button so they can search, firstname, surname, class etc (as you say "OR")plus another "deep search" button, (ie down level2,3 and 4) and another button to 'get out' of the deep search and get back to level 0 again. (I know there are menu shortcuts to do this already, but I'm building it for less tech savy to use) Also created a "New Record" and "Save Record" button. Cannot get a "quit" button to work, so they'll have to use the red "X" at top when editing to get out of screen.

** On a slight tangent, would be helpful if I could get a format for the edit record window, ie different colour background to let them know they're not on view record screen.

Not put my brain in gear properly yet re barcode box. Ideally I want it to close / search automatically, so I'm thinking of adding a loop to the effect "Check the old_data variable with current value. Has the (input) box changed? Yes? Record the input in a old_data variable, pause 3 sec then go back to top. If no, put the data into a field. If the barcode number is input by hand (as per my test as I don't have a scanner) by pausing a few seconds, when it does a compare, the typed in data will be different to stored data, and it will loop again. When the results don't change, it will move data into the search field, and 'click' the OK button.

One quick bit re photo. They're not actually stored in the record. It stays in a folder away from Cardbox. Rather, it's going to be like a mailmerge, but instead of picking data from a field to merge, the macro will (hopefully) seek the image data in the folder, and put it into a field on a format page, then send THAT to the printer.

It's gonna be difficult no doubt, but I shall keep on with it as I don't like things to beat me if I can help it. May take a lot of head scratching, but eventually I get things to work!

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home