Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
chris_johnson
Creator III
Creator III

Basic vbScript help

Hi,

Trying to do something simple (or so I thought) but not working and possibly going to send me over the edge....

I'm trying to write a line out to a text file but both looking at the example in the API Guide and in the few forum posts here I still can't get anything to output.

Here's what I'm doing:

sub CreateTextOutput

          set v = ActiveDocument.Variables("vFullPath")

          vLocalPath = v.GetContent.String

          Set objFSO = CreateObject("Scripting.FileSystemObject")

          Set objFile = objFSO.CreateTextFile(vLocalPath, true)

          'Export Header Line and spacing line

          set FileStream = objFile.OpenAsTextStream(8)

          FileStream.WriteLine vLocalPath

          FileStream.WriteBlankLines 1

          FileStream.Close

          objFile.Close

end sub

where vFullPath is set to a file location on my local hard drive.

The result is that I get the file created in the location but with nothing in the file itself.

Anyone see what I'm doing wrong?

Chris

Labels (1)
3 Replies
tom_tierney
Contributor
Contributor

Not quite sure I understand what you are trying to do but the following macro will simply create and write to a text file.

You can set the vFullPath variable in the Document QV script or from Document > Settimgs > Vaiable Overview.

Npte the vFullPath needs the directory and file name. e.g. c:\temp\myfile.txt

sub CreateTextOutput



          set v = ActiveDocument.Variables("vFullPath")

         

          vLocalPath = v.GetContent.String



          set objFSO = CreateObject("Scripting.FileSystemObject")



          set FileStream = objFSO.OpenTextFile(vLocalPath, 2, true) 'Change 2 to 8 for append



          FileStream.WriteLine("xxxx")



          FileStream.Close()



end sub

jeremy_fourman
Luminary
Luminary

Haven't used vbscript in awhile but do you need to specify an append mode? Would the last WriteBlankLines be overwriting the vLocalPath line already added. Just a guess.

FileStream.WriteLine vLocalPath

FileStream.WriteBlankLines 1

chris_johnson
Creator III
Creator III
Author

Hi both,

Yes Tom, you are correct in so far as I'm just trying to write a line out to a text file. In the end I'm trying to create a text file with a header row, a blank line and then the contents of a straight table. The file is for importing into a seperate system (Hyperion).

I ended up getting somewhere this morning by not using the File Stream object at all and just doing a file.writeline.

Jeremy, you are correct in what you are saying too in that I will write a line out to a file and then use an append function to add chart data to it. I tried to use chart.AppendExport but ended up getting html out instead of the data itself which was a bit confusing; especially since I used the chart.Export function previously to test out the result and got all of the data out as I wanted it.

Going to keep plugging away at it, using macros is proving to be a bit of a nightmare though.

Thanks,


Chris