VARIANT

(no version information, might be only in CVS)

VARIANT -- VARIANT 类

大纲

$vVar = new VARIANT($var)

描述

用于将变量封装进 VARIANT 结构中的简单容器。

方法

string VARIANT::VARIANT ( [mixed value [, int type [, int codepage]]] )

VARIANT 类构造函数。参数:

value

初始值。若省略则创建一个 VT_EMPTY 对象。

type

指定 VARIANT 对象的内容类型。可用的值为 VT_UI1VT_UI2VT_UI4VT_I1VT_I2VT_I4VT_R4VT_R8VT_INTVT_UINTVT_BOOLVT_ERRORVT_CYVT_DATEVT_BSTRVT_DECIMALVT_UNKNOWNVT_DISPATCHVT_VARIANT。这些值相互排斥,但是可以使用 VT_BYREF 将它们联合起来指定为一个值。若省略,则使用参数 value 的类型。额外信息请查阅 msdn 库。

codepage

指定用于将 PHP 字符串(php-strings)转换成 UNICODE 字符串(unicode-strings)的代码页,反之亦然。可用的值为 CP_ACPCP_MACCPCP_OEMCPCP_SYMBOLCP_THREAD_ACP, CP_UTF7CP_UTF8


add a note add a note User Contributed Notes
mark dot pearson at capita dot co dot uk
30-Oct-2003 03:51
Running PHP 4.3.2 on Windows 2000 I had to use the following expression to create an empty Variant:

<?php
 $empty
= new Variant(null);
 print
$empty->type //    ==>  1
?>

NOT

<?php
 $empty
= new Variant();
 print
$empty->type //    ==>  0
?>

The two expressions return different Variant type values!
richard dot quadling at carval dot co dot uk
26-Feb-2003 09:50
With thanks to Harald Radi and Wez Furlong.

Some VBA functions have optional parameters. Sometimes the parameters you want to pass are not consecutive.

e.g.

GoTo What:=wdGoToBookmark, Name="BookMarkName"
GoTo(wdGoToBookmark,,,"BookMarkName)

In PHP, the "blank" parameters need to be empty.

Which is ...

<?php
// Some servers may have an auto timeout, so take as long as you want.
set_time_limit(0);

// Show all errors, warnings and notices whilst developing.
error_reporting(E_ALL);

// Used as a placeholder in certain COM functions where no parameter is required.
$empty = new VARIANT();

// Load the appropriate type library.
com_load_typelib('Word.Application');

// Create an object to use.
$word = new COM('word.application') or die('Unable to load Word');
print
"Loaded Word, version {$word->Version}\n";

// Open a new document with bookmarks of YourName and YourAge.
$word->Documents->Open('C:/Unfilled.DOC');

// Fill in the information from the form.
$word->Selection->GoTo(wdGoToBookmark,$empty,$empty,'YourName'); // Note use of wdGoToBookmark, from the typelibrary and the use of $empty.
$word->Selection->TypeText($_GET['YourName']);

$word->Selection->GoTo(wdGoToBookmark,$empty,$empty,'YourAge');
$word->Selection->TypeText($_GET['YourAge']);

// Save it, close word and finish.
$word->Documents[1]->SaveAs("C:/{$_GET['YourName']}.doc");
$word->Quit();
$word->Release();
$word = null;
print
"Word closed.\n";
?>

The example document is ...

Hello [Bookmark of YourName], you are [Bookmark of YourAge] years old.

and it would be called ...

word.php?YourName=Richard%20Quadling&YourAge=35

Regards,

Richard.
alain at samoun dot com
03-Sep-2001 04:37
<?php
# I think that we need some examples of this thing:
# Lets define a real variant:
$varREAL=  new Variant("9.34 is a real number",VT_R8);
print
"Value:". $varREAL->value; # Will print 9.34
# Now an integer
 
$varINT=  new Variant("9.34 Printed as an integer",VT_INT);
print
"Value:". $varINT->value; # Will print 9
# Now a string
 
$varSTR=  new Variant("9.34 Printed as a string",VT_BSTR);
print
"Value:". $varSTR->value; # Will 9.34 Printed as a string
    
?>