VBA to JavaScript
I have a VB script I did for CorelDraw. It utilizes a .txt file. On that file is a number (a Doc Number). When I run my VB script, it would open a New Document, Name it with the "Doc Number" on the .txt File + 1 and store the new document file name (not including the extension) back to the text file.
So, lets say the txt file had 102 in it. When I ran my script a new document would open and be named 103. 103 (which is the active doc name) will then be stored back to the txt file (with no extension). The next person who runs the script gets a new document of 104. You get the picture. It is done this way for a purpose. We utilize one txt file and name our document this way to avoid duplicate documents or overwriting.
It's basically creating new document ID Numbers in a numeric fashion. The number will count up by 1 every time the script is run by 1.
I'm transitioning to JavaScript / Photoshop. How would this VB Script look converted over?
I think it would work the same.
1. Create a New Photoshop Document
2. Name it with the number on the txt file and add 1 to it.
3. Store Newly Created Document Name back to txt file (minus the extension).
CODE BELOW:
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
'----------------------------------------------------------------- Folder Path
On Error Resume Next
FilePath = "C:\Users\KoolKATZDesigns\Desktop\Script Tests\" & "Names" & ".txt"
'----------------------------------------------------------------- Get String (Proof Number) From Text File.
TextFile = FreeFile
'On Error GoTo ErrHandler
Open FilePath For Input As TextFile
Line Input #TextFile, FileContent
Close #TextFile
'------------------------------------------------- Creates New Document
Dim doc1 As Document
Set doc1 = CreateDocument()
doc1.Name = FileContent + 1
'------------------------------------------------- Stores New Proof Number
Open FilePath For Output As TextFile
On Error Resume Next
Print #TextFile, ActiveDocument.Name
Close TextFile
ExitSub:
Exit Sub
ErrHandler:
MsgBox "I'm Misbehaving. Tell Chieri." & vbCr & "Error occured: " & Err.Description
Resume ExitSub
End Sub
