Cardbox > Forums > Macros and Programming > "Interface macro"
Interface macro
Macro for researching into several files |
Current user: [none] |
| Posted By | Post |
|---|---|
Nadjan | 7-May-2007 07:06 I would like to create a kind of an interface program so that, just by introducing a request in a dialog box, a macro would search it into several files. The macro I'm trying to design is actually opening the requested file but does not open the search dialog box. Is it possible to get or just an utopy? Thanx for helping. |
Charles Welling | 7-May-2007 08:39 Yes, it is possible. Assuming the user opens no files by himself, you could turn your macro into a startup macro (look under Options) which runs as soon as Cardbox is started. The first step would be to display an INPUTBOX to find out what the user wants to search: searchwhat = InputBox("Enter your question:", "Search") You are advised to process the variable "searchwhat" to see if it is a valid search string before proceeding. Then open the first database, using the following lines (replace the filenames with your own): on error resume next This part tries to activate the window with the first database. If that database has not yet been opened, this will result in an error in which case Cardbox will open the file. Otherwise it will just activate the window. The second "Activate" may look superfluous, but it just makes sure that the right window is active. Cardbox then searches for the contents of the variable "searchwhat" in that database. Please note that this is just a very crude example. Your final macro could be and should be much more sophisticated, but these are the basics. |
Charles Welling | 7-May-2007 13:52 In addition to my previous answer I'd like to point out another way of solving your problem. It is an "old" solution for doing exactly what you want, without the need of using a macro, although macros may be used to automate several steps. The solution is based on relational searching. The idea is that you should create a simple database, containing a one-line field for the question and if necessary a second field to choose a field from (dropdown list!). Let's call this database INTERFACE. This database should have relational links to the databases you want to search. The user enters a question into INTERFACE and saves the record. Of course you can use macros and buttons to make this easier. For instance, a button could make a new record, another could be used to save it. Another advantage is that you would have a good idea of what your users try to search, because their questions would be kept (until you delete them). |
Nadjan | 8-May-2007 14:27 The problem with the macro is that it does open the so-called "Database1" but does not look for the matching term introduced in the dialog box (or inputbox) in the requested field. How can I get it? |
Charles Welling | 9-May-2007 05:20 To make absolutely sure, I copied the example to one of my own databases and it works. You say that the database is opened so the only line in which something can go wrong is: Cardbox.Select "MYFIELD", searchwhat You should of course change "MYFIELD" to whatever field you wish to use! If "MYFIELD" doesn't exist in your database, and I'm fairly sure it doesn't, no selection will be made. |
Nadjan | 10-May-2007 08:23 Of course I did change "MYFIELD" to the field I want to use, it's quite obvious, but there's something wrong with the macros in general. For example, I've copied all the macros I had in Cardbox 2.0 and pasted them in Cardbox 3.0: they did work in the former version but not in the new one! Strange, isn't it? |
Charles Welling | 10-May-2007 10:01 I'm sorry to disappoint you, but there's nothing wrong with the macros. The macro system in Cardbox3 is totally different from the old one and it is explicitly stated in all documentation that any macros from Cardbox2 will have to be re-recorded or rewritten from scratch. So the old macros are never going to work in Cardbox3. Did you try my example as I sent it, apart from the obvious modifications, or did you add some lines yourself? It is possible that errors that are not recognized by the system may stop a macro. If you did, remove or comment out your own lines and try the macro again. When it works, and it should, add your own lines bit by bit to see where and when things stop working. |
Nadjan | 10-May-2007 14:27 Sorry for insisting but I did exactly what you told me to do and it did work... once! Nevertheless, when I tried to repeat the experience, it failed. The current score is: failures 10, success 1. It results totally incomprehensible. |
Charles Welling | 11-May-2007 18:57 Please feel free to insist until this is sorted out. Could you tell me the exact steps you took when the macro worked? What I would like to know is: - did the macro work immediately, i.e. on your first try AND If so, did you do anything at all in between, apart from running the macro again? And last (for the moment): you say "it failed". Could you be more specific? Did it produce an error message, did the macro work but did it fail to make the right selection or.... etc. |