Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Hi,
I am trying to read a value from isolated storage and perform a function based on the value.

For example if the value is true I will then load some values. However all I get is Cannot implicitly convert type 'string' to 'float'

Here is the first part of my code:
C#
private void LayoutRoot_Loaded(object sender, System.Windows.RoutedEventArgs e)
       {
           {
               checkstate.Text +=
               IsolatedStorageSettings.ApplicationSettings["lost"] as string;
               float checks = float.Parse(checkstate.Text);
               if (checks = "true")
               {

                   number1.Text = rnd.Next(1, 10).ToString();
                   number2.Text = rnd.Next(1, 10).ToString();


and so on

Any help is much appreciated, I am just learning how to program so please forgive me for any completely stupid mistakes.
Posted
Comments
[no name] 17-Jul-12 14:25pm    
"checks = "true" ... is "true" a float? No it's a string. You cannot do that.
Sergey Alexandrovich Kryukov 17-Jul-12 16:44pm    
Besides, it probably meant "==". This is not spelling, just lack of understanding the very basics.
Voted 1.
--SA
[no name] 17-Jul-12 15:06pm    
Once you figure out the first error, the answer to your next question/error is: "=" is an assignment operator. What you want here is if (checks == true). The "==" (double equals) is a comparison operator.

1 solution

Data Types 101

A "STRING" is a sequence of characters commonly called "Text"
A "BOOLEAN" is a true or false value.
A "FLOAT" is a precision decimal number.

Here is an example of using each one.

C#
//STRINGS
string checkState = IsolatedStorageSettings.ApplicationSettings["lost"];
if(checkState == "true")
{
     //Do Stuff!
}

//BOOLEAN
bool checkState = false;
if(checkState == true)
{
     //Do Stuff!
}

//FLOATS
float checkState = 1.0002;
if(checkState > 1)
{
     //Do Stuff!
}
 
Share this answer
 
v2

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