You need to be logged in to post in the forums. If you do not have an account, please sign up first.
Can you webcode or other stuff? I need a little bit help.
Hey, I woundering that someone here maybe could help me; I've problems with VB (Visual Basic)I will make a program that save files on your computer and do it till i stop it. (I'll try with a .txt file)
Well, i've made a code that can save it to a folder, but i need a code to read the text i have written in the textfield.
The code to save is (My.Computer.FileSystem.CurrentDirectory & "Spam.txt")
Help plz

From norwegian boy.
Text from a textbox would look something like: (using your code)
Textbox1.text & "Spam.txt"
You might want to do a bit of checking on that though, or such as using "/Spam.txt" (incase you forgot to add the last "/" in the textbox), and you might also want to do:
If System.IO.File.Exists(Textbox1.text & "Spam.txt") Then
...
End If
If you want to read from a file, then something like:
System.IO.File.ReadAllLines(Path)
Splits it into an array based on CrLf's etc...
System.IO.File.ReadAllText(Path)
Just the whole file as a String
System.IO.File.ReadAllBytes(Path)
If you don't know... don't use it.
So... Textbox1.text = System.IO.File.ReadAllText(Path)
If your textbox contains a list of files... then you could do something like
For i As Integer = 0 to Textbox1.lines.length -1
...do something with Textbox1.lines(i)
Next
Naturally these are very simplistic examples, but I'm not really sure what you are trying to do...
Originally posted by Vectronic:
Read what text? Just text in a box? or the file you just saved?
Text from a textbox would look something like: (using your code)
Textbox1.text & "Spam.txt"
You might want to do a bit of checking on that though, or such as using "/Spam.txt" (incase you forgot to add the last "/" in the textbox), and you might also want to do:
If System.IO.File.Exists(Textbox1.text & "Spam.txt") Then
...
End If
If you want to read from a file, then something like:
System.IO.File.ReadAllLines(Path)
Splits it into an array based on CrLf's etc...
System.IO.File.ReadAllText(Path)
Just the whole file as a String
System.IO.File.ReadAllBytes(Path)
If you don't know... don't use it.
So... Textbox1.text = System.IO.File.ReadAllText(Path)
If your textbox contains a list of files... then you could do something like
For i As Integer = 0 to Textbox1.lines.length -1
...do something with Textbox1.lines(i)
Next
Naturally these are very simplistic examples, but I'm not really sure what you are trying to do...
Well, I try to make a program that saves files to the documents and do it till i stop the program.
That I write in the textfield will be write into the file.
Can you help me with a code like that?
System.IO.File.WriteAllText(Path, TextToWrite)
System.IO.File.WriteAllBytes(Path, ByteArray)
Naturally if you use: Imports System.IO, then it's a little easier for typing, since you can skip that, and just write it like File.WriteAllText() etc...
If you are writing the same stuff over and over, or a bunch of text in a row but you don't really know what the text is, or how much of it there is, etc...
Dim Writer As New System.IO.StreamWriter(Path, True)
then something like:
For i as Integer = 0 to X
Writer.WriteLine(Data)
Next
Or something like:
Dim Continue As Boolean = True
While Continue
Writer.WriteLine(Data)
End While
Among many other options...
Assuming you are using VisualStudio, then simply play around... read all the tooltips for the items that pop-up when you type System.IO...
Unless you have specific questions about how to do something, or why something isn't working... get back to VB and write some code.
3. May 2010, 19:52:43 (edited)
I'm not sure what code your using, but what I thought was obvious... "TextToWrite" is the text/data/string that you want to write to the file.
Originally posted by Esp3nn:
Let me guess, this is the first time you've ever used VB?Now i got "statement can not appear outside of an method body" at "If"
That's all you need in your form... for this example anyways.Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Test()
End Sub
Private Sub Test()
For i As Integer = 0 To 9
System.IO.File.WriteAllText("C:\Test" & i.ToString() & ".txt", "Text In File: Test" & i.ToString())
Next
End Sub
End Class
Edit: Merged the two comments since you deleted yours...