Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox Question

Status
Not open for further replies.

clubriza

Programmer
Jun 26, 2004
8
0
0
GB
Hi all,

Im making a VAT Calculator, that shows + vat, - vat, Net, Gross ect.

I want a textbox to display the contents of the "vat rate.txt" file. "ie 17.5" (is that possible?)

The reason for this is, i want the user to be able to change the vat rate (+ i can set it to only accept numbers & a sinlge "."). Then when the program closes, it then saves the changed vat rate to the .txt file, so the next time the program opens it shows the new vat rate.

cheers

clubriza

 
yes this is possible

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
I agree that it is possible as well. Try looking it up in help for file reading/writing. Its fairly simple.
 
thanks for your replys,
i already tired the help files, and came up with these:

Textbox.Text = System.IO.File.OpenRead("VAT Rate.txt", System.IO.File.OpenRead)

and this

' Create an instance of StreamReader to read from a file.
Dim sr As IO.StreamReader = New IO.StreamReader("VAT Rate.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(line)
Loop Until line Is Nothing
sr.Close()

None of them worked.
As a newbie with limited knowledge, i would apreatiate some more help.

cheers
frustrated clubriza
 
so what are the error messages you get on the first one you tried?

If you want good help you need to give us more information, we are no wizards who can see what happens in your particular case.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
hi crisse1

the error message i get is

Argument not specified for parameter 'path' of 'Public Shared Function OpenRead(path As String) As System.IO.FileStream'.

cheers for helping

clubriza
 
that's probably because you need to set the complete path of where the file is residing. something like

"c;\mytext.txt" would be better.


Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
tired this as well , no luck

TextBox.Text = IO.File.OpenText("VAT Rate.txt")

error message says

Value of type 'System.IO.StreamReader' cannot be converted to 'String'.

ahhhh
the answer is probably so simple, when you konw how

clubriza

 
tried that still got same error.

(think i might be retired by the time i finish this, lol)

clubriza
 
horraaaaa

finally got it to work

what i did was use a richtext box, set visible = false.
then used a textbox and copied the .text over from the richtext box.

Dim a
a = ".txt"
txtRate.LoadFile("VAT Rate" & a, RichTextBoxStreamType.PlainText)
TextBox.Text = txtRate.Text

i know its probably not the right way but it works really well.

If any1 wants copy of my project email me on michael@clubriza.freeserve.co.uk


clubriza

(as you probably guessed, yes this was my first real project)

 
Here is an example that populates the textbox from a file on program load, and writes it back (modified or not) on a button-click.

You could see other examples at:
under vb.net/file manipulation examples

Happy Programming!

Imports System.IO
' PC 2004-08-20
' ========================================
' module-level variable for name of file
Dim strFile As String = "TestText.txt"
'=========================================
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' The output file is written in the same file
Dim tFile As StreamWriter = File.CreateText(strFile)
tFile.WriteLine(TextBox1.Text)
tFile.Close()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Populate textbox1 on program load
Dim tFile As StreamReader = File.OpenText(strFile)
TextBox1.Text = tFile.ReadLine()
tFile.Close()
End Sub
 
Hi PC888

Thanks for showing me the correct way to do it.
I have writen that down in my note book for future
reference.

cheers

Clubriza
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top