Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Logical String Evaluation

Does anyone know how to evaluate a logical string in VBA? An example of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Logical String Evaluation


If Month = 4 Then
... whatever

--

HTH

RP
(remove nothere from the email address if mailing direct)


"VBA Dabbler" wrote in message
...
Does anyone know how to evaluate a logical string in VBA? An example of

one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Logical String Evaluation

Do you mean, simply:

If Month = 4 Then
...
...
End If


"VBA Dabbler" wrote:

Does anyone know how to evaluate a logical string in VBA? An example of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Logical String Evaluation

Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An example

of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Logical String Evaluation

I think you mean

Application.Evaluate(month = 4)

as month is a variable, which seems a pointless use of Evaluate to me when
you can do an If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mark Bigelow" wrote in message
oups.com...
Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An example

of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Logical String Evaluation

No, I want to evaluate the string as though it were 'code', and the string
can change for subsequent evaluations.

The example I gave, however, would error on 'Type mismatch'.

Thanks,
VBA Dabbler

"Bob Phillips" wrote:

I think you mean

Application.Evaluate(month = 4)

as month is a variable, which seems a pointless use of Evaluate to me when
you can do an If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mark Bigelow" wrote in message
oups.com...
Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An example

of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Logical String Evaluation

I was responding to Mark.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"VBA Dabbler" wrote in message
...
No, I want to evaluate the string as though it were 'code', and the string
can change for subsequent evaluations.

The example I gave, however, would error on 'Type mismatch'.

Thanks,
VBA Dabbler

"Bob Phillips" wrote:

I think you mean

Application.Evaluate(month = 4)

as month is a variable, which seems a pointless use of Evaluate to me

when
you can do an If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mark Bigelow" wrote in message
oups.com...
Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An

example
of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Logical String Evaluation

Sub Tester1()
Dim m As Long
m = 4
Dim sStr As String
sStr = "m=4"
Debug.Print Evaluate(sStr)

End Sub

returns Error 2009

If that is what you were suggesting. the evaluate command has no knowledge
of VBA variables. It is a virtual worksheet cell.

--
Regards,
Tom Ogilvy


"Mark Bigelow" wrote in message
oups.com...
Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An example

of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Logical String Evaluation

You're right. However, the string would be concatenated with literals for
comparison. Hence, if m=4, as you have it, the concatenated string to be
evaluated would be "4=4".

"Tom Ogilvy" wrote:

Sub Tester1()
Dim m As Long
m = 4
Dim sStr As String
sStr = "m=4"
Debug.Print Evaluate(sStr)

End Sub

returns Error 2009

If that is what you were suggesting. the evaluate command has no knowledge
of VBA variables. It is a virtual worksheet cell.

--
Regards,
Tom Ogilvy


"Mark Bigelow" wrote in message
oups.com...
Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An example

of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler





  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Logical String Evaluation

An example of one
is:


"Month=4"


Again, that isn't the question you asked.

--
Regards,
Tom Ogilvy


"VBA Dabbler" wrote in message
...
You're right. However, the string would be concatenated with literals for
comparison. Hence, if m=4, as you have it, the concatenated string to be
evaluated would be "4=4".

"Tom Ogilvy" wrote:

Sub Tester1()
Dim m As Long
m = 4
Dim sStr As String
sStr = "m=4"
Debug.Print Evaluate(sStr)

End Sub

returns Error 2009

If that is what you were suggesting. the evaluate command has no

knowledge
of VBA variables. It is a virtual worksheet cell.

--
Regards,
Tom Ogilvy


"Mark Bigelow" wrote in message
oups.com...
Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An

example
of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler








  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Logical String Evaluation

Thanks for pointing me back to the evaluate method - I had tried it
unsuccessfully and started looking elsewhere.

I did get it to work.

Thanks,
VBA Dabbler

"Mark Bigelow" wrote:

Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An example

of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Logical String Evaluation

How about showing us what works.

--
Regards,
Tom Ogilvy

"VBA Dabbler" wrote in message
...
Thanks for pointing me back to the evaluate method - I had tried it
unsuccessfully and started looking elsewhere.

I did get it to work.

Thanks,
VBA Dabbler

