Public Module Program Public Shared Function StringToBarcode128String(ByVal 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, isValid As Boolean = True Dim returnValue As String = String.Empty If value.Length > 0 Then ' Check for valid characters For charCount As Integer = 0 To value.Length - 1 'currentChar = char.GetNumericValue(value, charPos); currentChar = AscW(Char.Parse(value.Substring(charCount, 1))) If Not (currentChar >= 32 AndAlso currentChar <= 126) Then isValid = False Exit For End If Next ' Barcode is full of ascii characters, we can now process it If isValid Then 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 ' char.ConvertFromUtf32(210); returnValue = (ChrW(210)).ToString() Else ' Switch to table C returnValue = returnValue & (ChrW(204)).ToString() End If isTableB = False Else If charPos = 0 Then ' Starting with table B ' char.ConvertFromUtf32(209); returnValue = (ChrW(209)).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 = Integer.Parse(value.Substring(charPos, 2)) currentChar = IIf(currentChar < 95, currentChar + 32, currentChar + 105) '' returnValue = returnValue & (ChrW(currentChar)).ToString() charPos += 2 Else ' We haven't 2 digits, switch to table B returnValue = returnValue & (ChrW(205)).ToString() isTableB = True End If End If If isTableB Then ' Process 1 digit with table B returnValue = returnValue & value.Substring(charPos, 1) charPos += 1 End If End While ' Calculation of the checksum checksum = 0 For [loop] As Integer = 0 To returnValue.Length - 1 currentChar = AscW(Char.Parse(returnValue.Substring([loop], 1))) currentChar = IIf(currentChar < 127, currentChar - 32, currentChar - 105) If [loop] = 0 Then checksum = currentChar Else checksum = (checksum + ([loop] * currentChar)) Mod 103 End If Next ' Calculation of the checksum ASCII code checksum = IIf(checksum < 95, checksum + 32, checksum + 105) ' Add the checksum and the STOP returnValue = returnValue & (ChrW(checksum)).ToString() & (ChrW(211)).ToString() End If End If Return returnValue End Function End Module
Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net
. OneCompiler also has reference programs, where you can look for the sample code to get started with.
OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.
Public Module Program
Public Sub Main(args() As string)
Dim name as String = Console.ReadLine() ' Reading input from STDIN
Console.WriteLine("Hello " & name) ' Writing output to STDOUT
End Sub
End Module
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
Variable is a name given to the storage area in order to identify them in our programs.
Simple syntax of Variable declaration is as follows
Dim variableName [ As [ New ] dataType ] [ = initializer ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
Else If(conditional-expression) Then
'code if the above conditional-expression is true
Else
'code if the above conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
If(conditional-expression)Then
'code if the above conditional-expression is true
End If
End If
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End While
Do { While | Until } conditional-expression
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop
Do
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop { While | Until } conditional-expression
Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Procedures are of two types.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub