?
Solved

Trouble with export text in visual basic to .txt file

Posted on 2012-12-27
2
Medium Priority
?
296 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 52

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

800 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