Solved

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

Posted on 2006-06-13
7
150 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now