Solved

Trouble with export text in visual basic to .txt file

Posted on 2012-12-27
2
288 Views
Last Modified: 2012-12-31
Hi:

I've produced the following code:

Public Class background

    Dim stRep As String
    Dim strReport As String
    Dim oFSO As Object
    Dim objReport As Object

    Private Sub MakeFile1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MakeFile1.Click
        strReport = "report.txt"

        stRep = InputBox(TextBox1.Text)
        SetAttr(oFSO = CreateObject("Scripting.FileSystemObject"))
        SetAttr(objReport = oFSO.CreateTextFile(strReport, True))

        If oFSO.FolderExists(stRep) Then
            For Each oF1 In oFSO.GetFolder(stRep).Files
                objReport.WriteLine(oF1.Name)
            Next
        End If

        objReport.Close()

    End Sub

    Private Sub SetAttr(ByVal p1 As Object)
        Throw New NotImplementedException
    End Sub

End Class
=================================
The goal is to create a .txt file and append it if it already exists.  I'm working in VB 2010.  However, the bolded line is giving me trouble.  I've received the following message at runtime....

Operator '=' is not defined for 'Nothing' and type 'FileSystemObject'.

Any ideas on how to address this?  I will keep doing research, but would appreciate feedback!

Robert
0
Comment
Question by:RobertGeoff
2 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

Did you check the reference?

Shouldn't it be
 SetAttr(Set oFSO = CreateObject("Scripting.FileSystemObject"))

go on the safe side and do
Set oFSO = CreateObject("Scripting.FileSystemObject")

 SetAttr oFSO


Regards
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
Comment Utility
You are working with VB2010 and yet you wrote VB6 code!

>The goal is to create a .txt file and append it if it already exists.

Use

System.IO.File.AppendAllText("filepath", "text to append")

It will create the file if it does not exist and append to existing file if it already exists.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

18 Experts available now in Live!

Get 1:1 Help Now