Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Macro helpers wanted"

Macro helpers wanted

We're making a list of people able to give help with Cardbox macros.

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

Posted By Post

cardboss

13-Mar-2006 14:04

From time to time we get support requests that could easily be solved if someone spent a few minutes writing a ten-line macro. For example:

"I have a field that lists the years (1980, 1981, and so on) in which a person attended an annual event. Because I used check boxes to enter the data, the years aren't always in numerical order. I need to have a field in which they are in numerical order, preferably with commas as well as spaces between them. I have 700 records and I don't particularly want to edit them all by hand!"

We ourselves can't write macros-on-demand like this, any more than Microsoft will write you programs in the languages that they sell!

I'd like to establish a list (on the Cardbox) site of people who are willing to write short and simple macros, perhaps for a fixed price or perhaps in return for a charitable donation. It's not a question of spending a lot of time... often these micro-projects (which seem impossible to someone who's never programmed) may take only five minutes if you know what you are doing.

If you're interested in being included in that list, could you let me know, please, by responding to this message? You really don't have to be specially expert to be able to make a difference to someone.

There is a new page at http://www.cardbox.com/support/kb/vbscript.htm that lists help and resources for macro writing.

And if anyone does want to help with the specific macro I've used as an example, can you respond to this message as well?

Alex Maines

13-Mar-2006 22:39

Count me in....

AM

Charles Welling

16-Mar-2006 14:30

I'll join (for what I'm worth)
Charles

Charles Welling

19-Mar-2006 20:49

Well, here's a macro that will sort the field containing the years. The writing was not too hard, but the debugging took me a day or so. It appeared that the array (eachyear)in which the years are stored somehow terminated the macro when it appeared inside a "for next". This explains why I had to make the numbers of the two counters increase by hand. This eliminated the problem.

Use at your own risk :)
This macro can easily be turned into a macro that sorts the contents of any field, which of course only makes sense if the field does not contain long lines of free text. The two lines that have to be changed to make it sort a listing have been marked.

And yes, the sorting can be made faster if the loops are terminated when no swapping takes place anymore, but it is fast as it is and I didn't feel spending another minute adding the necessary lines.

Enjoy it.

Charles

**********

dim browse ' counter that browses through the records
dim str ' the string to work with
dim swap ' temp variable for swapping two years
dim arraysize ' how many years in the string
dim counter ' counter used for sorting
dim counter2 ' another counter used for sorting
dim whichfield ' speaks for itself

whichfield=UCASE(Inputbox("Which field to sort?"))

FirstRecord

for browse = 1 to RecordCount
str=FIELDS(whichfield)
eachyear=Split(str," ") ' for listings change into: eachyear=Split(str,CHR(10))
arraysize=0
for each item in eachyear
arraysize=arraysize+1
next

arraysize=arraysize-1

counter = 0
do while counter < arraysize
counter2 = 0
do while counter2 < arraysize
str2=eachyear(counter2+1)
if StrComp(eachyear(counter2),eachyear(counter2+1)) = 1 then
swap = eachyear(counter2)
eachyear(counter2) = eachyear(counter2+1)
eachyear(counter2+1) = swap
end if
counter2 = counter2 + 1
loop
counter = counter + 1
loop

EditRecord
FIELDS(whichfield)=Join(eachyear,", ") ' for listings change into: FIELDS(whichfield)=Join(eachyear,CHR(10))
SaveRecord
NextRecord
next

Charles Welling

19-Mar-2006 20:58

PS:
There's an obsolete line in the macro, which I forgot to delete after some testing:

str2=eachyear(counter2+1)

It can be safely deleted, but it will not any harm (in fact hardly anything at all) if it remains.

Alex Maines

22-Mar-2006 00:06

I am offering a service of writing macros to order. I can write macros for either version 2 or version 3. I also provide a conversion service for converting version 2 macros into version 3 format.

Anyone who would like to commission a macro should feel free to drop me a line. All jobs taken. As a rule, I work on an hourly rate basis, the rate fixed by the nature of your business and the complexity of the work. Small jobs are, naturally, gratis.

For anyone who previously approached me for conversion of their version 2 macros, I have drastically reduced my rates, so if you are still interested, please get in touch.

My contact details are posted under the consultancy section of the Cardbox website.

Regards

AM

Quick Reply

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

 
© 2010 Cardbox Software Limited   Home