473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

InvalidCastException "Cast from string "6<5" to type 'Boolean is not valid.

I get an InvalidCastException "Cast from string "6<5" to type 'Boolean is
not valid.

for

If (CInt(objBuyInfo.Budget) & " " & arrRuleList(i).operator & " "
& CInt(arrRuleList(i).LeadMemberValue)) Then

where arrRuleList(i).operator = ">"

and CInt(objBuyInfo.Budget) = 6

and CInt(arrRuleList(i).LeadMemberValue) = 5

The quickwatch shows "6 < 5" {String} Object
How can I create a legitimate expression from this property values?

Thank you,
-hazz


Nov 21 '05 #1
3 1989
You can't. You need to evaluate a string as if it were code, and there is
no easy way to do that. You would need to either parse it out yourself, or
there are ways you can write, compile and execute code at runtime (slow and
not so pretty).

In your case, I am not sure why you are turning things into Integers, just
to then turn them back into a string during concatentation?

The easiest way to do this in your particular case would be to write a
function that took as parameters the values to compare, and the operator.
Then just have a case statement on the operator, and perform the appropriate
comparison with the operands. Return the result of the comparison.

Also, you should turn Option Strict On. That would prevent these errors at
compile time, rather then at runtime. You should always keep this option
turned on.

"hazz" <gr*********@nospamcomcast.net> wrote in message
news:e5****************@tk2msftngp13.phx.gbl...
I get an InvalidCastException "Cast from string "6<5" to type 'Boolean is
not valid.

for

If (CInt(objBuyInfo.Budget) & " " & arrRuleList(i).operator & " "
& CInt(arrRuleList(i).LeadMemberValue)) Then

where arrRuleList(i).operator = ">"

and CInt(objBuyInfo.Budget) = 6

and CInt(arrRuleList(i).LeadMemberValue) = 5

The quickwatch shows "6 < 5" {String} Object
How can I create a legitimate expression from this property values?

Thank you,
-hazz

Nov 21 '05 #2
Thank you for your quick reply Marina!
Thank you for the following suggestion which I was beginning to see as the
only solution.
The easiest way to do this in your particular case would be to write a
function that took as parameters the values to compare, and the operator.
Then just have a case statement on the operator, and perform the
appropriate comparison with the operands. Return the result of the
comparison.


And thank you for your other comments. Option Strict On is a fixture now.

Appreciatively,
-hazz
Nov 21 '05 #3
hazz schrieb:
I get an InvalidCastException "Cast from string "6<5" to type 'Boolean is
not valid.

for

If (CInt(objBuyInfo.Budget) & " " & arrRuleList(i).operator & " "
& CInt(arrRuleList(i).LeadMemberValue)) Then

where arrRuleList(i).operator = ">"

and CInt(objBuyInfo.Budget) = 6

and CInt(arrRuleList(i).LeadMemberValue) = 5

The quickwatch shows "6 < 5" {String} Object
How can I create a legitimate expression from this property values?

http://msdn.microsoft.com/library/en...elanguages.asp
Armin
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String...
7
by: Ensoul Chee | last post by:
I used #include <iostream.h> int m; cout << "Hexadecimal == 0x" << hex << m << endl; to print value of m in hexadecimal mode. But I got the compile error like this couttest.cpp:20 `hex'...
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
3
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
1
by: Kashish | last post by:
Is file<<"Some string"<<endl is an atomic operation. where file is an ofstream object. If we output a string in ofstream and we provide endl after that,Can we make sure the whole string will be...
4
by: Andy Leszczynski | last post by:
watch this: http://www.turbogears.org.nyud.net:8090/docs/wiki20/20MinuteWiki.mov or read this: http://www.turbogears.org.nyud.net:8090/docs/wiki2 0/page4.html should not it be: 2 def...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
1
by: mato81 | last post by:
Hi all! I am a newbie to WSDL. I have a questions which has been driving me crazy... If I would have a WSDL with a types element somewhat like below, what is the point of the third last row...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.