Can you webcode or other stuff? I need a little bit help.

Forums » The Lounge » The Lounge

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

3. May 2010, 14:11:21

Esp3nn

Posts: 9

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 sad

From norwegian boy.

3. May 2010, 14:28:42

Vectronic

... ... ...

Posts: 2538

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...

3. May 2010, 15:11:57

Esp3nn

Posts: 9

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? smile

3. May 2010, 15:24:25

Vectronic

... ... ...

Posts: 2538

System.IO.File.WriteAllLines(Path, StringArray)
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...

3. May 2010, 16:05:04

Esp3nn

Posts: 9

Ok, but where did it save? smile

3. May 2010, 16:10:53

Esp3nn

Posts: 9

Can you write the whole code for me? Please? bigsmile

3. May 2010, 18:22:11

Vectronic

... ... ...

Posts: 2538

You've been helped...

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:16:09

Esp3nn

Posts: 9

I need to declare path. And it doesn't like TextToWrite

3. May 2010, 19:52:43 (edited)

Vectronic

... ... ...

Posts: 2538

FacePalm...

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:

Now i got "statement can not appear outside of an method body" at "If"

Let me guess, this is the first time you've ever used VB?

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

That's all you need in your form... for this example anyways.

Edit: Merged the two comments since you deleted yours...

4. May 2010, 05:27:22

Esp3nn

Posts: 9

Yey, Thanks! bigsmile

Forums » The Lounge » The Lounge