Solved

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

Posted on 2006-06-13
7
154 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 500 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
Industry Leaders: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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