Batch BOL/EOL Editing

I needed a way of adding periods to the end of every line in text documents. The text documents in question had 100+ lines, so going through each document and pressing ( END > . > ENTER ) repetitively was not ideal. I needed a program, but after some brief googling I gave up and decided that I needed to write this program. I started my project by getting some advice and direction, here, and I am glad I did or else I would have went with my original plan of working with “regex” 🙁 …

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
Dim Needy As String = tbx_main.Text
Dim Added As String = Regex.Replace(Needy, “(\p{P})(?=\Z|\r\n)”, “.”)
oWrite.Write(Added)
oWrite.Close()
oWrite = oFile.CreateText(“C:\Text_to_Speech.txt”)
End Sub

The end result is a little program that adds any desired character(s) to the beginning or end of all lines pasted into its textbox. The code is as follows…

Try
‘Make sure big tbx is not empty
If tbx_main.Text = “” Then
tbx_main.Text = “Please enter text!”
ElseIf tbx_main.Text = “Please enter text!” Then
tbx_main.Text = “Please enter text!”
Else
‘Make sure small tbx is not empty
If tbx_desired.Text = “” Then
tbx_desired.Text = “Char?”
ElseIf tbx_desired.Text = “Char?” Then
tbx_desired.Text = “Char?”
Else
‘Declare: file, stream and savefiledialog
Dim oFile As File
Dim oMyStream As Stream
Dim saveFileDialog1 As New SaveFileDialog
‘Set savefiledialog defaults
saveFileDialog1.Filter = “txt files (*.txt)|*.txt”
saveFileDialog1.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True
‘Run nested code if user presses OK button in dialog
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
oMyStream = saveFileDialog1.OpenFile()
Dim oWrite As New StreamWriter(oMyStream)
For Each LineInput As String In tbx_main.Lines
‘Core Code, add periods to beginning or end
If rbtn_begin.Checked = True Then
‘Beginning
oWrite.WriteLine(tbx_desired.Text + LineInput)
ElseIf rbtn_end.Checked = True Then
‘End
oWrite.WriteLine(LineInput + tbx_desired.Text)
End If
Next
oWrite.Close()
End If
‘Periods added, display success msgbx, close form
MessageBox.Show(“Success: file was created!”)
Me.Dispose()
Me.Close()
End If
End If
Catch exc As Exception
‘Catch Errors, display messagebox
MessageBox.Show(“Error: file was not created!”)
End Try

Sounds useful? If you want to download the program and use it at your own risk, click here.

ASP.net 1.1 Repeater Columns

While writing a script to mass approve posts on a site, similar to deleting all unwanted email using: a repeater (not a datagrid), a checkbox in each indexItem, and a button; I ran into a common problem for many… ASP.net repeaters don’t have columns. I searched the net and visited two of my favorite forums looking for help and came up with nothing…

Here’s my Psuedo/Logic:
1) Load Repeater with list of “UNmoderated” items
2) Put a checkbox inside the repeaters ItemTemplate
3) Add code to button (dosomething if checkbox is checked)

Problem:
I couldn’t locate the column with the PrimaryUniqueID because there are no columns in repeaters, but my Stored Procedure “requires” the PrimaryUniqueID.

Button code:
Private Sub MassApprove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MassApprove.Click
Try
Dim MyRptItem As RepeaterItem
For Each MyRptItem In MyRepeater.Items
Dim chbxMassApprove As CheckBox = CType(MyRptItem.FindControl(“chbxMassApprove”), CheckBox)
Dim PrimaryUniqueID As String = MyRptItem.DataItem(PrimaryUniqueID) PROBLEMATIC LINE
If chbxMassApprove.Checked = True Then
‘DO THE MASS APPROVE
‘LOOP THRU STORED PROCEDURE
End If
Next
Catch exc As Exception
Response.Write(exc.ToString)
End Try
End Sub

Solution:
I used this as a workaround if this helps anyone…

Front End:
Text='<%# DataBinder.Eval(Container, “DataItem.PrimaryUniqueID”) %>’

Back End:
Dim PrimaryUniqueID As String = ckbxMassApprove.Text.ToString