DO12 - Scripting problem with dialog box

I have been trying to find an easy way to add to the document properties of the metadata fields of images. I have very little VB scripting ability, but after days of hacking through the Opus helpfiles and various internet resources I have come up with the following (probably very crude) VB script which does the job as far as it goes

Using the new dialog features of DO 12 I have created:


The code the form runs is:

@nodeselect dim copysymbol, tagger Function OnClick(ByRef ClickData) Set dlg = ClickData.Func.Dlg Dlg.template = "Metadata" Dlg.Show copysymbol = "© " + dlg.Control("copyright").Value tagger = "+" + dlg.Control("keyword").Value ClickData.Func.Command.RunCommand("SetAttr META ""copyright:" & copysymbol & """") ClickData.Func.Command.RunCommand("SetAttr META ""author:" & dlg.Control("photog").Value & """") ClickData.Func.Command.RunCommand("SetAttr META ""imagedesc:" & dlg.Control("caption").Value & """") ClickData.Func.Command.RunCommand("SetAttr META ""subject:" & dlg.Control("subject").Value & """") ClickData.Func.Command.RunCommand("SetAttr META ""title:" & dlg.Control("title").Value & """") ClickData.Func.Command.RunCommand("SetAttr META ""tags:" & tagger & """") DOpus.Output "Keywords " & Dlg.Control("keyword").Value End Function

Of course, the great problem is that should any field eg Copyright be empty when you submit the results of the form it wipes out what is in the copyright field of the current metadata on the image.

What I cannot figure out is how I can check whether the value of any box on the form is empty, and if it is,skip by the instruction to setAttr META for that field and move onto the next one, where I can run a similar test.

Can some scripting expert like Tbone help me with this problem? I would be very grateful

You can use the Len() function to see if the string is empty (it'll return 0 if it is).

Many thanks for the prompt reply. I am probably not making myself very clear about what my problem is.
I have worked out:

if dlg.Control("copyright").Value ="" Then
msgbox "WHOOPS!!"
Else
Msgbox "OK"
End If

What I am having the problem with is how, in place of the Msgbox box WHOOPS, I get the script to miss out the instruction to fill the copyright metadata field and move on to the next field. Obviously if there is text in the copyright field I can carry out the instruction in place of Msgbox OK.

I thought of labeling the instructions in the script and using GoTo LABEL to achieve the task, but I cannot get it to work at all.

If dlg.Control("copyright").Value <> "" Then Msgbox "OK" End If

Or

If Not (dlg.Control("copyright").Value = "") Then Msgbox "OK" End If

Gosh, you guys are fast...

That kinda solves my problem except that if there is no text in the copyright string I need the script to pass over the instruction to fill the copyright field and move on to (say) the photographer field, where I can start the text check process all over again.

It is this method I am really struggling with.

Put the instruction where the Msgbox is in the example.

@nodeselect dim copysymbol, tagger Function OnClick(ByRef ClickData) Set dlg = ClickData.Func.Dlg Dlg.template = "Metadata" Dlg.Show copysymbol = "© " + dlg.Control("copyright").Value tagger = "+" + dlg.Control("keyword").Value If Not (dlg.Control("copyright").Value = "") Then ClickData.Func.Command.RunCommand("SetAttr META ""copyright:" & copysymbol & """") End If ClickData.Func.Command.RunCommand("SetAttr META ""author:" & dlg.Control("photog").Value & """") ClickData.Func.Command.RunCommand("SetAttr META ""imagedesc:" & dlg.Control("caption").Value & """") ClickData.Func.Command.RunCommand("SetAttr META ""subject:" & dlg.Control("subject").Value & """") ClickData.Func.Command.RunCommand("SetAttr META ""title:" & dlg.Control("title").Value & """") ClickData.Func.Command.RunCommand("SetAttr META ""tags:" & tagger & """") msgbox "Author " & (Dlg.Control("author").Value) End Function

This gives an error

Error at line 16, position 1
Invalid procedure call or argument: 'dlg.Control' (0x800a0005)

Line 16 is nowhere near the part you just changed. Was that not happening before?

No if I remove the whole If Not statement the script works fine.

As soon as I re-instate it I get the error.

In case it helps this is the xml for the form

While I have been experimenting developing the script I seem to have run into problems using If and Label statements.

The only way I eventually got the script to run without errors was to gather the ouput from the dialog into variables and then use those variables as the input to the SetATTR META commands. @nodeselect dim copysymbol, tagger,author,caption,subject,title Function OnClick(ByRef ClickData) Set dlg = ClickData.Func.Dlg Dlg.template = "Metadata" Dlg.Show copysymbol = dlg.Control("copyright").Value caption = dlg.Control("caption").Value subject = dlg.Control("subject").Value title = dlg.Control ("title").Value author = dlg.Control("photog").Value tagger = dlg.Control("keyword").Value If Not copysymbol = ("") Then copysymbol = "© " + copysymbol ClickData.Func.Command.RunCommand("SetAttr META ""copyright:" & copysymbol & """") End If If Not author = ("") Then ClickData.Func.Command.RunCommand("SetAttr META ""author:" & author & """") End If If Not caption = ("") Then ClickData.Func.Command.RunCommand("SetAttr META ""imagedesc:" & caption & """") End If If Not subject = ("") Then ClickData.Func.Command.RunCommand("SetAttr META ""subject:" & subject & """") End If If Not title = ("") Then ClickData.Func.Command.RunCommand("SetAttr META ""title:" & title & """") End If If Not tagger = ("") Then tagger = "+" + dlg.Control("keyword").Value ClickData.Func.Command.RunCommand("SetAttr META ""tags:" & tagger & """") End If

Many thanks for all your help.

You didn't post the script that was actually causing an error, so it's hard to know what the problem could have been.

Basically, you need to use an If clause for each item of metadata, to test whether the control's value is empty or not. For example,

if Len(dlg.Control("photog").Value) > 0 Then ClickData.Func.Command.RunCommand("SetAttr META ""author:" & dlg.Control("photog").Value & """") End If


[code]@nodeselect
Function OnClick(ByRef ClickData)
Set dlg = ClickData.Func.Dlg
Dlg.template = "PDFMeta"
Dlg.Show
If Len(dlg.Control("comment").Value) > 0 Then
ClickData.Func.Command.RunCommand("SetAttr META ""comment:" & dlg.Control("commentPDF").Value & """")
End If
If Len(dlg.Control("keywords").Value) > 0 Then
ClickData.Func.Command.RunCommand("SetAttr META ""tags:" & dlg.Control("keywords").Value & """")
End If
End Function

[/code]

As you can see from the screenshot. Incorporating the code that Jon suggested throws up an error that does not seem to make much sense to me, but as I have said, I am no expert on VB, but line 5 position 2 seems to have nothing to do with dlg.control.

The problem could not be anything to do with hidden characters in the script, could it? I often work by doing a lot of cutting and pasting into scripts

If you use "@" modifiers like @deselect within the script code section, the line "counting" seems to be irritated and wrong in case of error.
It halso happened here, while there were no modifiers in the script code section/tab, but new ones were copied and pasted into the correct "Modifiers" tab.
Fake editing the Modifiers tab finally made DO recognize the correct number of lines there (looked like that at least).

So I guess that's what you are dealing with here, some kind of buglet. o) Notice, I'm still at beta4, did not manage to update yet. o(

What kind of hidden characters do you mean? As in non-printing Unicode characters?

(TBone beat me to it: The @nodeselect at the top belongs in the Modifiers tab, by the way.)

The indentation in your code is making it quite hard to read, also, and may be masking some other misunderstanding, perhaps. How well do you understand the basics of VBScript like If/Then/Else statements?

Moving the @nodeselect to the modifiers section cures the script line problem and I can see the logic of that, but it still does not get rid of the error, and that is my real problem

@auden
You use v12 beta5? The .value property is not available in versions prior to that iirc. You'd use .GetText() before beta5.
Maybe post the error with your code again, now that the line numbers are correct (hopefully), it's probably much easier to see what fails and why.

As you can see I am on Beta 5

This is the code with the error

[code] Function OnClick(ByRef ClickData)
Set dlg = ClickData.Func.Dlg
Dlg.template = "PDFMeta"
Dlg.Show
If Len (Dlg.Control ("commentPDF").Value) > 0 Then
ClickData.Func.Command.RunCommand("SetAttr META ""comment:" & dlg.Control("commentPDF").Value & """")
DOpus.Output "Return code = " & Dlg.result
End If
If Len (dlg.Control("keywords").Value) > 0 Then
ClickData.Func.Command.RunCommand("SetAttr META ""tags:" & dlg.Control("keywords").Value & """")
End If
End Function

<resources>
<resource name="PDFMeta" type="dialog">
	<dialog fontsize="10" height="129" lang="english" standard_buttons="ok,cancel" title="ENTER PDT or EPS METADATA" width="302">
		<control halign="left" height="8" name="Comment" title="Comment:" type="static" width="155" x="16" y="19" />
		<control halign="left" height="43" max="512" multiline="yes" name="CommentPDF" type="edit" width="218" x="16" y="27" />
		<control halign="left" height="8" name="static2" title="Keywords:" type="static" width="100" x="17" y="81" />
		<control halign="left" height="12" name="keywords" tip="Enter keywords" type="edit" width="264" x="17" y="92" />
	</dialog>
</resource>
[/code]

Any help would be appreciated




Maybe it's "comment" (wrong) vs. "Comment" (correct name)?
Don't remember if these control ids/names are case sensitive or not, if not, then you have something to fix. o)

I can confirm that changing comment to Comment makes no difference to the error message.

Maybe it is a bug