Question Text in the TextBox in the code?

ofek149

Member
Joined
Sep 8, 2012
Messages
7
Programming Experience
3-5
i build project and i have some problems..
1.i need to know how i put the Text in the TextBox in the code

Try
Dim writeFile As System.IO.TextWriter = New _
StreamWriter("ofek149\Test.txt")
writeFile.WriteLine("Test")
writeFile.Flush()
writeFile.Close()
writeFile = Nothing
Catch ex As IOException
MsgBox(ex.ToString)
End Try



ofek149 = The text in the TextBox

2nheoow.png



2.how i add a date to this code:

Try
Dim writeFile As System.IO.TextWriter = New _
StreamWriter("ofek149\Test.txt")
writeFile.WriteLine("Test")
writeFile.Flush()
writeFile.Close()
writeFile = Nothing
Catch ex As IOException
MsgBox(ex.ToString)
End Try

i want when this code create a txt..
in the txt file have the text "Test" and near the Date
Example
[31/08/2012]Test

good day.. :)
 
1. You get the contents of the TextBox from its Text property. You can use the IO.Path.Combine method to combine that with the rest of your text to create a file path.

2. If you want today's date then you get the using Date.Now (includes current time) or Date.Today (time zeroed to midnight). You can call ToString on that or any Date value to create a String representation. You can pass a format specifier as an argument if you want that String in a specific format. When dealing with files and folders, you should always use "yyyy-MM-dd", so that alphabetical and chronological order are synchronised.
 
1. You get the contents of the TextBox from its Text property. You can use the IO.Path.Combine method to combine that with the rest of your text to create a file path.

2. If you want today's date then you get the using Date.Now (includes current time) or Date.Today (time zeroed to midnight). You can call ToString on that or any Date value to create a String representation. You can pass a format specifier as an argument if you want that String in a specific format. When dealing with files and folders, you should always use "yyyy-MM-dd", so that alphabetical and chronological order are synchronised.


can you give me example to 1?...
 
How about you give it a try for yourself and I can help if you can't get it to work? Get one property and call one method. If you want examples then there are plenty out there already. Finding them is a useful exercise in itself. You have to learn how to find information a some point and this is as good a time as any. If what you try doesn't work then by all means post it here and tell us what happened and we can advise how you can fix it.
 
How about you give it a try for yourself and I can help if you can't get it to work? Get one property and call one method. If you want examples then there are plenty out there already. Finding them is a useful exercise in itself. You have to learn how to find information a some point and this is as good a time as any. If what you try doesn't work then by all means post it here and tell us what happened and we can advise how you can fix it.

i try this code

Imports System.IO
Imports System
Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim path1 As String = TextBox3.Text
Dim path2 As String = "\Data\test.txt"
Dim writeFile As System.IO.TextWriter = New _
StreamWriter(path1, path2)
writeFile.WriteLine("ofek")
writeFile.Flush()
writeFile.Close()
writeFile = Nothing
Catch ex As IOException
MsgBox(ex.ToString)
End Try
End Sub
End Class

can you help me to fix ?...
 
Back
Top