che sto cercando di scrivere l'equivalente di VBScript di una funzione simile a ciò che è in basso:Restituisce Null o Nothing dalla funzione VBScript?
object getObject(str)
{
if (...)
{
return object_goes_here;
}
return null;
}
La mia ipotesi è al di sotto, solo che non sto capire la differenza tra il nulla e Null. Come chiamante, preferirei verificare se il valore di ritorno è impostato utilizzando IsNull()
rispetto a X Is Nothing
.
Function getObject(str)
If ... Then
Set getObject = object_goes_here
Exit Function
End If
Set getObject = Nothing // <-- or should this be Null?
End Function
In che modo InStr riesce a farla franca? Sembra che restituisca l'equivalente .NET di Nullable. http://www.w3schools.com/vbscript/func_instr.asp –
jglouie
@jglouie 'InStr' accetta un' VARIANT' come parametro, non un oggetto. Quindi esamina il 'VARIANT' e prova a darti quello che ti aspettavi. Restituire un 'Null' se un operando stringa è' Null' è un concetto comune molto standard proveniente da database. Per quanto riguarda le stringhe in VB6 (e VBScript), non sono comunque oggetti, non possono essere 'Nothing'. Beh, sono in grado di farlo, ma si chiama 'vbNullString' e non viene rilevato con' Is Nothing'. – GSerg