Alpha-numeric barcodes in datagridview - vb.net

I have created a barcode label printing app in vb. net using visual studio 2010. I have managed to successfully generate alpha-numeric numbers into the datagridview and the barcodes in the image column but instead of printing from 1A-1D, the barcode only prints the 1A when scanned. Please can someone tell me what I’m doing wrong, I’ve been trying to do this for the past few days, but nothing seems to work. Help much appreciated.
Dim alphaNumeric As String = String.Empty
Dim number As String = txtSubNo.Text
Dim alphabet As String = txtAlpha.Text
Dim loopValue As String = txtNo..Text
For index As Integer = 0 To loopValue - 1
alphaNumeric = number.ToString & alphabet
DataGridView1.DataSource = Nothing
DataGridView1.ColumnCount = 4
DataGridView1.Columns(0).Name = "LAB No"
DataGridView1.Columns(1).Name = "SUBNO"
DataGridView1.Columns(2).Name = "INDICATOR"
DataGridView1.Columns(3).Name = "BARCODE"
DataGridView1.Rows.Add(txtLabNo.Text, "" & alphaNumeric, Indicator.Text, PictureBox1.image)
If Asc(alphabet) + 1 <= 90 Then
alphabet = Chr(Asc(alphabet) + 1)
Else
alphabet = "A"
End If
Next
End If

Related

Ordering numbers highest to lowest

