Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > VB6 > Как обратиться к системным переменным?


Автор: Prorok 29.5.2007, 11:20
Суть задачи такова: как получить значение системных переменных, например TEMP, TMP переменных сред. Помогите пожалуйста, если знаете)

Автор: Akina 29.5.2007, 12:13
Environ("Temp")

Автор: Prorok 29.5.2007, 13:46
получилось 2 варианта:
1. Dim TempDir as String
    TempDir = Environ("Temp")
    MsgBox(TempDir)
В этом случае компилятор выдает ошибку в 1-й строке - "Предполагается наличие окончания инструкции..."

2. Dim TempDir
    TempDir = Environ("Temp")
    MsgBox(TempDir)
В этом случае выходит ошибка во 2-й строке - Несоответствие типа 'Environ'

Непонятно в чем проблема(((

Автор: mihanik 29.5.2007, 14:30
Покури GetSpecialFolder (FileSystemObject)

Цитата

GetSpecialFolder MethodSee Also
GetAbsolutePathName Method | GetBaseName Method | GetDrive Method | GetDriveName Method | GetExtensionName Method | GetFile Method | GetFileName Method | GetFileVersion Method | GetFolder Method | GetParentFolderName Method | GetTempName Method
Applies To: FileSystemObject ObjectLanguage
JScript

VBScript

Show All
Returns the special folder object specified.
object.GetSpecialFolder(folderspec)
Arguments
object 
Required. Always the name of a FileSystemObject. 
folderspec 
Required. The name of the special folder to be returned. Can be any of the constants shown in the Settings section. 
Settings
The folderspec argument can have any of the following values:
ConstantValueDescription
WindowsFolder0The Windows folder contains files installed by the Windows operating system.
SystemFolder1The System folder contains libraries, fonts, and device drivers.
TemporaryFolder2The Temp folder is used to store temporary files. Its path is found in the TMP environment variable.

The following example illustrates the use of the GetSpecialFolder method. 
[JScript]
var fso, tempfile;
fso = new ActiveXObject("Scripting.FileSystemObject");

function CreateTempFile()
{
   var tfolder, tfile, tname, fname, TemporaryFolder = 2;
   tfolder = fso.GetSpecialFolder(TemporaryFolder);
   tname = fso.GetTempName();
   tfile = tfolder.CreateTextFile(tname);
   return(tfile);
}
tempfile = CreateTempFile();
tempfile.writeline("Hello World");
tempfile.close();
[VBScript]
Dim fso, tempfile
Set fso = CreateObject("Scripting.FileSystemObject")

Function CreateTempFile 
   Dim tfolder, tname, tfile
   Const TemporaryFolder = 2
   Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
   tname = fso.GetTempName   
   Set tfile = tfolder.CreateTextFile(tname)
   Set CreateTempFile = tfile
End Function

Set tempfile = CreateTempFile
tempfile.WriteLine "Hello World"
tempfile.Close


Автор: Akina 29.5.2007, 16:02
Цитата(Prorok @  29.5.2007,  14:46 Найти цитируемый пост)
получилось 2 варианта:

Оба твоих варианта у меня компилируются и отрабатывают правильно. Вывод будет для тебя обидным...

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)