Help with reading from file then putting into textbox
Hey guys first to point out i'm new to the forums so please if I break any rules during this post i'm sorry :D
This is for a school project and myself and my friend a completely clueless on what to do for some of these coding practices. So if you could help on a few things I would be forever grateful and I would also worship you :) Haha
K, First Off I need help with printing to a text box from a saved file on my computer. I think a guy said in my class that I need to create an array?
So yeah, I figured out on my own on how to print the text box and how to write to disk. I also have a read from disk program at school but I don't know how to adapt it to this problem here.
Also, I need to total up the persons order in the text box. how would I do that?
Uhm Here comes the files just to show you what I have to do. I'll upload them to Rapidshare and the files shouldn't be over 100kb I promis! :D
Code:
http://rapidshare.com/files/132735898/Student_Assessment.rar.html
(This includes documentation on what I have to do. What the program looks like so far. And alittle test program that doesn't work :D)
So yeah, If you could Please!!! Help I would be forever greatful. Even if you point me to a place that can tell me what to do :) Orr!! If you just want to help out with one of the problems here I would also be very greatful Haha
Thanks for reading
Re: Help with reading from file then putting into textbox
For loading data from a file, use this code:
Code:
Private Sub cmdLoad_Click()
Dim k As Integer
Dim strFile, tempData As String
Text1.Text = ""
k = FreeFile
strFile = "c:\test.txt"
Open strFile For Input As #k
While Not EOF(k)
Line Input #k, tempData
Text1.Text = Text1.Text & tempData & vbCrLf
Wend
Close #k
End Sub
Don't forget to enable the MultiLine property of the Textbox to True
For saving data from the textbox to a file, use the below code:
Code:
Private Sub cmdSave_Click()
Dim k As Integer
Dim strFile As String
k = FreeFile
strFile = "c:\test.txt"
Open strFile For Output As #k 'or Append
Print #k, Text1.Text
Close #k
End Sub
Re: Help with reading from file then putting into textbox
Quote:
Originally Posted by Millsie
Hey guys first to point out i'm new to the forums so please if I break any rules during this post i'm sorry :D
Welcome to VBforums Millsie.
Yes you should have read Before you post....
This question as been asked many times so its always a good idea to search before hand.
Anyway opening a Text file into a TextBox.
Code:
Private Sub cmdLoad_Click()
Dim k As Integer
Text1.Text = ""
k = FreeFile()
Open "c:\test.txt" For Input As #k
Text1.Text = Input$(LOF(k), #k)
Close #k
End Sub
You don't have to read each line as akhileshbc stated LOF Length of File is quicker.
akhileshbc code is straight forward for saving the text in the TextBox. ;)
Re: Help with reading from file then putting into textbox
Quote:
Originally Posted by Millsie
Hey guys first to point out i'm new to the forums so please if I break any rules during this post i'm sorry :D ....
You're not really breaking any rule but we prefer that you attach files to a post (perhaps a zip file) by way of the Manage Attachments button that you find in the Additional Options Frame below the area where you compose a new post rather than linking to another site.
Re: Help with reading from file then putting into textbox
Ok then. What about reading from a textfile saved on my computer then putting it into a text box? thanks :)
Re: Help with reading from file then putting into textbox
Re: Help with reading from file then putting into textbox
Use a common dialog controt for browsing a file in your computer.
Re: Help with reading from file then putting into textbox
Right thanks guys!!! This will surely allow me to pass the assement! Sorry Keithuk, If you do go into this topic again I didn't see that code that you put in your post the first time I skimmed through the messages :D I must say.. Thanks one more time :) Cause wow, The help on this forum was amazing :) I wish I had found this site before :D K, Im outties cya guys
Re: Help with reading from file then putting into textbox
Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer. Also if someone has been particularly helpful you have the ability to affect a their forum "reputation" by rating their post. Your ratings won't actually count until you have 20 posts, but the person you rate will see it and know that you appreciate their help.