For a highscore page in my game I am taking the 1st to 5th highest values from a text file and then displaying them in a text box but I am having the issue that my code is seeing each digit as a separate number, an example being that 43 will be read as 4 and 3. This means my highsore page never shows a score above 9. The text file is in the rescources if the program and contain a new number on each line.
How do i fix this?
Code Below.
'Part 1: Determine Resource File Path based on Debugging mode or Published mode
Dim ResourceFilePathPrefix As String
If System.Diagnostics.Debugger.IsAttached() Then
'In Debugging mode
ResourceFilePathPrefix = System.IO.Path.GetFullPath(Application.StartupPath & "\..\..\resources\")
Else
'In Published mode
ResourceFilePathPrefix = Application.StartupPath & "\resources\"
End If
'Part 2: Write the text file
Dim lines() As String = File.ReadAllLines(ResourceFilePathPrefix & "scores.txt")
Array.Sort(lines)
Array.Reverse(lines)
P1Score.Text = lines(0)
P2Score.Text = lines(1)
P3Score.Text = lines(2)
P4Score.Text = lines(3)
P5Score.Text = lines(4)
You need to convert the scores into integers before you can sort them numerically otherwise they will be sorted as text (which is how the scores are stored in the file).
'Part 2: Write the text file
Dim lines() As String = File.ReadAllLines(ResourceFilePathPrefix & "scores.txt")
Dim scores As New System.Collections.Generic.List(Of Integer)
For Each line As String in lines
scores.Add(Convert.ToInt32(line))
Next
scores.Sort()
scores.Reverse()
P1Score.Text = scores(0)
P2Score.Text = scores(1)
P3Score.Text = scores(2)
P4Score.Text = scores(3)
P5Score.Text = scores(4)
Or using Linq:
'Part 2: Write the text file
Dim lines() As String = File.ReadAllLines(ResourceFilePathPrefix & "scores.txt")
Dim scores = lines.Select(Function(x) Convert.ToInt32(x)).OrderByDescending(Function(x) x)
P1Score.Text = scores(0)
P2Score.Text = scores(1)
P3Score.Text = scores(2)
P4Score.Text = scores(3)
P5Score.Text = scores(4)

Word VBA code to cut numbers from one column and paste them in another

I am looking for some code that can search cell by cell in the 2nd column of a table for numbers and decimal points, cut them and paste them in the cell to the left whilst leaving the text behind.
For example:
1(tab space)Test
1.1(tab space)Test
1.1.1(tab space)Test
1.1.1.1(tab space)Test
Where the bullet points represent separate cells in different columns.
In all instances the numbers are separated from the text by a tab space "Chr9" (as indicated in the example)
Any help or useful snippets of code would much appreciated!
EDIT: I have some code that scans each cell in a column but I dont know the code to tell it to only cut numbers and decimal points up to the first tab space.
The Split function delivers what you are after. Sample code:
Dim inputString As String
Dim splitArray() As String
Dim result As String
inputString = "1 Test"
splitArray = Split(inputString, " ")
If(UBound(splitArray) >= 1) Then 'Making sure that it found something before using it
result = splitArray(1) 'Text
End If
inputString = "1.1 Test"
splitArray = Split(inputString, " ")
If(UBound(splitArray) >= 1) Then
result = splitArray(1) 'Text
End If
'etc.
UPDATE
Code delivering the functionality you want:
Dim splitArray() As String
Dim curTable As Table
Set curTable = ActiveDocument.Tables(1)
For Row = 1 To curTable.Rows.Count
With curTable
splitArray = Split(.Cell(Row, 2).Range.Text, " ")
If (UBound(splitArray) >= 1) Then
.Cell(Row, 2).Range.Text = splitArray(1)
.Cell(Row, 1).Range.Text = splitArray(0)
End If
End With
Next Row

Add Text Into Textbox's in Visual Basic

Ok, so im trying to make this program and i need this:
"Melternet Hello Melternet#gmail.com 5/7/2013" to be in different textbox's like this
"Textbox1 = Melternet"
"Textbox2 = Hello"
"Textbox3 = Melternet#gmail.com"
"Textbox4 = 5/7/2013"
So pretty much every space is a cut off line to add that text to a textbox and then it does the rest like the first one
How would i do something like that, thanks in advance.
Please Answer Back If Anyone Can Figure This Out Or Help Me, NEED THIS QUICK...
BTW: i'm using Visual Basic 2008.
Without more info...something like:
Dim data As String = "Melternet Hello Melternet#gmail.com 5/7/2013"
Dim values() As String = data.Split(" ")
If values.Length >= 4 Then
TextBox1.Text = values(0)
TextBox2.Text = values(1)
TextBox3.Text = values(2)
TextBox4.Text = values(3)
End If
It looks like you are simply splitting the entire input text string: "Melternet Hello Melternet#gmail.com 5/7/2013" wherever a space occurs, yes(?)
If your string has a variable number of words, then fill up textboxes programmatically, like, e.g.:
Dim mystr as String
mystr = "hello world I want to paste this to multiple textboxes"
Dim Buff() as String
Buff = Split(mystr," ")
For i As Integer = 0 to UBound(Buff)
Dim tb As New TextBox
str = Buff(i)
tb.Name = str
tb.Text = str
tb.Left = 50
tb.Top = 50 + 25 * i
tb.Width = 50
tb.TextAlign = HorizontalAlignment.Right
Me.Controls.Add(tb)
Next
In the above fashion, no matter what the value of mystr, or how many words are in the string (mystr), you can write them all to new textboxes that are created/placed dynamically on Form1, i.e. "Me".

VB.net incremented number concatenate with texbox value

I'm learning vb.net. I'm trying to create an incremental number that starts at 00000 and concatenate that number with a value from a textbox (eg. JH00001), then insert it into the database.
Please can someone kindly help me with this as I'm totaly new to vb.net.
Thank you all for your assistance in advance. And I'm sorry for my bad English.
Dim number as Integer = 1
Dim text as String = textbox1.text &= number.toString().padLeft(5, "0"c)
Use D5 precision specifier to indicate that the number should be at least 5 digits including leading zeros:
Dim valueFromTextBox As String = "JH"
Dim value As String = ""
For i = 0 To 99
value = valueFromTextBox & i.ToString("D5")
'Insert value to database
Next
Check MSDN for more formatting methods
A for loop should be what you need:
Something like:
Dim text As String = textbox1.text
Dim DBtext As String
For value As Integer = 0 To 5
DBtext = text & value.ToString()
'Insert anything else you need to do. Such as insert into DB.
Next
Just replace the 5 with however many times you need it to run.
I personally prefer using String.Format ...
For i = 0 to 1e6-1
Dim FormattedString = String.Format("{0}{1:00000}", Textbox1.Text, i)
Next

Cant figure out how to merge variables vb.net

I am creating a for each loop to take the words from a string and place them each into a text box. The program allows for up to "9" variables What I am trying to attempt is.
Foreach word in Words
i = i +1
Varible & i = word
txtCritical1.Text = variable & i
any ideas on a way to make this work?
Have a look through the MSDN article on For Each. It includes a sample using strings.
https://msdn.microsoft.com/en-us/library/5ebk1751.aspx
So i went with a simple if statement this does the trick. Each text box is filled in.
Dim details As String = EditEvent.EditDbTable.Rows(0).Item(13).ToString()
Dim words As String() = details.Split(New Char() {"«"})
Dim word As String
For Each word In words
i = i + 1
v = word
If i = 1 Then
txtCritical1.Text = v
ElseIf i = 2 Then
txtCritical2.Text = v
ElseIf ....
ElseIf i = 9 then
txtCritical2.text = v
Else
....
End If
Next