"Mark Bigelow" wrote:

Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An example

of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler





  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Logical String Evaluation

Certainly. Try this.

MonthNumber = 4
OperatorString = "="
CriteriaValue = 4
If Evaluate(MonthNumber & OperatorString & CriteriaValue) Then
Msgbox "It Works!"
End If

"Tom Ogilvy" wrote:

How about showing us what works.

--
Regards,
Tom Ogilvy

"VBA Dabbler" wrote in message
...
Thanks for pointing me back to the evaluate method - I had tried it
unsuccessfully and started looking elsewhere.

I did get it to work.

Thanks,
VBA Dabbler

"Mark Bigelow" wrote:

Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An example
of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler





  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Logical String Evaluation

Hello,

I tried it and something else:

Sub OddStuff()
Dim mNum As Long, opStr As String, myCrit As Long
mNum = 4
opStr = "="
myCrit = 4
If Evaluate(mNum & opStr & myCrit) Then _
MsgBox "It Works! But not very well!"
End Sub

Sub ConventionalVB()
Dim mNum As String
Const MY_CRIT As Long = 4
Let mNum = "Month=4"
If Val(Mid$(mNum, InStr(1, mNum, "=", vbBinaryCompare) + 1, Len(mNum))) _
= MY_CRIT Then MsgBox "It Works!"
End Sub

Looks like OddStuff() is about ~450% slower on a single call and ~1,050%
slower on ten thousand calls, never mind the fact that it won't work in a
non-Excel environment.

If I was trying to parse a string, I might just do that.

Regards,
Nate Oliver
  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Logical String Evaluation

That's fine, but that isn't what you originally asked.

your code does

Evaluate("4=4")

But thanks for clearing it up.


--
Regards,
Tom Ogilvy


"VBA Dabbler" wrote in message
...
Certainly. Try this.

MonthNumber = 4
OperatorString = "="
CriteriaValue = 4
If Evaluate(MonthNumber & OperatorString & CriteriaValue) Then
Msgbox "It Works!"
End If

"Tom Ogilvy" wrote:

How about showing us what works.

--
Regards,
Tom Ogilvy

"VBA Dabbler" wrote in message
...
Thanks for pointing me back to the evaluate method - I had tried it
unsuccessfully and started looking elsewhere.

I did get it to work.

Thanks,
VBA Dabbler

"Mark Bigelow" wrote:

Try:

Application.Evaluate("Month=4")

Mark

VBA Dabbler wrote:
Does anyone know how to evaluate a logical string in VBA? An

example
of one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler









  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Logical String Evaluation

BTW, not a good idea to use Month as a variable name as that takes out the
VBA Month function.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"VBA Dabbler" wrote in message
...
Does anyone know how to evaluate a logical string in VBA? An example of

one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler



  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Logical String Evaluation

Agreed.

"Bob Phillips" wrote:

BTW, not a good idea to use Month as a variable name as that takes out the
VBA Month function.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"VBA Dabbler" wrote in message
...
Does anyone know how to evaluate a logical string in VBA? An example of

one
is:

"Month=4"

If the variable 'Month' is 4, then the string would be true.

Thanks,
VBA Dabbler




  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Logical String Evaluation

Option Explicit

Sub a()
Dim m As String

m = "1+2=3"
Debug.Print Evaluate(m)
m = "1+2=4"
Debug.Print Evaluate(m)

End Sub

will result in (press CTRL + g)
True
False

Avoid VBA keywords as variable names... (I took m, not
Month :-)

HTH,
Bernd
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula evaluation Edward New Users to Excel 2 March 31st 09 01:31 PM
Excel interprets Text String as value in logical Argument JonesyE360 New Users to Excel 3 January 14th 09 04:02 AM
Multiple Logical Conditions With Date and String Comparison Not wo Anurag Excel Worksheet Functions 3 November 1st 07 06:48 PM
logical test and concatenate(string) dpayne Excel Discussion (Misc queries) 7 April 5th 07 08:30 PM
Evaluation Sheet perplexed Excel Worksheet Functions 2 March 10th 06 10:51 PM


All times are GMT +1. The time now is 08:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"