how to convert string to integer?

liunx

Guest
how to convert string to integer.
for example:
dim a as string = "11 + 2"
dim s as integer

s= convert.toInt32(a)

the code above cannot work, so have any code else that can convert the string data to integer.

thanks!!!This this:
s = CInt(a),
s = CInt(Val(a))
Advise: should not use variables with name s,
Try put each number in variable then use CInt functionthe code that you give is just to get the value of 11 from variable a, but if i want to get the whole value(11 + 2)=13, any suggestion to get this?

thanks!how to convert string to integer.
for example:
dim a as string = "11 + 2"
dim s as integer

s= convert.toInt32(a)


my code is done in c# hope u won't mind :)
(you will be calling the same .net library regardness the language)

string a = "11 + 2";
int s1 = Int32.Parse(a.substring(0,2)); <--get "11" xfer to int
int s2 = Int21.Parse(a.substring(5,1)); <--get "2" xfer to int (space count!)

int s = s1+s2;well my idea was to use each number in separate variables, or in sirpelidor exapmle, you can "+" to substring by, i guess it would be better, dont you think?!
Dim s1 as Integer = CInt(Trim(a.SubString(0, a.IndexOf("+"))))
Dim s2 as Integer = CInt(Trim(a.SubString(a.IndexOf("+"), a.Length)))what you write is correct but i have another problem on it...

i have a formula which is already saved in the database, "(BASIC / 26) + (OT * RATE)"
if the user key in the BASIC, OT, RATE value in the textbox, and click a button then the formula from the database is retrieved,
and the textbox value will be assign to the formula, which use to be calculated.

thanks!!!You must either write custom code for each formula or generate and compile c# code at runtime.what you write is correct but i have another problem on it...

i have a formula which is already saved in the database, "(BASIC / 26) + (OT * RATE)"
if the user key in the BASIC, OT, RATE value in the textbox, and click a button then the formula from the database is retrieved,
and the textbox value will be assign to the formula, which use to be calculated.

thanks!!!

Hi,

Did you find answer for your query? I have the same problem.

My problem is the formula also keeps changing with every record in the database, which makes it even worst.



Pls post me the answer if you have any.
 
Back
Top