Convert String to Integer

Ask general questions here.
akshayru
Posts: 5
Joined: Thu Jan 18, 2018 10:23 pm

Convert String to Integer

Post by akshayru » Thu Jan 18, 2018 10:29 pm

I am trying to convert string to integer, so i can use arithmatical operator but somehow i am not able to do so. below is my code and few options i tried..

Code: Select all

string actualPrice = (repo.HKItemICSearch2010CIVICEngineIC.Row01.actprice.Text).ToString();
	string silverPrice = repo.HKItemICSearch2010CIVICEngineIC.ASJPanel.Silver.TextValue;
	int val=0;					
	if (!Int32.TryParse(actualPrice, out val)){																
    	   Report.Log(ReportLevel.Info," Actual Price="+actualPrice+ " sliver price="+silverPrice+" Parsed="+"Failed","Actual vs Silver",new RecordItemIndex(31));
	} else {
	  Report.Log(ReportLevel.Info," Actual Price="+actualPrice+ " sliver price="+silverPrice+" Parsed="+val,"Actual vs Silver",new RecordItemIndex(31));	
	}


// System.Number.StringToNumber(repo.HKItemICSearch2010CIVICEngineIC.Row01.actprice.Text);
if (Int64.Parse((repo.HKItemICSearch2010CIVICEngineIC.ASJPanel.Silver.TextValue).ToString()) > Int64.Parse((repo.HKItemICSearch2010CIVICEngineIC.Row01.actprice.Text).ToString())){
Report.Log(ReportLevel.Success, "Price Information:","Valid price information displayed."+repo.HKItemICSearch2010CIVICEngineIC.ASJPanel.Silver.TextValue,repo.HKItemICSearch2010CIVICEngineIC.WarrantyPanelInfo,new RecordItemIndex(23));
} else {
Report.Log(ReportLevel.Warn, "Price Information:","In-Valid price information displayed."+repo.HKItemICSearch2010CIVICEngineIC.ASJPanel.Silver.TextValue,repo.HKItemICSearch2010CIVICEngineIC.WarrantyPanelInfo,new RecordItemIndex(23));
}

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Convert String to Integer

Post by odklizec » Fri Jan 19, 2018 8:18 am

Hi,

And what exactly is your problem? You forgot to add an error message (if you got any) or description of the problem you are experiencing. Please add also Ranorex version and Snapshot (not screenshot!) of the element, from which you are trying to read the value. Thanks.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

McTurtle
Posts: 297
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Convert String to Integer

Post by McTurtle » Fri Jan 19, 2018 8:37 am

Hello akshayru,

What about using Convert.ToInt32(String)? Something like this:

int number=Convert.ToInt32("12345");

It's a .net method: Convert.ToInt32 Method (String)
If this is not what you were looking for, then I also don't understand your question and you must then follow up on the post of odklizec :)

Regards,
McTurtle

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Convert String to Integer

Post by odklizec » Fri Jan 19, 2018 8:45 am

I'm using Int32.TryParse in my projects and it works as expected, so my guess is that the problem is something else? Unfortunately, without more details, it's impossible to tell what's wrong.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

akshayru
Posts: 5
Joined: Thu Jan 18, 2018 10:23 pm

Re: Convert String to Integer

Post by akshayru » Fri Jan 19, 2018 5:50 pm

Sorry about the delay... My Probilem is i tried all Convert.Int32, Int32.Parse,Int.Parse,Int64.parese,Int32.TryParse but all of them are failing. While i can see value does exist. but when i am trying to convert it doesn't work and i get below exception...

Code: Select all

at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt) at System.Int64.Parse(String s) at PinnacleLogin.partSearch.Ranorex.Core.Testing.ITestModule.Run() in C:\Users\arudrak\Documents\Ranorex\RanorexStudio Projects\PinnacleLogin\PinnacleLogin\partSearch.cs:line 233 at Ranorex.Core.Testing.TestModuleLeaf.RunInternal(DataContext parentDataContext, Int32 iteration, Int32 iterationCount, Boolean skipIteration)

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Convert String to Integer

Post by odklizec » Mon Jan 22, 2018 8:46 am

Hi,

It looks like a problem with .net? What version of .Net (and Ranorex) are you using? Have you tried to reinstall it (both .Net and Ranorex)?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

akshayru
Posts: 5
Joined: Thu Jan 18, 2018 10:23 pm

Re: Convert String to Integer

Post by akshayru » Tue Jan 23, 2018 7:56 pm

I am using latest Ranorex version 8 with 4.6.1 .net version.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Convert String to Integer

Post by odklizec » Wed Jan 24, 2018 8:58 am

Hi,

I'm afraid, I don't have a clue what's wrong? I'm using Parse and TryParse in my tests quite frequently and it works as expected. So there must be something wrong with your system. I would suggest to reinstall .net, Ranorex and maybe also all Ranorex pre-requisities.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Convert String to Integer

Post by krstcs » Wed Jan 24, 2018 3:56 pm

Are you absolutely certain that the string is, in fact, a true representation of an integer? No decimal points, no commas, nothing but numerals?
Shortcuts usually aren't...