|
-
Jul 26th, 2008, 09:19 PM
#1
Thread Starter
New Member
Help with reading from file then putting into textbox
Last edited by Millsie; Jul 26th, 2008 at 11:42 PM.
-
Jul 27th, 2008, 08:55 AM
#2
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
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 27th, 2008, 11:36 AM
#3
Re: Help with reading from file then putting into textbox
 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
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.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jul 27th, 2008, 11:57 AM
#4
Re: Help with reading from file then putting into textbox
 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  ....
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.
-
Jul 27th, 2008, 04:21 PM
#5
Thread Starter
New Member
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
-
Jul 27th, 2008, 04:41 PM
#6
Re: Help with reading from file then putting into textbox
-
Jul 27th, 2008, 08:51 PM
#7
Re: Help with reading from file then putting into textbox
Use a common dialog controt for browsing a file in your computer.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 28th, 2008, 08:09 AM
#8
Thread Starter
New Member
-
Jul 28th, 2008, 08:24 AM
#9
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|