Formatting text output from DataGridView in vb.net - vb.net

I'm writing the values of two (1 column) DGVs and a text box to a text file. The text box value is the heading, DGV1 is a column of strings (such as SI CA S C...etc) and DGV2 is a column of numbers of the format 11.23 or 0.01. The formats are exactly how I want them as displayed in the DGVs, but that formatting doesn't carry over to the text file these values are output to. Here's what I want the textfile to look like:
A012345 101 1.03
SI 32.13
C 1.45
CA 0.03
Here's what I'm getting instead:
A012345 101 1.03
SI32.13015
C1.452359
CA0.032568
Here's the code:
Try
Dim da, da2 As OleDbDataAdapter
Dim ds, ds2 As DataSet
'open connection to nit2.xlsm'
Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""" & TextBox2.Text & """;Extended Properties=""Excel 12.0;HDR=YES;""")
'Fill dataviewgrid1 with element symbols, string, once'
da = New OleDbDataAdapter("select * from [Sheet1$A:A" & lastrow & "]", cn)
ds = New System.Data.DataSet
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
'''''''''''''loop through each sample and write to text file'''''''''''''''''''''''
da2 = New OleDbDataAdapter("select * from [Sheet1$B:B" & lastrow & "]", cn)
ds2 = New System.Data.DataSet
da2.Fill(ds2)
DataGridView2.DataSource = ds2.Tables(0)
'write sample heading to textbox1, looped'
TextBox1.Text = "Q0" & xlWsheet1.Cells(1, 2).Value & " " & xlWsheet2.Cells(1, 2).Value
'write to text file each data analysis point with formatted heading, looped'
Dim title As String = TextBox1.Text
Dim sub_title As String = title.Substring(0, 16)
Using writer As New System.IO.StreamWriter(fName, True)
writer.WriteLine(sub_title) 'heading'
Dim symbol, SymbolT As String
Dim compo As String
For cell1 As Integer = 0 To (DataGridView1.Rows.Count - 2)
symbol = Me.DataGridView1(0, cell1).Value 'element symbol'
symbolT = symbol.Trim
compo = Me.DataGridView2(0, cell1).Value 'composition'
writer.WriteLine(symbolT & compo)
Next
writer.Close()
End Using
cn.Close()
How can I format the numbers from DGV2 so that they only display to 2 decimals?
I also need to set the spacing between SI and 32.13 (for example) so that the decimal points in each line line up.
Formatting...anyone?

Something like this ?
Dim symbol As String
Dim compo As String
Dim symbolSpan As Integer = 0 ' stores the MaxLength of symbol
Dim compoSpan As Integer = 0 ' stores the Max Integer Part Length of compo
Dim symbolList As New List(Of String) ' all trimmed symbol
Dim compoList As New List(Of String) ' all trimmed compo
Dim compoIntLengthList As New List(Of Integer)
Dim doubleValue As Double
Dim i As Integer
Dim j As Integer
For i = 0 To (DataGridView1.Rows.Count - 2)
' element symbol...
symbol = Me.DataGridView1(0, i).Value.ToString().Trim()
symbolList.Add(symbol)
If symbol.Length > symbolSpan Then
symbolSpan = symbol.Length
End If
' composition...
If Double.TryParse(Me.DataGridView2(0, i).Value.ToString().Trim(), doubleValue) Then
compoList.Add(doubleValue.ToString("R"))
' well, the ToString("R") is not really the displayed value.
' if your DGV allows scientific display for Double then
' you'll have to handle that here with another code...
compo = doubleValue.ToString("F0") ' gets the Integer part length...
compoIntLengthList.add(compo.Length)
If compo.Length > compoSpan Then
compoSpan = compo.Length
End If
Else
' ohhhh ! the Cell doesn't contain a valid number... :/
compo = Me.DataGridView2(0, i).Value.ToString().Trim()
compoList.Add(compo)
If compo.Contains(".") Then ' Watch out culture about dots and commas...
If compoSpan < compo.IndexOf("."c) Then
compoSpan = compo.IndexOf("."c)
End If
compoIntLengthList.add(compo.IndexOf("."c))
Else
If compoSpan < compo.Length Then
compoSpan = compo.Length
End If
compoIntLengthList.add(compo.Length)
End If
End If
Next
symbolSpan = symbolSpan + 1 ' space between symbol and compo.
Using writer As New System.IO.StreamWriter(fName, True)
writer.WriteLine(sub_title) 'heading'
For i = 0 To symbolList.Count - 1
symbol = symbolList.Item(i)
While symbol.Length < symbolSpan
symbol = symbol + " "
End While
compo = compoList.Item(i)
j = compoIntLengthList.Item(i)
While j < compoSpan
compo = " " + compo
j = j + 1 ' this is what was causing the endless loop.
End While
writer.WriteLine(symbol & compo)
Next
symbolList.Clear()
symbolList= Nothing
compoList.Clear()
compoList = Nothing
compoIntLengthList.Clear()
compoIntLengthList = Nothing
writer.Close()
End Using
I haven't tested the code. Just written it on the fly.. The approach looks ugly (and I agree) but that's one way I remember so far. Could be better with String.Format or StringBuilder I guess but don't remember well how those ones works, sorry.
EDIT : Missed the two decimals part...
Oh, sorry ! You want only two decimals.. Replace this :
compoList.Add(doubleValue.ToString("R"))
by this :
compoList.Add(doubleValue.ToString("F2"))
' or this :
compoList.Add(doubleValue.ToString("#.##")) ' to allow 0 or 1 decimal aswell
and replace this part :
' ohhhh ! the Cell doesn't contain a valid number... :/
compo = Me.DataGridView2(0, i).Value.ToString().Trim()
compoList.Add(compo)
If compo.Contains(".") Then ' Watch out culture about dots and commas...
If compoSpan < compo.IndexOf("."c) Then
compoSpan = compo.IndexOf("."c)
End If
compoIntLengthList.add(compo.IndexOf("."c))
Else
If compoSpan < compo.Length Then
compoSpan = compo.Length
End If
compoIntLengthList.add(compo.Length)
End If
by this :
' ohhhh ! the Cell doesn't contain a valid number... :/
compo = Me.DataGridView2(0, i).Value.ToString().Trim()
If compo.Contains(".") Then ' Watch out culture about dots and commas...
If compoSpan < compo.IndexOf("."c) Then
compoSpan = compo.IndexOf("."c)
End If
If compo.Length > (compo.IndexOf("."c) + 3) Then
compo = compo.SubString(0, compo.IndexOf("."c) + 3)
End If
compoIntLengthList.add(compo.IndexOf("."c))
Else
If compoSpan < compo.Length Then
compoSpan = compo.Length
End If
compoIntLengthList.add(compo.Length)
End If
compoList.Add(compo)

Related

Read the whole file into an array, replace one of the elements of that array, then write the whole file again. Text ends up the same

I have a form3 that when the user exits it attempts to save the time they spent playing. When trying to replace the line I end up with the exact same text, therefore nothing changes in the file. Why will it not replace the text? Thanks in advance.
File.AppendAllLines(Application.StartupPath + "\content\main\userdata\tgametime.txt", FileLines)
'this line will not write to file if it has the same file name because FileLines is still using it, if this could be solved too awesome!
Private Sub SaveGameTime()
Dim fullpath = Path.Combine(Application.StartupPath + "\content\main\userdata\gametime.txt")
Dim FileLines = File.ReadLines(fullpath)
Dim alltext = File.ReadAllText(fullpath)
Dim datalist = New List(Of String)
Dim line
datalist.Add(tbGameName.Text + " : " + LBtimeout.Text)
TextDiag(FileLines.Count.ToString, "Clear")
If FileLines.Count > 0 Then
If alltext.Contains(tbGameName.Text) Then
For Each line In FileLines
TextDiag(line, "Clear")
line.Replace(line, tbGameName.Text + " : " + LBtimeout.Text)
TextDiag("new line: " + line, "Clear")
Next
File.AppendAllLines(Application.StartupPath + "\content\main\userdata\tgametime.txt", FileLines)
Else
TextDiag("Line not found, adding new line", "Clear")
File.AppendAllLines(fullpath, datalist)
End If
Else
TextDiag("No lines not found, adding new line", "Clear")
File.AppendAllLines(fullpath, datalist)
End If
datalist.Clear()
fullpath = Nothing
FileLines = Nothing
datalist = Nothing
TextDiag Output
Got it working, replaces text at a specified string value in a file formatted like this: "Text > 0 : 0 : 0" . It gets a new time value extracted from a label formatted like this: "0 : 0 : 0", removes everything but the numbers and colons to this: "0:0:0", formats them to a TimeSpan and adds them to the outputlines which also contain any other original text.
Thank you
Dim fullpath = "yourpath"
Dim FileLines = File.ReadLines(fullpath)
Dim outputlines As New List(Of String)
Dim alltext = File.ReadAllText(fullpath)
Dim datalist = New List(Of String)
Dim line
Dim lbtime = TimeSpan.Parse(LBtimeout.Text.Replace(" ", ""))
datalist.Add("youstring" + " : " + "yourstring")
If FileLines.Count > 0 Then
If alltext.Contains("yourstring") Then
For Each line In FileLines
If line.contains("yourstring") Then
Dim liness = line.substring(line.indexof(">") + 1)
Dim linerep = liness.replace(" ", "")
Dim linetime = TimeSpan.Parse(linerep)
Dim timesum As TimeSpan = lbtime + linetime
line.replace(line, "")
line = "yourstring" + " > " + timesum.ToString
outputlines.Add(line)
Else
outputlines.Add(line)
End If
Next
File.WriteAllLines("yourpath", outputlines)
Else
File.AppendAllLines(fullpath, datalist)
End If
Else
'No lines not found, adding new line
File.AppendAllLines(fullpath, datalist)
End If
datalist.Clear()
fullpath = Nothing
FileLines = Nothing
datalist = Nothing

Repeat character in Two or More Textboxes VB Net

I want to compare the Textbox1 with TextBox2, or Textbox line 1 of the text box to the 2nd line, to show me the existing Character in another textbox, or show me how many characters are repeated. iI really like learning, so I would be helpful because I want to learn...
TextBox1.Text = 1,4,7,11,13,16,19,20,28,31,44,37,51,61,62,63,64,69,71,79,80
TextBox2.Text = 1,5,7,10,13,16,26,20,28,31,44,37,51,72,73,74,69,71,79,80
TextBox3.Text = Character Repeated: 1,7,13,16,20,28,31,44,37,51,69,71,79,80
TextBox4.Text = Number of Character Repeated = 14
TextBox5.Text = Number of Character which has not been repeated: 4,11,19,61,62,63,64 etc, you got to idea
TextBox6.Text = Number of Character isn't Repeated: 7
here are some codes: but I do not know how to apply them correctly.
Code 1: Show repetable character:
' Split string based on space
TextBox1.Text = System.IO.File.ReadAllText(Mydpi.Text)
TextBox2.Text = System.IO.File.ReadAllText(Mydpi.Text)
TextBox4.Text = System.IO.File.ReadAllText(Mydpi.Text)
For i As Integer = 0 To TextBox2.Lines.Count - 1
Dim textsrtring As String = TextBox4.Lines(i)
Dim words As String() = textsrtring.Split(New Char() {","c})
Dim found As Boolean = False
' Use For Each loop over words
Dim word As Integer
For Each word In words
TxtbValBeforeCompar.Text = TextBox1.Lines(i)
CompareNumbers()
If TextBox1.Lines(i).Contains(word) Then
found = True
Dim tempTextBox As TextBox = CType(Me.Controls("Checkertxt" & i.ToString), TextBox)
On Error Resume Next
If TextBox2.Lines(i).Contains(word) Then
If tempTextBox.Text.Contains(word) Then
Else
tempTextBox.Text = tempTextBox.Text + " " + TxtbValAfterCompar.Text()
End If
Else
End If
End If
Next
Next
Private Sub CompareNumbers()
'First Textbox that is to be used for compare
Dim textBox1Numbers As List(Of Integer) = GetNumbersFromTextLine(N1Check.Text)
'Second Textbox that is to be used for compare
Dim textBox2Numbers As List(Of Integer) = GetNumbersFromTextLine(TxtbValBeforeCompar.Text)
'Union List of Common Numbers (this uses a lambda expression, it can be done using two For Each loops instead.)
Dim commonNumbers As List(Of Integer) = textBox1Numbers.Where(Function(num) textBox2Numbers.Contains(num)).ToList()
'This is purely for testing to see if it worked you can.
Dim sb As StringBuilder = New StringBuilder()
For Each foundNum As Integer In commonNumbers
sb.Append(foundNum.ToString()).Append(" ")
TxtbValAfterCompar.Text = (sb.ToString())
Next
End Sub
Private Function GetNumbersFromTextLine(ByVal sTextLine As String) As List(Of Integer)
Dim numberList As List(Of Integer) = New List(Of Integer)()
Dim sSplitNumbers As String() = sTextLine.Split(" ")
For Each sNumber As String In sSplitNumbers
If IsNumeric(sNumber) Then
Dim iNum As Integer = CInt(sNumber)
TxtbValAfterCompar.Text = iNum
If Not numberList.Contains(iNum) Then
TxtbValAfterCompar.Text = ("")
numberList.Add(iNum)
End If
Else
End If
Next
Return numberList
End Function
Code 2: Remove Duplicate Chars (Character)
Module Module1
Function RemoveDuplicateChars(ByVal value As String) As String
' This table stores characters we have encountered.
Dim table(value.Length) As Char
Dim tableLength As Integer = 0
' This is our result.
Dim result(value.Length) As Char
Dim resultLength As Integer = 0
For i As Integer = 0 To value.Length - 1
Dim current As Char = value(i)
Dim exists As Boolean = False
' Loop over all characters in the table of encountered chars.
For y As Integer = 0 To tableLength - 1
' See if we have already encountered this character.
If current = table(y) Then
' End the loop.
exists = True
y = tableLength
End If
Next
' If we have not encountered the character, add it.
If exists = False Then
' Add character to the table of encountered characters.
table(tableLength) = current
tableLength += 1
' Add character to our result string.
result(resultLength) = current
resultLength += 1
End If
Next
' Return the unique character string.
Return New String(result, 0, resultLength)
End Function
Sub Main()
' Test the method we wrote.
Dim test As String = "having a good day"
Dim result As String = RemoveDuplicateChars(test)
Console.WriteLine(result)
test = "areopagitica"
result = RemoveDuplicateChars(test)
Console.WriteLine(result)
End Sub
End Module
You could make use of some LINQ such as Intersect and Union.
Assuming your TextBox1 and TextBox2 contains the text you have provided.
Here's a simple method to find repeated and non repeated characters.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim firstBoxList = TextBox1.Text.Split(",").ToList()
Dim secondBoxList = TextBox2.Text.Split(",").ToList()
Dim intersectionList = firstBoxList.Intersect(secondBoxList)
For Each str As String In intersectionList
TextBox3.Text = TextBox3.Text & str & ","
Next
TextBox4.Text = intersectionList.Count()
Dim notRepeatedCharacter = firstBoxList.Union(secondBoxList).ToList
notRepeatedCharacter.RemoveAll(Function(x) intersectionList.Contains(x))
For each str As String In notRepeatedCharacter
TextBox5.Text = TextBox5.Text & str & ","
Next
TextBox6.Text = notRepeatedCharacter.Count()
End Sub
The output is something like that:
This consider both of the textboxes not repeated character.
If you just want to find the not repeated characters from first list to the second, this should do it:
firstBoxList.RemoveAll(Function(x) secondBoxList.Contains(x))
For Each str As String In firstBoxList
TextBox7.Text = TextBox7.Text & str & ","
Next
TextBox8.Text = firstBoxList.Count
And this is the output:
Here's the full code using String.Join to make the lists look smoother in the text boxes:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'First we grab all the numbers written inside the textboxes (I am not verifying anything)
Dim firstBoxList = TextBox1.Text.Split(",").ToList()
Dim secondBoxList = TextBox2.Text.Split(",").ToList()
'Second we intersect the two lists and show them
Dim intersectionList = firstBoxList.Intersect(secondBoxList)
TextBox3.Text = String.Join(",", intersectionList)
TextBox4.Text = intersectionList.Count()
'We're checking the distintc character from both lists
Dim notRepeatedCharacter = firstBoxList.Union(secondBoxList).ToList
notRepeatedCharacter.RemoveAll(Function(x) intersectionList.Contains(x))
TextBox5.Text = String.Join(",", notRepeatedCharacter)
TextBox6.Text = notRepeatedCharacter.Count()
'we're checkng the distinct character inside first list that doesn't show in second list
firstBoxList.RemoveAll(Function(x) secondBoxList.Contains(x))
TextBox7.Text = String.Join(",", firstBoxList)
TextBox8.Text = firstBoxList.Count
End Sub

vb.net how do i add long text into csv

hello this is my firs thread ,
i'm trying to convert description of this page (https://www.tokopedia.com/indoislamicstore/cream-zaitun-arofah)
with regex and replace <br/> tag with new line and convert it to csv .
the datagridview it's alright but the csv got screwed
this is my code :
Dim dskrip As New System.Text.RegularExpressions.Regex("<p itemprop=""description"" class=""mt-20"">(.*?)\<\/p>\<\/div>")
Dim dskripm As MatchCollection = dskrip.Matches(rssourcecode0)
For Each itemdskrm As Match In dskripm
getdeskripsinew = itemdskrm.Groups(1).Value
Next
Dim deskripsinew As String = Replace(getdeskripsinew, ",", ";")
Dim deskripsitotal As String = Replace(deskripsinew, "<br/>", Environment.NewLine)
' ListView1.s = Environment.NewLine & deskripsinew
txtDeskripsi.Text = deskripsitotal
datascrapes.ColumnCount = 5
datascrapes.Columns(0).Name = "Title"
datascrapes.Columns(1).Name = "Price"
datascrapes.Columns(2).Name = "Deskripsi"
datascrapes.Columns(3).Name = "Gambar"
datascrapes.Columns(4).Name = "Total Produk"
Dim row As String() = New String() {getname, totalprice, deskripsitotal, directoryme + getfilename, "10"}
datascrapes.Rows.Add(row)
Dim filePath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\" & "Tokopedia_Upload.csv"
Dim delimeter As String = ","
Dim sb As New StringBuilder
For i As Integer = 0 To datascrapes.Rows.Count - 1
Dim array As String() = New String(datascrapes.Columns.Count - 1) {}
If i.Equals(0) Then
For j As Integer = 0 To datascrapes.Columns.Count - 1
array(j) = datascrapes.Columns(j).HeaderText
Next
sb.AppendLine(String.Join(delimeter, array))
End If
For j As Integer = 0 To datascrapes.Columns.Count - 1
If Not datascrapes.Rows(i).IsNewRow Then
array(j) = datascrapes(j, i).Value.ToString
End If
Next
If Not datascrapes.Rows(i).IsNewRow Then
sb.AppendLine(String.Join(delimeter, array))
End If
Next
File.WriteAllText(filePath, sb.ToString)
this is the csv file
I'm not sure where your problem is looking at the CSV file, but there are certain cases where you'll want to quote the values for a CSV. There's no official spec but RFC 4180 is often used as an unofficial standard. I would recommend using a library like CSV Helper

This code is supposed to output the number of times a word starts with a letter from the alphabet, but just displays zero for each one

This code is supposed to output the number of times a word starts with a letter from the alphabet, but just displays zero for each one
I get no errors, but just a text file with all of the letters and zero for each one.
When pressing the debug button, it appears to do nothing. Here's the code
Imports System.IO
Module Module1
Sub Main()
Dim myArray As New List(Of String)
Using myReader As StreamReader = New StreamReader(".\myFile.txt")
'telling VB that we're using a StreamREader, read a line at a time
Dim myLine As String
myLine = myReader.ReadLine 'assigns the line to String Variable myLine
Do While (Not myLine Is Nothing)
myArray.Add(myLine) 'adding it to the list of words in the array
Console.WriteLine(myLine)
myLine = myReader.ReadLine
Loop
End Using
SortMyArray(myArray) 'Calls the new SubRoutine => SortMyArray, passing through the parameter myArray,
'created back on line 7 that stores all of the lines read from the text file.
'Console.ReadLine()
wordCount(myArray)
End Sub
Sub SortMyArray(ByVal mySort As List(Of String))
Dim Tmp As String, writePath As String = ".\sorted.txt"
Dim max As Integer = mySort.Count - 1
Dim myWriter As StreamWriter = New StreamWriter(writePath)
For Loop1 = 0 To max - 1
For Loop2 = Loop1 + 1 To max
If mySort(Loop1) > mySort(Loop2) Then
Tmp = mySort(Loop2)
mySort(Loop2) = mySort(Loop1)
mySort(Loop1) = Tmp
End If
Next
myWriter.WriteLine(mySort.Item(Loop1).ToString())
Next
myWriter.Dispose()
End Sub
Sub wordCount(ByVal stringArray As List(Of String))
Dim alphabet As String = "abcdefghijklmnopqrstuvwxyz", myString As String
Dim writePath As String = ".\counted.txt"
Dim myWriter As StreamWriter = New StreamWriter(writePath)
Dim countOf(25) As Integer, Max As Integer = stringArray.Count - 1
For Loop1 = 0 To 25
myString = alphabet.Substring(Loop1, 1)
For Loop2 = 0 To Max
If stringArray(Loop2).Substring(0, 1) = myString Then
countOf(Loop1) += 1
End If
Next
myWriter.WriteLine(myString & " occured " & countOf(Loop1) & " times ")
Next
myWriter.Dispose()
End Sub
End Module
Any help would be appreciated. Thanks

Finding Missing numbers in a given range

So i have a problem with my codings and was wondering if anyone can help me.
Basically i'm using VB.NET and MSSQL to make a program on finding missing numbers in between a given range set by the user. The program will read from the table and give the output on a textbox. And the above codes are so far what i can come up with. But the problem is, i get wrong output and not what i want. Here's an image of the output.
Function FindingMissingNumber() As String
Dim intX As Integer = Nothing
Dim intY As Integer = Nothing
Dim strSting As String = Nothing
Dim strSqlQUery As String = Nothing
Dim cmdSqlCommand As Data.SqlClient.SqlCommand = Nothing
Dim rdrDataReader As Data.SqlClient.SqlDataReader = Nothing
'------------------------------------------------------------------------------------------------------------------------
'-> Process
'------------------------------------------------------------------------------------------------------------------------
strSqlQUery = "Select ExReportPolicyNo From DBReport Order by ExReportPolicyNo"
Dim msSqlConnection As New Data.SqlClient.SqlConnection()
'NOTE - You may need to CHECK your connection string!!! in the line below
msSqlConnection.ConnectionString = "Data Source=SISBSQL\SISBSQL;Initial Catalog=ExceptionReport;User ID=sa;Password=123;"
cmdSqlCommand = New Data.SqlClient.SqlCommand(strSqlQUery, msSqlConnection)
If cmdSqlCommand.Connection.State = Data.ConnectionState.Closed Then cmdSqlCommand.Connection.Open()
rdrDataReader = cmdSqlCommand.ExecuteReader()
If rdrDataReader.HasRows Then
Do While rdrDataReader.Read()
intX = txtRangeLeft.Text
intY = txtRangeRight.Text
'intY = rdrDataReader.GetValue(rdrDataReader.GetOrdinal("ExReportPolicyNo"))
Do While intX <> intY
intX = intX + 1
If intX <> intY Then
strSting = strSting & intX & ", " 'if it is not, then record the non sequential number into the string
Else
Exit Do
End If
Loop
Loop
End If
If cmdSqlCommand.Connection.State = Data.ConnectionState.Open Then cmdSqlCommand.Connection.Close()
'return string
Return strSting
'tidy up
intX = Nothing
intY = Nothing
strSting = Nothing
strSqlQUery = Nothing
cmdSqlCommand = Nothing
rdrDataReader = Nothing
End Function
As you can see the program loops it multiple times, and give out the wrong output. The output should read only "286118, 286120, 286121". Question is where did i went wrong?
Try this (using linq)
Change query to return rows between start and end value
Select distinct ExReportPolicyNo From DBReport
Where ExReportPolicyNo between #start and #end
Order by ExReportPolicyNo
Create List from your query:
Dim originalList as List(Of Integer)
If rdrDataReader.HasRows Then
Do While rdrDataReader.Read()
originalList.Add(rdrDataReader.GetInt(0))
Loop
End If
Create List of range from your start and end number
//Dim rangeList = Enumerable.Range(286117, 286121 - 286117 + 1).ToList()
Dim starti = Int32.Parse(txtRangeLeft.Text)
Dim endi = Int32.Parse(txtRangeRight.Text)
Dim rangeList = Enumerable.Range(starti, endi - starti + 1).ToList()
Find all missing numbers
Dim missingList = originalList.Except(rangelist)
Create CSV string from list above
strString = String.Join(",", missingList.Select(x => x.ToString()).ToArray())