d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Visual Studio Message Box
Prev12
Add Reply New Topic New Poll
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Nov 1 2014 11:51pm
Quote (Chesse @ Nov 2 2014 12:51am)
It gives me this : "use of unassigned local variable" when i move it outside


Then initialize the variable.
Member
Posts: 6,175
Joined: Sep 4 2009
Gold: Locked
Trader: Scammer
Nov 1 2014 11:55pm
Quote (Minkomonster @ Nov 1 2014 09:51pm)
Then initialize the variable.


I believe I did ?

{
const decimal r = 0.05m;
decimal p = 1000;
int n = 1;
string myString;



for (n = 1; n <= 5; n++)
{
p = p * (1 + r);
myString = p.ToString("C") + "\n";

}

MessageBox.Show(myString, "Compound Interest", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 2 2014 12:02am
you declared it, not initialized it.
Member
Posts: 6,175
Joined: Sep 4 2009
Gold: Locked
Trader: Scammer
Nov 2 2014 12:07am
Quote (carteblanche @ Nov 1 2014 10:02pm)
you declared it, not initialized it.


string myString = "";

it only gives me the last iteration now
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 2 2014 12:10am
Quote (Chesse @ Nov 2 2014 02:07am)
string myString = "";

it only gives me the last iteration now


look very closely at your code. in particular, how are you assigning the string? use a debugger or log statement if you must.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Nov 2 2014 12:32am
Quote (carteblanche @ Nov 2 2014 02:10am)
look very closely at your code. in particular, how are you assigning the string? use a debugger or log statement if you must.


This.

Hint: Look inside your loop and take a close look at your assignment operator.

This post was edited by AbDuCt on Nov 2 2014 12:32am
Member
Posts: 6,175
Joined: Sep 4 2009
Gold: Locked
Trader: Scammer
Nov 2 2014 01:47pm
wow such a stupid mistake :l , sorry for all the trouble I caused you guys.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Nov 2 2014 03:12pm
Quote (Chesse @ Nov 2 2014 02:47pm)
wow such a stupid mistake :l , sorry for all the trouble I caused you guys.


Don't ever apologize for learning.
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll