Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
We have a winapp that works 100% on windows 7/8 and all the previous servers except server 2012.

The code that works on Win7 and not server2012:
VB
If aFld.Extract(11).StringValue < 0 Then
           lblAvailCrW.ForeColor = Color.Red
           lblAvailCrT.ForeColor = Color.Red
       End If


Things I've tried to convert the aFld.Extract(11).StringValue so that it can be compared to 0 to see if smaller:
ivalue each time has the appropriate type.
VB
Double.TryParse(aFld.Extract(11).StringValue, iValue)
        CDbl(aFld.Extract(11).StringValue)
        Decimal.TryParse(aFld.Extract(11).StringValue, iValue)
        Convert.ToDouble(aFld.Extract(11).StringValue)
        Convert.ToDecimal(aFld.Extract(11).StringValue)


aFld.Extract(11).StringValue returns "182.25" as a string.

If I enter the screen it gives an incorrect format error on the conversion.
I have tried every type of casting and converting and parsing to decimal and double I could think of, but still keep getting the same error and it's just on Server 2012( not the core version)

Any help please and thanx
Posted
Updated 17-Dec-14 2:21am
v2
Comments
Shweta N Mishra 17-Dec-14 7:02am    
whic line do you get error, where is your cast code applied ?
Asgard25 17-Dec-14 7:04am    
double.tryparse(svalue,ivalue), was one of the ways I tried
on any line that does the converting it gives the error.
Tomas Takac 17-Dec-14 7:23am    
I'm confused. You say the problem is with database but I don't see any code accessing DB in your post. Show the code where exception is thrown.
Asgard25 17-Dec-14 7:48am    
No not SQL server just windows server 2012, it has nothing to do with the DB.
Tomas Takac 17-Dec-14 7:51am    
I see, thanks for explanation.

VB
dim svalue as string = "182.82"
        'Do conversions here
        if System.Convert.ToDecimal(svalue) < 0 then
        ' change grid colours
        end if
 
Share this answer
 
Comments
Asgard25 17-Dec-14 7:23am    
Nope still get "input string was not in a correct format" error.
This is C# but it works.
C#
double dvalue;
string svalue = "182.82";
bool br = Double.TryParse(svalue, out dvalue);

Why not show the exact code you are using.
 
Share this answer
 
Comments
Asgard25 17-Dec-14 7:36am    
This is the exact code that works on win7 and server2008

If aFld.Extract(11).StringValue < 0 Then
lblAvailCrW.ForeColor = Color.Red
lblAvailCrT.ForeColor = Color.Red
End If
Richard MacCutchan 17-Dec-14 7:43am    
So where is the conversion from string to Double?
Asgard25 17-Dec-14 7:52am    
Double.TryParse(aFld.Extract(11).StringValue, iValue)
CDbl(aFld.Extract(11).StringValue)
Decimal.TryParse(aFld.Extract(11).StringValue, iValue)
Convert.ToDouble(aFld.Extract(11).StringValue)
Convert.ToDecimal(aFld.Extract(11).StringValue)

Those are some of the ways I tried, none of them works.
Richard MacCutchan 17-Dec-14 7:58am    
What is returned from aFld.Extract(11).StringValue?

Please edit your question, and show the exact code that you are using, and full details of the error or exception. Make sure you include the details of any parameter values.
Asgard25 17-Dec-14 8:22am    
Updated question.
aFld.Extract(11).StringValue returns a string value, in this case something like "182.82"
I think the regional settings are different on your server. You need to parse the number unsing specific culture:
VB
Dim number As Double
number = Double.Parse(
  aFld.Extract(11).StringValue, 
  System.Globalization.NumberStyles.Number, 
  System.Globalization.CultureInfo.InvariantCulture)

If number < 0 Then
...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900