Cardbox Talk


CardboxForumsCardbox Talk > "Are Formats / Windows the same thing?"

Are Formats / Windows the same thing?

When you change view, are you (programatically speaking) swithcing to a new window?

Posted By Post


8-Feb-2015 14:03

I created a database (Photo Database) I then created a new format, which became (Photo Database #2) Cannot see a way to rename that as it's part of the same database.

I've tried various options from the manual, but none appear to allow access to that second "window"
The second format/Window (#2) is laid out as a template within the print boundaries. This is comprised of one record, and one mergebox, the latter of which is correctly pulling data from format/page1. When sent to printer, it prints as expected.

Using macro / VBS, I want to access that second (#2) page/format, replace the record with an image from an external folder, and send format to the printer ... if I could find a way to access that record in the second window! (Should be possible to replace the field with image as you can change the data in most field via macros etc)

**I also tried recording jumping to external folder, copying to clipboard, returning to app and pasting into record ... only whilst the paste option is there, and the cursor flashes in field, it won't allow me to paste into record!! All the macro said after all this action was "Application:WindowState Normal" (Properties of field is NOT Read Only)

*** Also manual says, go to menu, load as object. Great. Apart from only showing two types,(Text and Rich Text) when you select "*.*" it loads it as data!!(ie first few lines show Exif keyword)

**** "Or you can use CTRl+R ..." only that does absolutely nothing if on view record or edit record!

As you can no doubt tell, bit frustrated with this today!


8-Feb-2015 14:16

If you read the manual you could know that #2 means that you opene a database with same name a second time in your window.
Please read it first instead become frustrated.


8-Feb-2015 19:05

So I've not actually set up a second window? Will have to experiment with that tommorrow. Still don't know why pictures won't work, and the image button mentioned in manual no longer seems to exist


8-Feb-2015 20:54

I repeat: read the manual :-(
If you had read it, you knew the answer was to find on page 106


9-Feb-2015 09:53

I did read manuals, and managed to get what I THOUGHT was two windows showing. (ie reporting as 2 windows under Windows menu, and 2 windows showing in workspace) However, after more research, it would seem that the "New Window" option does not actually always mean a completely 'new window' if clicked from within an existing database. It means a copy of the first window renamed to "#2" This might be programatically the same window as opposed to a second window as per example of copying from one database to another in manual! I will have to experiment, and see if using WindowNumber variable allows me to access the fields in second window (#2) To open a TRUE New Window is to open another database.

I'm also wondering if after about 10 days it might be academic anyway as the program simply doesn't like images. Try as the manual says, and insert picture as object ... but that only permits "txt" and "rtf" files. Select "*.*", and it loads it as ASCII rather than binary for images. It allows you to add images to page design, but it doesn't allow you to put pictures in records fields. Copy & Paste. Nope: Only prints ASCII again!

I thought I'd have a look at sample "PhotoArchive" database button which says something like "You can now add images to this menu. Select from menu, or use Ctrl+N" or file->import" ... except that ALL these option are greyed out, and reports the file as Read Only. (Just looked at macros, and see this demo only works if connected to an S3 account to save the images, so you can't get that running either)

Had a look at "Photos" which DOES have pictures in. Thought I'd have a look at the format to see if I'd done anything wrong, ie setting the format of the record to binary or something. But that's been set to read only, and you cannot interogate the format!

Maybe when the final free rather than paid version was released, the option to use pictures was also removed.

The window convention is a minor 'niggle' which I can get around given time. The fact that I cannot get photos to work on local machine is more worrying


9-Feb-2015 10:01

I was half right, but going about it wrong way. You do need to set the format of the field to binary ... but in the format menu, this is also greyed out. Appears that the answer is to set it from the NATIVE menu. (Must remember that format views are only 'read only' versions of the native which actualy sets things)

Not tried it yet, but wanted to get back here quick before you posted to forum. I'm a bit more positive now!


9-Feb-2015 11:03

There is a simple working photo example available on http://cardbox.magix.net.
If you first read, then implementing, it generates solutions by itself in stead of questions about many very basic Cardbox things.


9-Feb-2015 12:39

Sorry. I sense I'm annoying you! Whilst they might be "very basic Cardbox things" to someone who has experience of using it, to someone who is new to the program (10 days), and also new to all things Visual Basic, it's very challenging to say the least.

**I'm in two minds about this next part now. I thought I might send you a screenshot of my progress so far:

So now =MY= challenge is to learn how to use an external script to take an image from a folder, and place into a record, and then find out how to get the external script to print a format window that's not displayed. I seem to have exhausted your help at this time, but thanks for what help you have given.


9-Feb-2015 15:43

You can make a vbs script that starts a "hidden" Cardbox.
Again I have to assign you to the Cardbox HELP: search for "Getting and creating Cardbox objects." In a Cardbox object you can read your picture, add it to the database and print it using a fitted format for your print.
But I have to say again: if you want to program - even using Visual Basic Script, it is better first to read about it and start programming with "Hello World" things in stead of programming by trial and error and then scream "it does not work".
That does not make friends and generates not much support.


9-Feb-2015 17:58

I did read the manuals ... but I'm afraid I "cram read". I went through the whole manual in one marathon 4.5hr session, so some sunk in and some didn't. Then the next day I went through the macros, and again - having learned PERL by trial and error too - some of it made sense, and some went over my head. I agree, I should really sit down and read through it SLOWLY again, but - as ever - I try to run before I can walk!

At least with PERL, if the script is wrong, you get an Internal Server Error, and can check an error log to see what's wrong. (Before you say it, I remember reading there is an option to write a log, but I think that's to record what the script's variables are set to rather than error reports) But when using the Cardbox macro, or a VBS written in a text editor, if it's wrong - simply nothing appears to happens! I actually anticipate that loud "DONG!" with an error prompt. At least that points to the line where the error is.

I heed what you say about the starting a second application of Cardbox in the background, and it's an approach I'll look at if I can't find an alternative. My current thought process is I can simply send the image directly to the record in current ActiveWindow so that it appears in that field top right - which will update the field in second format layout of that record. If "push comes to shove" I'll then simply use a macro to swap formats, and then print the ActiveWindow

Again, thanks for your patience


9-Feb-2015 18:43

You missed again a first step in Cardbox Help:
"Introduction to macros and programming"
Something is written there about the Microsoft Scrip Debugger.
Written for VBS, for Cardbox a useful tool.


10-Feb-2015 10:01

So that help prompt says You can use Microsoft Script Debugger. (Will have to check that later and check it's not one of the items Microsoft now charge developers to use!)

Well, I had a go at pulling various parts from manual, and I got this. Probably a "scholbox howler" in there somewhere, but the "ReadFromFile" is still complaining. Yet to me, it looks as it is in book. And Googling the error 800A0401 says there's a syntax error. But what (Line 9 Char30)


'Option Explicit
Dim cbx,win,imgs,ReadImg,recc
Set cbx=GetObject(,"Cardbox.Application")' Gets data for Cardbox application, and puts it in cbx
Set recc=cbx.ActiveWindow.ActiveRecord' The currently active record to edit within active window
Set win=cbx.ActiveWindow.ActiveRecord.Fields("PHOTO")' Within Active Window, look at the currently Active Record to find field PHOTO that contains image. (May not be needed)
Set imgs=cbx.ActiveWindow.ActiveRecord.Images' Find all the images within the record

Set fso = CreateObject("Scripting.FileSystemObject")
'Set ReadImg=fso.ReadFromFile "C:\Users\ChrisBrown\Desktop\PhotoBooth\Hot\test.jpg"
'Set ReadImg=imgs.ReadFromFile "C:\Users\ChrisBrown\Desktop\PhotoBooth\Hot\test.jpg"

'' EVERY TIME, THIS RESPONDS "End of statement required ine 9 Char 30
'' Yet this is the syntax shown in help / guides etc
'' So what gives?
'' I have tried both fso - probably wrong as creates a new object first and imgs as the object. Neither work

'Set imgs(0)=img' Set img(0)
MsgBox("OK to here"&Count)

'Set imgs=ActiveRecord.Images (As per line 5)
'imgs.ReadFromFile "d:\import.gif"
'Set img=imgs(imgs.Count) ' get the last image in 'imgs'

Thought I'd try copy and paste from edit window. That ADDS an image rather than replace, (so have to paste, and then delete original?) Thought I'd do as manual suggests, and record a macro to see key strokes ... but of course, the right click to access commands for "LoadFromFile" etc are not available whilst recording

Oh well


10-Feb-2015 11:56

see a working read images example on http://cardbox.magix.net
(dont need a fso using the Cardbox function for adding an image in your record)

Mary Doyle

10-Feb-2015 12:38

I wish I had learnt all about Cardbox AND Vbscript in 10 days! Learning by example is a great way to learn, but not on its own. To program Cardbox with Vsbscript I would suggest that you first need to understand Cardbox itself. Then you will be better able to understand examples. The manual and help files are actually excellent, but speed reading them will only give you an overview. I think you need to go through the manual more slowly and get a real understanding of how things work. It is actually a brilliant program and very good for managing photos. Sometimes less is more - in the long run.
Good luck.



10-Feb-2015 16:57

I agree with you 100% Mary. It's a very comprehensive program, and has more 'bells and whistles' than my program actually needs at this stage. Agree too I need to study the manuals and help files line by line. But unlike learning Perl where you can see programs other people have developed, and see the inner workings, and 'pinch' lines of code to use in your own program, it's a bit more 'hidden' in terms of Cardbox and VBScript. When using PERL, (I created five websites and four stand alone programs over about 10 years) you can turn to places like Stackoverflow, or even support of web hosting company to give you pointers on where PERL/UNIX code is wrong, but since Cardbox is a much smaller community, there is less help on the net.

Please, don't read this as though I'm "knocking" you or Bert; I'm grateful for any help to guide me. I just wish it was more a case of "No, partA is wrong. What you really need to do is XYZ, and change partB to this. Find details about this on pageXX of the macro guide or Help point 999"

Bert: You suggested the Microsoft Debugger. That's now been depreciated, and only works as far as the XP software anyway. (I'm on Windows7) The other option was in Visual Studio. I might try running thro Internet Explorer to see if that has a debug option. Shame Firefox cannot support VBScript, but then I believe the latter is coded by Microsoft.

Anyway, time to look at magix.net


10-Feb-2015 17:35

Perl is totally not comparable to Cardbox. Perl is developer tool. Cardbox is a user application.
Of course I could tell you do this, do that. But if you are not yet familiar with the basic things of the user program, is first help: read the manual + help because you did a lot of things wrong which are clearly written in the books and the help. What can I do better than tell you that is all to read. For me it is a bridge too far the program anothers application. I do that only if there is an agreement for such a thing.

Then: MS Script debugger runs in Win 7 also win 8(.1) even 64 bit. However: MS install things that disturb their own Script Debugger.
If you have problems with the debugger, try to kill mdm.exe (MS Machine Debug Manager). When switched off, my experience the debugger works ok - also with Cardbox.


10-Feb-2015 18:24

Just briefly looked through the "ImportImages" macro, which may be a starting point (Thanks) ... One point. It's initiated from a push button running a macro from WITHIN Cardbox. I need everything to be command based from an external VBScript so it happens automatically in the background. Just a case of getting my head around the "object" syntax, and then adding "xyz." name of object to start of commands shown.

Also, this reads images in sequencially, (which of course is what it's designed to do). With my database, I'm on a pre-selected record, and need to replace that image. (Simple enough: Go into Edit mode/Delete Current Photo/Load From File. Found that simply giving LoadFromFile appends it to record) May be able to shorten that sequence if read directly into images(0) or similar command.

You said I don't need the fso part. I'll remove that. (Case of 'borrowing' from another script to see if it fits) Is the syntax correct on the ReadFromFile line? It keeps failing saying that it's missing "end of statement" at char 30 (the space at end of command / start of path)
Set ReadImg=imgs.ReadFromFile "C:\Users\ChrisBrown\Desktop\PhotoBooth\Hot\test.jpg"

I've got it down to a flow diagram of what I need to do from the external script.

Edit Record
GoToField "PHOTO"
Delete image
Save Record

Of course, some of those are macro commands, and I shall be using the direct VBS command.

Thanks. Off to have a deeper look at the macro to see what gems I can discover


10-Feb-2015 18:37

Sorry, don't want us to decend into the world of "Trolling", but when I made the analogy with PERL, I was referring to the syntax of VBScript, such as "For..Next", "If..Then..Else" loops being very similar, assigning data to variables, (var $a=1 in PERL, Set a=1 in VBS)

I understand you don't want to write another person's code. That's understandable, as if you did that for one person, where would you draw the line? (Unless you get paid for it. And I think it's good of you to devote so much time to this forum anyway) Plus, you don't learn if it's done for you.

Re the debugger, I was only going by what was written on the Microsoft site re being depreciated, and not being compatable from XP. Thanks for the insight that it will work. Can but give it a try. If it don't work, I simply uninstall.


10-Feb-2015 22:17

Try this:
set rec = cbx.ActiveWindow.ActiveRecord
Set imgs= arec.Images
imgs.Remove 1
imgs.ReadFromFile "yourfilename"


10-Feb-2015 23:58

type error:
set arec = cbx.ActiveWindow.ActiveRecord
Set imgs= arec.Images
imgs.Remove 1
imgs.ReadFromFile "yourfilename"


11-Feb-2015 14:19

Thanks for the code snippets. I can understand how they're working ... and they might just be the answer.

So far, I might have been working "back to front", and trying to get an external script to "push" data into Cardbox, mainly because I needed to run a DO loop - which I don't think Cardbox would like!

But in a "flash of inspiration" I'm wondering if between "img.Remove 1" and "ReadFromFile", I insert a Run command. This will then trigger the external DO loop, and pause the macro until the external script signals OK to continue. I appreciate that whilst waiting for the signal, Cardbox would be unable to do anything, but that's no real problem. If it was, I could perhaps start a second copy of Cardbox, and run the command from there. (Get one thing right first!)

Incidentally, is there a timeout limit on how long a run command will wait for the script being called to return its data?

On a tangent, I've just been doing some reading ("Great!" says Bert!) Am I correct in saying that in order to use Cardbox commands in an external script, they have to be set as CONST at the top? If that is the case, then my original script would NEVER work anyway as "cbxReadFromFile" is not one of the codes listed in the manual.

Similarly - if the above is true - there appears to be no cbxEditRecord either, so I don't think I could use an external VBScript to force a Cardbox record into edit mode either.

I did find one command that MIGHT be of use ... but couldn't find any details in help or manual:
const cbxImageOverwriteFile = 1

I think between us we're getting there!


11-Feb-2015 15:29

"They might be..." > they AREe the answer on what YOU wrote.
Loops? Why should Cardbox does not like loops? If VBS does'nt like such a thing, of course Cardbox macro's will not like it. VBS has no trouble with loops. It is a feature of it.
Timeout? Prgram it rigt. There is something as a "sleep" command. So, you can make it as long as you like.
Constants? In the Help page for macro commands there is a link to constants. I really think you can use these. Just a thought.
Const at the top? Possible, not necessary. You can use also the numbers when needed in stead of the cbx... constants in vbs.


12-Feb-2015 13:29

Ohh ...

When I said "They might be ...", I wasn't being insulting to your knowledge. What I didn't express very well was that after all the runaround I've given you on this thread, and various incorrect methods I've suggested, we could have now reached a working plan and thus might / could have the solution.

Why do I think it doesn't like loops. Put it down to my coding inability at the time. I tried it a few times, and it just wouldn't work. (Just tried it again, and For..Next worked fine!!)

Timeout. You missed my point I'm afraid. I know there is the sleep command; I use that within my script in a "Do Until" loop. But - to use a similarly - when you use FTP and the server doesn't get any data for a few minutes - it closes the connection. I wondered if there might be a similar constraint when Cardbox called an external macro. If it didn't get any response within say 2mins, it would kill the process. (Indirectly, I found that scripts CAN be set to "die" after a limited time because I accidently set my wscript to quit after 1 sec when finished, so when an error did pop up, the program quit before I'd had time to read the prompt. Took me a while to get that property disabled again)

Yes, I did read the table of constants - which is how I found the cbxImageOverwriteFile which I could find nothing about. "You can use also the numbers when needed in stead of the cbx ..." Don't even know where to find the numbers, or how I'd use them. But let's not go down that road; save that for when I need them

By the way, is "arec.save=" a typo?


12-Feb-2015 15:28

- arec.save without = (in first) it was right of course. Unwanted type error.
- the snippet I wrote you can also use in a vbs. If they does not work, then there are objects not right defined.
- constants: look in help Index of methods and properties. 3rd line: List of constants (Visual Basic format). Never learned reading the whole screen?
- ff you give Cardbox the task to wait for something you have programmed, it will wait. I cannot imagine why Cardbox should not do this. If not, your code is not ok.

© 2010 Cardbox Software Limited   Home