Add barcode 128 to an SSRS form
Posted in blog

Add barcode 128 to an SSRS form

BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88
BPJS88

klaim freebet khusus untuk pengguna baru di situs ini

If you have a need to display information about the current environment on a dashboard then you can use the following in-built variable names to add to a calculated field in a BAQ.

VariableSteps:
1. Download the free code 128 font from here: http://jtbarton.com/Barcodes/BarcodeStringBuilderExample.aspx
2. Add this to the fonts on the SSRS Database server (you may need to reboot this server before it recognises the font.
3. Edit the SSRS form you want to add the barcode to using the Microsoft Report Builder program.
4. Add following code to “code” section of Page properties.

Machine generated alternative text:
Properties
Code
Data Only
OataEIem entNam
OataEIementStyIe Attribute
Data Schema
DataTran sform

Code

Public Shared Function StringToBarcode128(value As String) As String

‘ Parameters : a string

‘ Return : a string which give the bar code when it is dispayed with CODE128.TTF font

‘ : an empty string if the supplied parameter is no good

Dim charPos As Integer, minCharPos As Integer

Dim currentChar As Integer, checksum As Integer

Dim isTableB As Boolean = True

Dim returnValue As String = String.Empty

If IsValid(value) then ‘ Check for all valid ascii characters

charPos = 0

While charPos < value.Length

If isTableB Then ‘ See if interesting to switch to table C, yes for 4 digits at start or end, else if 6 digits

If charPos = 0 OrElse charPos + 4 = value.Length Then

minCharPos = 4

Else

minCharPos = 6

End If

minCharPos = IsNumber(value, charPos, minCharPos)

If minCharPos < 0 Then ‘ Choice table C

If charPos = 0 Then ‘ Starting with table C

returnValue = chr(205).ToString()

Else ‘ Switch to table C

returnValue = returnValue & chr(199).ToString()

End If

isTableB = False

Else

If charPos = 0 Then ‘ Starting with table B

returnValue = chr(204).ToString()

End If

End If

End If

If Not isTableB Then ‘ We are on table C, try to process 2 digits

minCharPos = 2

minCharPos = IsNumber(value, charPos, minCharPos)

If minCharPos < 0 Then ‘ OK for 2 digits, process it

currentChar = Int32.Parse(value.Substring(charPos, 2))

If currentChar < 95 then

currentChar = currentChar + 32

else

currentChar = currentChar + 100

end if

returnValue = returnValue & chr(currentChar)

charPos = charPos + 2

Else ‘ We haven’t 2 digits, switch to table B

returnValue = returnValue & chr(200)

isTableB = True

End If

End If

If isTableB Then ‘ Process 1 digit with table B

returnValue = returnValue & value.Substring(charPos, 1)

charPos = charPos + 1

End If

End While

checksum = CalcCheckSum(returnValue)

returnValue = (returnValue & chr(checksum)) + chr(206) ‘ Add the checksum and the STOP

End If

Return returnValue

End Function

Public Shared Function CalcCheckSum(Value as string) as integer

dim checksum as integer = 0

dim currentChar as integer = 0

For i As Integer = 0 To Value.Length – 1

currentChar = Asc(Value.Substring(i, 1))

If currentChar < 127 then

currentChar = currentChar – 32

else

currentChar = currentChar – 100

end if

If i = 0 Then

checksum = currentChar

Else

checksum = (checksum + (i * currentChar)) Mod 103

End If

Next

If checksum < 95 then

checksum = checksum + 32

else

checksum = checksum + 100 ‘ Calculation of the checksum ASCII code

end if

return checksum

end function

Public Shared Function IsValid(value as string) as boolean

if value.Length = 0 then

return false

end if

dim c as string

for i as integer = 0 to value.Length – 1

c = value.Substring(i,1)

if c < chr(32) or c > chr(126) then

return false

end if

next

return true

End Function

Public Shared Function IsNumber(InputValue As String, CharPos As Integer, MinCharPos As Integer) As Integer

‘ if the MinCharPos characters from CharPos are numeric, then MinCharPos = -1

MinCharPos = MinCharPos – 1

If CharPos + MinCharPos < InputValue.Length Then While MinCharPos >= 0

If Asc(Char.Parse(InputValue.Substring(CharPos + MinCharPos, 1))) < 48 Or Asc(Char.Parse(InputValue.Substring(CharPos + MinCharPos, 1))) > 57 Then

Exit While

End If

MinCharPos = MinCharPos – 1

End While

End If

Return MinCharPos

End Function

5. Create a field, or use an existing field and use the following code in the formula field.


Machine generated alternative text:
Finished Goods Part Number
[Part Num]
Text Box
Cut
Copy
Paste
Delete
Select
Expression…
Text Box Properties…
Tablix
Insert Column
Insert Row
Delete Columns
Delete Rows
Add Group
ROW Group
Add Total
Insert

=code.StringToBarcode128(value)

Like this:
Machine generated alternative text:
Expression
Set expression for: Wue
= code.StringToBarcode
Category.
Constants
Built-in Fields
Parameters
Fields (DataSet2)
Datasets
Operators
Common Functions
Help
Item:
No constants are available for
this property.
Cancel

6. Change the font for the field to the BarCode128 font.

Happy coding!

Value
@@servername
The database server’s machine name
@@servicename
The database Instance
DB_NAME()
Database name
HOST_NAME()
The database client’s machine name – e.g.Epicor app server name

You use them like this:

 

Happy coding!

Share this post

Start typing and press Enter to search

Shopping Cart

No products in the basket.