vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Zippen wie die Profis!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Allgemeine Diskussionen
Ein Ansatz zu 1.: 
Autor: unbekannt
Datum: 20.08.01 14:01

Hi Tolwyn,

durch die VBA-Gemeinde geistert die EVAL-Function, die genau das macht. Allerdings habe ich bislang noch keinen Verweis herstellen können, zu dieser Funktion in VB zu gelangen. Die Funktion ist jedenfalls in der MSDN als eine Office '97 und Office '95 Funktion definert, wobei sich Microsoft so ausdrückt:


Eval Function
Description

You can use the Eval function to evaluate an expression that results in a text string or a numeric value.

You can construct a string and then pass it to the Eval function as if the string were an actual expression. The Eval function evaluates the string expression and returns its value. For example, Eval("1 + 1") returns 2.

If you pass to the Eval function a string that contains the name of a function, the Eval function returns the return value of the function. For example, Eval("Chr$(65)") returns "A".

Syntax

Eval(stringexpr)

The stringexpr argument is an expression that evaluates to an alphanumeric text string. For example, stringexpr can be a function that returns a string or a numeric value. Or it can be a reference to a control on a form. The stringexpr argument must evaluate to a string or numeric value; it can't evaluate to a Microsoft Access object.

Note If you are passing the name of a function to the Eval function, you must include parentheses after the name of the function in the stringexpr argument. For example:

Debug.Print Eval("ShowNames()") ' ShowNames is user-defined

' function.

Debug.Print Eval("StrComp(""Joe"",""joe"", 1)")

Debug.Print Eval("Date()")

Remarks

You can use the Eval function in a calculated control on a form or report, or in a macro or module. The Eval function returns a Variant that is either a string or a numeric type.

The argument stringexpr must be an expression that is stored in a string. If you pass to the Eval function a string that doesn't contain a numeric expression or a function name but only a simple text string, a run-time error occurs. For example, Eval("Smith") results in an error.

You can use the Eval function to determine the value stored in the Value property of a control. The following example passes a string containing a full reference to a control to the Eval function. It then displays the current value of the control in a dialog box.

Dim ctl As Control, strCtl As String
Set ctl = Forms!Employees!LastName
strCtl = "Forms!Employees!LastName"
MsgBox ("The current value of " & ctl.Name & " is " & Eval(strCtl))
You can use the Eval function to access expression operators that aren't ordinarily available in Visual Basic. For example, you can't use the SQL operators Between...And or In directly in your code, but you can use them in an expression passed to the Eval function.

The next example determines whether the value of a ShipRegion control on an Orders form is one of several specified state abbreviations. If the field contains one of the abbreviations, intState will be True (–1). Note that you use single quotation marks (') to include a string within another string.

Dim intState As Integer
intState = Eval("Forms!Orders!ShipRegion In " _
& "('AK', 'CA', 'ID', 'WA', 'MT', 'NM', 'OR')")
See Also

Choose function, IIf function, Switch function.

Example

The following example assumes that you have a series of 50 functions defined as A1, A2, and so on. This example uses the Eval function to call each function in the series.

Sub CallSeries()
Dim intI As Integer

For intI = 1 To 50
Eval("A" & intI & "()")
Next intI
End Sub
The next example triggers a Click event as if the user had clicked a button on a form. If the value of the button's OnClick property begins with an equal sign (=), signifying that it is the name of a function, the Eval function calls the function, which is equivalent to triggering the Click event. If the value doesn't begin with an equal sign, then the value must name a macro. The RunMacro method of the DoCmd object runs the named macro.

Dim ctl As Control, varTemp As Variant

Set ctl = Forms!Contacts!HelpButton
If (Left(ctl.OnClick, 1) = "=") Then
varTemp = Eval(Mid(ctl.OnClick,2))
Else
DoCmd.RunMacro ctl.OnClick
End If

Wenn also jemand einen Verweis kennen würde, wäre man ein Stück weiter.

In Excel jedenfalls gibt es die Evaluate-Funktion, die das 100 pro erledigt!


cu
Lordchen
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Wie kann ich einen code aus einer textbox ausführen?71Tux12Fun20.08.01 10:41
Re: Wie kann ich einen code aus einer textbox ausführen?59Tolwyn20.08.01 12:08
Ein Ansatz zu 1.:331unbekannt20.08.01 14:01
Re: Ein Ansatz zu 1.:43Tolwyn20.08.01 15:47

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel