I currently have a text file that looks like this
I need to be able to create a VBScript file that will use FileSystemObject to change the rows into columns and output the data into an html table like below
I am having a difficult time finding a method for transposing. I am new to VBscripting, I assume that I can still use the CreateTextFile method for HTML?
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("C:\Users\User.mdm\Desktop\PracticeTest\table.html", True)
MyFile.WriteLine(?)
MyFile.Close
Related
I have a database with 2 alternive picture filenames pic1 and pic2. If the first picture file does not exist i want to print the second.
in the onFormat Event of the report I want to do somthing like:
if FileExists(pic1)
Then
article.Picture=pic1
Else
article.Picture=Pic2
EndIf
But I do not succeed as the componentone vbscript is not so well documented
UPDATE
C1Report VBScrit engine does not support CreateObject, and thus this is not supported from report designer.
There are no inbuilt IO commands in VBScript. Instead, you can use FileSystemObject to check this. Use this function to determine if a file exists:
Function FileExists(filePath)
Dim fso, exists
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filePath)) Then
exists = True
Else
exists = False
End If
FileExists = exists
End Function
Use this function in your VBScript editor
I'm trying to access a file by index using vbs but Item does not work as I expected. I would rather not have to loop all files as I'm trying to avoid a treewalk. I recieve the error "Error: Invalid procedure call or argument" on the line with colFiles.Item().
Randomize
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(fFolder.Path)
Set colFiles = objFolder.Files
Set objFile = colFiles.Item(Int(colFiles.Count * Rnd))
I'm sure it's obvious, but my searching only shows example using loops.
VBScript does not support random/index access to the elements of the .Files collection. You'll have to For Each loop, pick a random file, and Exit the loop.
Update:
According to the docs, you can use a 'name' (file name, file spec(?)) as parameter to .Item(), so you could keep an array of file names/specs, pick one randomly, and access the file. Whether that would be an improvement in your case, remains to be seen.
how to force fully delete , rename and replace text file/log file in vb6. I am performing some actions on a log file and replacing original log file with a new one in the end but the application is still using the original log.
Here is the delete
Sub DeleteAFile(filePath)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(filePath)
End Sub
Just mess around with the FileSystemObject class, it has methods to delete, rename, create, etc.
I need a script to create a empty text file for each row in my csv file.
My csv file has 3 columns of data...
Along Came Polly,2003,192
American Beauty,1999,146
American Cousins,2007,286
An American Crime,2007,179
I want to create a empty text file named for each row and formatted as....
Along Came Polly (2003) Slot 192.txt
American Beauty (1999) Slot 146.txt
American Cousins (2007) Slot 286.txt
An American Crime (2007) Slot 179.txt
Can someone help me with this as I have no vb experience.
Thank you,
Tim
This is what you might be looking for
Option Explicit
Dim objFSO, objTextFile, strFileLine,objFile,strFileName
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile=objFSO.OpenTextFile("C:\Documents and Settings\amolc\Desktop\SO\Sample.csv") ''Mention Path of your CSV file here
Do Until objTextFile.atEndOfStream
strFileLine =objTextFile.ReadLine
strFileLine =Split(strFileLine,",")
strFileName=strFileLine(0)&" ("&strFileLine(1)&") "&"Slot "&strFileLine(2)&".txt"
Set objFile = objFSO.CreateTextFile("C:\Documents and Settings\amolc\Desktop\SO\"&strFileName) ''Hardcoded path is the location where you can store your text file
Loop
I am writing in vb, and using excels parameters to convert .xls documents to pdf. The process works fine because I am using a string. What I need to know is to somehow loop through the source folder and then convert all files in that folder to pdf and put in the export folder keeping the original file name. Loops are seriously the bane of my existence in programming even though I know you need it for a solid foundation in this industry.
EXAMPLE:
Dim excelApplication As ApplicationClass = New ApplicationClass()
Dim excelWorkbook As Workbook = Nothing
Dim paramSourceBookPath As String = "C:\My_Projects\Testing\filename.xls"
Dim paramExportFilePath As String = "C:\My_Projects\Testing\filename.pdf"
Thanks in advance.
Try this:
Dim dir As New IO.DirectoryInfo(path)
Dim files As IO.FileInfo() = dir.GetFiles("*.xls")
For Each file In files
'Do Something
Next