'instr@ Function Follow

0
Avatar
Legacy Poster

I am trying to use the VBScript InStr function to determine in a named sub-string the occurence of a comma character. If found within the string I would then like to manipulate the PrintVisibilty of another label object based (Text field) on this occurence.

 

I have so far come up with this VBScript outline which I think is on the right lines, but I am having problems with the syntax

 

If InStr ("BT_INV_OW_NO",",") <0 Then

Format.Objects ("Text 1") .PrintVisibility = True

Else

Format.Objects ("Text 1") .Printvisibility = False

End If

 

The sub-string BT_INV_OW_NO is obtained from an external database

 

Any help on the above would be much appreciated?

2 comments

0
Avatar
Fernando Ramos Miracle
Moderator
Comment actions Permalink

1. Firstly please note that in order to modify an objects property (such as "Visibility") you need to do it from the Document level VB Script accessible from the "File>BarTender Document Options..." dialog, under the "VB Scripting" tab. Also note that you'll need at least the Automation edition of BarTender to use this VB Script.

 

2. Note that another option to change the visibility of an object is to render its data sources' value empty. For instance a text or barcode object with its data source value as "" won't print. Note that you don't need the document level VB script to change a data source value.

 

3. In order to reference the value of the "BT_INV_OW_NO" named data source (or sub-string) you'll need to use the complete reference, only using its name is legacy from older version and might cause problems:

 

Format.NamedSubStrings("BT_INV_OW_NO").Value 

 

*In your code you are actually analyzing the string "BT_INV_OW_NO" not the named sub-string with that name.

 

4. Another option if the data is coming from a database field is to use its direct reference: Field("<FieldName>"), instead of sourcing it from a named sub-string.

 

5. Finally please note that the InStr() can take values only from 0 onwards (positive values) so your If...Then statement will always be false. If you wish to evaluate when the specified character is not on the data use "<1" or "=0".

0
Avatar
Legacy Poster
Comment actions Permalink

Hi,

 

Thank you for the information above

 

I did have to extend the functionality of the requirement to look for other sets of variables instead of just the coma character. I think I have managed to get round this problem with the following code, which is executed at document level with the VBScript placed in the OnNewRecord section. Here is the code I came up with, which seems to work, albeit a bit long winded:-

 

Dim SearchString, SearchCH, SearchHB, SearchPO, SearchSFG, ValueCH, ValueHB, ValuePO, ValueSFG

SearchString = Format.NamedSubStrings("BT_INV_OW_NO").Value

SearchCH ="CH"

SearchHB ="HB"

SearchPO ="PO"

SearchSFG ="SFG"

If Instr (1,SearchString,SearchCH,1)>0 Then

ValueCH = "ADDON"

ElseIf Instr (1,SearchString,SearchHB,1)>0 Then

ValueHB = "ADDON"

ElseIf Instr (1,SearchString,SearchPO,1)>0 Then

ValuePO = "ADDON"

ElseIf Instr (1,SearchString,SearchSFG,1)>0 Then

ValueSFG = "ADDON"

End If

If ValueCH = "ADDON" or ValueHB = "ADDON" or ValuePO = "ADDON" or ValueSFG = "ADDON" Then

Format.Objects ("Text 44").PrintVisibility=True

Else

Format.Objects ("Text 44").PrintVisibility=False

End If

 

Any comments for refinement would be very welcome?

 

Thanks

Please sign in to leave a comment.