Sub recipecreator()
Dim modName As String
Dim modFolder As String
Dim modnameFolder As String
Dim modrecipeFolder As String
Dim modblockFolder As String
Dim itemName As String
Dim inputOne As String
Dim inputTwo As String
Dim inputThree As String
Dim inputoneCount As Integer
Dim inputtwoCount As Integer
Dim inputthreeCount As Integer
Dim outputCount As Integer
Dim rowCount As Integer
Dim I As Integer
modName = Sheets("Setup").Range("B2").Value
modFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator & Sheets("Setup").Range("B1").Value
modnameFolder = modFolder & "\" & modName
modrecipeFolder = modnameFolder & "\recipes"
modblockFolder = modrecipeFolder & "\blocks"
CreateFolder modFolder
CreateFolder modnameFolder
CreateFolder modrecipeFolder
CreateFolder modblockFolder
rowCount = Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
For I = 2 To rowCount
itemName = Sheets("Data").Cells(I, 1).Value
inputOne = Sheets("Data").Cells(I, 2).Value
inputoneCount = Sheets("Data").Cells(I, 3).Value
inputTwo = Sheets("Data").Cells(I, 4).Value
inputtwoCount = Sheets("Data").Cells(I, 5).Value
inputThree = Sheets("Data").Cells(I, 6).Value
inputthreeCount = Sheets("Data").Cells(I, 7).Value
outputCount = Sheets("Data").Cells(I, 8).Value
If Not inputTwo = vbNullString Then
If Not inputThree = vbNullString Then
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount, inputTwo, inputtwoCount, inputThree, inputthreeCount
Else
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount, inputTwo, inputtwoCount
End If
Else
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount
End If
Next I
End Sub
Function CreateFolder(name As String)
If Len(Dir(name, vbDirectory)) = 0 Then
MkDir name
End If
End Function
Function CreateTextFile(modblockFolder As String, modName As String, itemName As String, inputOne As String, inputoneCount As Integer, outputCount As Integer _
, Optional inputTwo As String, Optional inputtwoCount As Integer, Optional inputThree As String, Optional inputthreeCount As Integer)
Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.CreateTextFile(modblockFolder & "\" & modName & "_" & itemName & ".recipe", True)
ts.WriteLine ("{")
ts.WriteLine (" ""input"" : [")
ts.WriteLine (" { ""item"" : """ & inputOne & """, ""count"" : " & inputoneCount & " }")
If Not inputTwo = vbNullString Then
ts.WriteLine (" { ""item"" : """ & inputTwo & """, ""count"" : " & inputtwoCount & " }")
End If
If Not inputThree = vbNullString Then
ts.WriteLine (" { ""item"" : """ & inputThree & """, ""count"" : " & inputthreeCount & " }")
End If
ts.WriteLine (" ],")
ts.WriteLine (" ""output"" : { ""item"" : """ & itemName & """, ""count"" : " & outputCount & " },")
ts.WriteLine (" ""groups"" : [ ""craftingtable"", ""materials"", ""all"" ]")
ts.WriteLine ("}")
End Function
Getting an "subscript out of range" on this line here,
modName = Sheets("Setup").Range("B2").Value
What is wrong with it? Thank you for any input, while your at it if you can is there anything else that is wrong?
Dim modName As String
Dim modFolder As String
Dim modnameFolder As String
Dim modrecipeFolder As String
Dim modblockFolder As String
Dim itemName As String
Dim inputOne As String
Dim inputTwo As String
Dim inputThree As String
Dim inputoneCount As Integer
Dim inputtwoCount As Integer
Dim inputthreeCount As Integer
Dim outputCount As Integer
Dim rowCount As Integer
Dim I As Integer
modName = Sheets("Setup").Range("B2").Value
modFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator & Sheets("Setup").Range("B1").Value
modnameFolder = modFolder & "\" & modName
modrecipeFolder = modnameFolder & "\recipes"
modblockFolder = modrecipeFolder & "\blocks"
CreateFolder modFolder
CreateFolder modnameFolder
CreateFolder modrecipeFolder
CreateFolder modblockFolder
rowCount = Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
For I = 2 To rowCount
itemName = Sheets("Data").Cells(I, 1).Value
inputOne = Sheets("Data").Cells(I, 2).Value
inputoneCount = Sheets("Data").Cells(I, 3).Value
inputTwo = Sheets("Data").Cells(I, 4).Value
inputtwoCount = Sheets("Data").Cells(I, 5).Value
inputThree = Sheets("Data").Cells(I, 6).Value
inputthreeCount = Sheets("Data").Cells(I, 7).Value
outputCount = Sheets("Data").Cells(I, 8).Value
If Not inputTwo = vbNullString Then
If Not inputThree = vbNullString Then
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount, inputTwo, inputtwoCount, inputThree, inputthreeCount
Else
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount, inputTwo, inputtwoCount
End If
Else
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount
End If
Next I
End Sub
Function CreateFolder(name As String)
If Len(Dir(name, vbDirectory)) = 0 Then
MkDir name
End If
End Function
Function CreateTextFile(modblockFolder As String, modName As String, itemName As String, inputOne As String, inputoneCount As Integer, outputCount As Integer _
, Optional inputTwo As String, Optional inputtwoCount As Integer, Optional inputThree As String, Optional inputthreeCount As Integer)
Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.CreateTextFile(modblockFolder & "\" & modName & "_" & itemName & ".recipe", True)
ts.WriteLine ("{")
ts.WriteLine (" ""input"" : [")
ts.WriteLine (" { ""item"" : """ & inputOne & """, ""count"" : " & inputoneCount & " }")
If Not inputTwo = vbNullString Then
ts.WriteLine (" { ""item"" : """ & inputTwo & """, ""count"" : " & inputtwoCount & " }")
End If
If Not inputThree = vbNullString Then
ts.WriteLine (" { ""item"" : """ & inputThree & """, ""count"" : " & inputthreeCount & " }")
End If
ts.WriteLine (" ],")
ts.WriteLine (" ""output"" : { ""item"" : """ & itemName & """, ""count"" : " & outputCount & " },")
ts.WriteLine (" ""groups"" : [ ""craftingtable"", ""materials"", ""all"" ]")
ts.WriteLine ("}")
End Function
Getting an "subscript out of range" on this line here,
modName = Sheets("Setup").Range("B2").Value
What is wrong with it? Thank you for any input, while your at it if you can is there anything else that is wrong?