Results 1 to 9 of 9

Thread: Help with reading from file then putting into textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    12

    Unhappy 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

    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!

    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 )

    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
    Last edited by Millsie; Jul 26th, 2008 at 11:42 PM.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

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

  3. #3
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

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

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

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

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    12

    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

  6. #6

  7. #7
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

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

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    12

    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 I must say.. Thanks one more time Cause wow, The help on this forum was amazing I wish I had found this site before K, Im outties cya guys

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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
  •  



Click Here to Expand Forum to Full Width