Reading Textbox

Posts 1–15 of 15 · Page 1 of 1
Reading Textbox
This is what im trying to make.

If autofill button is clicked. Read the line from emailtextbox.text. Save the line into a file called Emails.txt.

For every other email following, seperate it with a ","

How can i turn this into a code?
Quote Originally Posted by ppl2pass View Post
This is what im trying to make.

If autofill button is clicked. Read the line from emailtextbox.text. Save the line into a file called Emails.txt.

For every other email following, seperate it with a ","

How can i turn this into a code?
Are you going to write to a textbox on a website?

Or what do you mean?
Code:
  Dim TargetFile As StreamWriter

        Try
            TargetFile = New StreamWriter("test.txt", True)
        Catch
            MessageBox.Show("Error opening " & "test.txt")
        End Try

        Try
            TargetFile.WriteLine(Now())
            TargetFile.Write(TextBox1.Text)
            TargetFile.WriteLine()
            TargetFile.WriteLine()
        Catch
            MessageBox.Show("Error writing file")
        End Try

        TargetFile.Close()
        MessageBox.Show("Text saved to " & "test.txt")
Namespace

Imports system.io


@Blubb, Credit to Java2s for that C&P

@Topic, I think he is talking about CSV

He wants to read and write CSV (Comma Seperated Value) (Delimiters)

(Delimiters can be anything by the way ":" "," ";" Your choice )

Example of CSV bob@bob.com,shane@aol.com,chris@chris.com,

Writing is easy , Use System IO and Save the txt file the same way you normally would only pass , to the end of each in your save event

Read

Code:
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\email.txt") ' or its location and name
   MyReader.TextFieldType = FileIO.FieldType.Delimited
   MyReader.SetDelimiters(",")
   Dim thisRow As String()
   While Not MyReader.EndOfData
      Try
         thisRow = MyReader.ReadFields()
         Dim thisField As String
         For Each thisField In thisRow
            listbox1.items.add(thisField)
         Next
      Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
      MsgBox("Line " & ex.Message & _
      "is not valid and will be skipped.")
      End Try
   End While
End Using
That method is standard MSDN method (just about)

Or alternately you can use

Code:
Private Sub ReadCSV()
 
         Dim ary(0) As String
        Dim systemr As New System.IO.StreamReader("c:\email.txt") ' or file location here
 
        Dim PH As Integer = 0
 
        Do While systemr.Peek <> -1 
            ary(PH) = systemr.ReadLine
            PH += 1
        Loop
 
         
    End Sub
Note:: You can loop through the elements with String.Split() in sample two looking for anything Delimited by ","

Note: You can replace the listbox in example one with anything.
i didnt phrase it too well.
ok ill explain fully.

so a person will fill in their email to emailtextbox.text and when they click the autofill button the email will be automatically written to a file called emails.txt with a comma that will seperate emails that the person will make after.
Just append a ","


Code:
emailtextbox.text & ","
ok but how do u make it automatic. like putting it in a timer.
On button click, It will auto add using & ","

I think I am misunderstanding however, no need for a timer, You want this to happen on button click right?
here is what i am thinking of.

If autofill.button is clicked then
create a new text file called email.txt
insert email from emailtextbox.text

If email.txt is already created
do not create overwrite
continue on text
Easy Way, Load the Emails into a ComboBox instead of a Textfile

then use

Code:
 If (Not ComboBox1.Items.Contains(ComboBox1.Text)) Then
            ComboBox1.Items.Add(ComboBox1.Text)
        Else
            MsgBox("this email already exisits")
        End If
Then save the contents of the comboBox so when the application loads, the new emails load as well.

This code can easily be manipulated to handle checks in numerous different ways, but it's a easy way to check against a list, you can do the same with list view and list box's etc. Alot simpler then string manipulation and string readers

i dont think u get what i mean.

so im trying to save the email into a textfile not load it.
Right, But instead of opening a txt file and searching for duplicates, use a combo box to make your life easier, use blubbs (java2s) Save Txt Code, but save the combo box, and test the emails against it.

Does that make sense, Or am I making a tutorial tonight?
so wats the code to place emailtext.text into the combo box?
Code:
Dim streamw As StreamWriter = New StreamWriter("C:\email.txt", False)

        For i As Integer = 0 To ComboBox1.Items.Count - 1 Step 1
            streamw.WriteLine(ComboBox1.Items(i).ToString())
        Next
        streamw.Close()
can you please make a tut. i still dun get it. sorry.
Posts 1–15 of 15 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us