[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Trouble with export text in visual basic to .txt file

Posted on 2012-12-27
2
Medium Priority
?
300 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
[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
2 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 38723513
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 750 total points
ID: 38724436
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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 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