Accessing Database Fields From Vbscript 追蹤

Legacy Poster

Hi Folks,

   Running BT 9.4 SR3


   I have a very simple label, that gets its data from a tab-delimited text file. The file has multiple records, but only 1 field per record, the location number. I want to print the human readable version of the location, the barcode version of the location and then I want to print an up arrow or down arrow based on a portion of the location.


   example location: 705-15-3


   If the last digit is a 1, I want to print the down arrow, if the last digit is greater than 1, print the up arrow.


   I am getting the arrow from the Text (from Symbol font character) and setting it in Screen Data.


   I have created the label object, and have tried various vbscript commands to get the last digit from the location, and then tried various ways of modifying "Value" to get this to work. I know that I am having trouble with getting the location from the database.


   In my label definition, under Database connection setup I see

      All Databases

         TextFile 1


               Field 1


   In other places, I see this field referred to as "LOCS.Field 1", note the space between "d" and "1".


   For a simple test, I created a text field, populated the sample data with 99, then wrote vbscript somewhat like the following...


   dim loc, currentValue, shelf

   currentValue = Value (if I do not include this line, the editor complains about not accessing Value)

   loc = Field("LOCS.Field 1")


   shelf = Right(loc,1)

   if shelf = 1 then

      Value = 88

   end if


   Doing a test print, nothing prints in this position on the label, but the text version and the bc version of the data do print correctly. There are no complaints when saving the code for the label or when the test print runs. If I vary the code "loc = Field("LOCS.Field 1"), removing quotes, getting rid of the space between "d" and "1", etc, I get errors when trying to print the label, thus, I think I am referencing the field correctly.


   Searching the forums for "field(" got me lots of hits... 137 I think, but I could find nothing that really addressed the correct syntax for referencing database fields... everyone has x = Field(<fieldname>), some with, some without quotes. Can someone point me to documentation or whitepapers that talks about using VBscript, embedded in a BT label, to access the current fields on the label, and the fields in the referenced database?


   Next issue is getting the arrow to appear at the correct time.


   My first thought was to create 2 text objects, having code in each one that would set it Value to "" when the shelf number was not correct, causing one arrow object to print, while the other would not.

   up arrow object

*  do not print the up arrow when this is shelf 1

   if shelf = "1" then

      Value = ""

   end if


   down arrow object

*  do not print the down arrow if shelf is greater than 1

   shelf = CInt(shelf)

   if shelf > 1 then

      Value = ""

   end if


   Not elegant, but should work. I don't think this logic is working, and I get strange things happening in the design interface. If I set Value to "", rather than display the arrow, I see many characters from the font symbol set. Maybe that just the way it's supposed to work... don't know.


   If I could I would rather do the following.....

      create 1 text (from Symbol font character) object

      write vb code that says

      if shelf = 1 then

         Value = down arrow character


         Value = up arrow character

      end if


      Problem is that I do not know a way to reference the font set, and the correct character to get this to happen.


   Any wild thoughts that you have on these issue would be appreciated.... humor, even at my expense is also allowed!!


thanx in advance,


1 意見

Fernando Ramos Miracle
評論操作 永久連結

Hello Ron,


*Could you attach a simple label with what you are trying to do, it might be easier to guide you in the right direction.


1. Regarding the capture of the data, please note that if you are retrieving the information from a text file, it will be considered as text. As such, a comparison like "If Value = 2 Then..." won't work because you are comparing a string with an integer type value.


Being that the case your code should work by writing the following:


Dim shelf


shelf = Right(Field("LOCS.Field 1"),1)

If shelf = "1" Then

      Value = 88

End if


The main difference between your code and the one above is that I've added quotes to the [1] value in the "If...Then" statement. regarding the rest I've only removed the variables that I think might be redundant.


Also please note that the message you get, is because you are not using the actual value of the data source, and you can of course choose to ignore it (it's a warning, not an error).


2. Although setting the value of the data source to "" could certainly do the trick your second option seems much more interesting. To get that precise symbol you'll need to figure out to which ASCII character they correspond (when using the Symbols font). As a test I've used double arrows, the upper one is 223 and the lower one is 224 ASCII code. This way your code would look as follows:


Dim shelf


shelf = Right(Field("LOCS.Field 1"),1)


If shelf = "1" Then

  Value = Chr(223)


  Value = Chr(224)

End If


The Chr() command will get you the ASCII value of the code you enter. Note that the above example will only work on a text object using the Symbols font.