Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Help please with this line of code 1

Status
Not open for further replies.

seanybravo

IS-IT--Management
Sep 24, 2003
89
GB
Could someone please help me with the syntax with this line if code in my VB application:

if txtDataEntry(20).Text adorsemployee("fldEmployeefrom") then

<5 is stored in fldEmployeefrom

Thanks

Sean
 
The reason that won't work is because there is no function being used to compare the two variables.

I have written a class in the past to evaluate the string representation of an equation.

For a simple equation such as the one you have there the following would work:

Code:
public function Evaluate(Val as Double, Equation as String) as Boolean
dim strComparison as String
dim dblCompareTo as Double

strComparison=Left(Equation,1)
dblCompareTo=cdbl(mid(Equation,2))

Select Case strComparison
Case "="
    Evaluate = Val = dblCompareTo
Case "<"
    Evaluate = Val < dblCompareTo
Case ">"
    Evaluate = Val > dblCompareTo
End Select

end function

...

if Evaluate(txtDataEntry(20).Text,adorsemployee("fldEmployeefrom")) then
 
Neil

Thank you for you reply thats great. I have got another slight problem with the code.

The code is to automatically sort out employee banding in my application. I have planned the Banding infomation to be stored like:

A >= 5
B >5 and <= 10

...in two database fields.

Here is my code:

Private Sub txtDataEntry_Change(index As Integer)

ListingsChange = 1
Me.cmdDataEntryControl(7).Enabled = True

'Code for the automatic employee banding
If index = 20 Then
Dim temp
Dim i As Integer
If txtDataEntry(20).Text <> "" Then
AdoRsEmployee.MoveFirst
For i = 1 To AdoRsEmployee.RecordCount
temp = AdoRsEmployee!fldemployeefrom
If Evaluate(txtDataEntry(20).Text, AdoRsEmployee("fldEmployeefrom")) Then
txtDataEntry(21).Text = AdoRsEmployee("fldemployeeband")
End If
AdoRsEmployee.MoveNext
Next
Else
txtDataEntry(21).Text = ""
End If
End If

End Sub

Any Ideas to help me I'm stummped.

Many thanks

Sean
 
Here's a slightly more flexible EvalString function:
Code:
[blue]Private Function EvalString(strExpression As String) As Variant
    With CreateObject("MSScriptControl.ScriptControl")
        .Language = "vbscript"
        EvalString = .Eval(strExpression)
    End With
End Function[/blue]
And an example of calling it illustrating your originally posed problem
Code:
[blue]Private Sub Command1_Click()
    Dim a As String
    Dim b As String
    
    a = "10"
    b = "<5"
    MsgBox EvalString(a + b)
End Sub[/blue]
 
strongm

Sorry for the delay in responding. Thank you very much works great just what I was looking for.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top