Hyluss

[VisualBasic] Create File in Unity

Dec 30th, 2019
469
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '---- I Module ----
  2. Option Explicit
  3.  
  4. Sub WriteCS()
  5.  
  6. Dim fso As FileSystemObject
  7. Dim fsoFile As TextStream
  8.  
  9. Set fso = New FileSystemObject
  10.  
  11. ' TristateTrue - uzycie unicode
  12. Set fsoFile = fso.OpenTextFile(GetPath & "\Test.cs", ForWriting, True, TristateTrue)
  13.  
  14. fsoFile.WriteLine "Hello world"
  15. fsoFile.Close
  16.  
  17. End Sub
  18.  
  19. '---- II Module ----
  20.  
  21. 'deklaracja zmiennych musi byc jawna
  22. Option Explicit
  23.  
  24. ' function - zwraca wartosc
  25. Function GetPath()
  26.  
  27. Dim path As String
  28. 'pobranie sciezki pliku
  29. path = ThisWorkbook.path
  30.  
  31. Dim processedPath As String
  32. processedPath = ""
  33.  
  34. ' przedrostek sciezki
  35. Dim pathSuffix As String
  36. pathSuffix = "\Scripts\Static\StringTables"
  37.  
  38.  
  39. ' Wyswieltenie wszystkiego do ostatniego znaku "/"
  40. ' ---
  41. Dim cLoop As Long
  42. Dim cLimit As Long
  43. cLimit = Len(path)
  44.  
  45. For cLoop = 1 To cLimit
  46.     If Mid(path, cLoop, 1) = "\" Then
  47.         processedPath = Left(path, cLoop - 1)
  48.     End If
  49.    
  50. Next cLoop
  51. ' ---
  52.  
  53. ' wyswietlenie sciezki
  54. ' MsgBox path & vbCrLf & processedPath
  55.  
  56.  
  57. GetPath = processedPath & pathSuffix
  58.  
  59. End Function
  60.  
  61. Sub Test()
  62.  
  63. MsgBox GetPath
  64.  
  65. End Sub
RAW Paste Data