Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I write text data to a text box instead of a text file?

Posted on 2006-06-13
7
Medium Priority
?
159 Views
Last Modified: 2010-04-30
Hi

I have been outputting data to a txt file which works fine. But rather than a txt file I need to use an open window with a text box. Lines of text are continually entered one at a time.
I use the following to open the file and write the data

Public Function WriteLineToFile(ByVal filename As String, ByVal outputLine As String)
    On Error GoTo fileError
   
    Dim ff As Integer
    ff = FreeFile
    Open filename For Append As #ff
    Print #ff, outputLine
    Close #ff
    Exit Function
   
fileError:
    MsgBox "Error writing to " & filename & vbCrLf & err.Description, vbExclamation, "Error " & err.Number
End Function

and the following under the click button
 WriteLineToFile outputlog, "Logged on user:" & "  " & name & "  " & Date & "  " & Time & "  " & "FFT" & " " & "Image Name:" & "  " & imagename

Here output log is a file, I want to change it to a text box. I have tried but keep getting errors

Experts can you help?
0
Comment
Question by:eneate
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 14

Expert Comment

by:StillUnAware
ID: 16898082
First of all You have to create a form and add a TextBox to it, then add text to it

textBox1.Text = textBox1.Text & "Logged on user:" & "  " & name & "  " & Date & "  " & Time & "  " & "FFT" & " " & "Image Name:" & "  " & imagename
0
 

Author Comment

by:eneate
ID: 16898312
That works. I have it behind a command button when the button is clicked the text is added to the box. However liek this it only enter the line onnce. Every time the button is clicked I need it to go to the next line and print the same thing again. It is to be used as a image history.
Thanks
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 2000 total points
ID: 16898369

you can use this code:

Public Function WriteLineToTextbox(ByVal txtBox As TextBox, ByVal outputLine As String)
   txtBox.Text = txtBox.Text & vbCrLf & outputLine
End Function


usage:

Private Sub Command1_Click()
   WriteLineToTextbox Text1, "This is the first line!"
   WriteLineToTextbox Text1, "this is the second line"
   WriteLineToTextbox Text1, "and this the third"
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:eneate
ID: 16898500
Thanks that works. Is there a way to make it so that the user can not deleate or edit the text. Read only
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16898521

yes
in code:
text1.locked = true

in properties:

set the option locked from text 1 to true
0
 

Author Comment

by:eneate
ID: 16898531
Thank very much it works very well.
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16898559

thanks for the points, and happy coding!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question