| View previous topic :: View next topic |
| Author |
Message |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Dec 15, 2008 1:45 pm Post subject: nvm |
|
|
ok so i decided to learn Visual C++, i made basic programs like show form , close , go to web page by press button etc.
here is what i want do to:
1.I Have textBox1 where i need to put number.
2.Click a Button then it will be divided by 3 then multiplicated by 2.
3.Result have to appear in textBox2.
here is what i did and when i click button , in textBox1 and textBox2 appear 0 -.-
| Code: | private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int labelv;
int liczba;
int a = 3;
int b = 2;
int foo = System::Int32::Parse(textBox1->Text);
textBox1->Text = Convert::ToString(liczba);
labelv = (double)liczba / a * b;
textBox2->Text = Convert::ToString(labelv);
} |
whats wrong? :S
Last edited by Wiw3K on Mon Dec 15, 2008 4:26 pm; edited 1 time in total |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Mon Dec 15, 2008 1:51 pm Post subject: |
|
|
maybe its this
change
int labelv;
int liczba;
for
double labelv;
double liczba;
? |
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Dec 15, 2008 1:54 pm Post subject: |
|
|
| gogodr wrote: | maybe its this
change
int labelv;
int liczba;
for
double labelv;
double liczba;
? |
still 0/0 at textBoxes  |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Mon Dec 15, 2008 1:59 pm Post subject: |
|
|
I dont get it much but should you add a
liczba = textBox1->Text
instead of
textBox1->Text = Convert::ToString(liczba);
---------------
its because
labelv & liczba
initial values is 0 and you are not changing that
0 / a * b
is 0
Last edited by gogodr on Mon Dec 15, 2008 2:04 pm; edited 1 time in total |
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Dec 15, 2008 2:04 pm Post subject: |
|
|
| gogodr wrote: | I dont get it much but should you add a
liczba = textBox1->Text
instead of
textBox1->Text = Convert::ToString(liczba); |
nah, not working, tried change everything alot times and search in google like 2h xd nothing  |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Mon Dec 15, 2008 2:06 pm Post subject: |
|
|
edited previous post, the problem is that you are not declaring anything to your variables
their inital value is 0 when declaring them and you are just saying there to change te textbox 1 text to o and then change the texbox 2 text to 0 / a * b wich is 0
try this one?
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX
TX = textBox1->Text
textBox2->Text == TX / 3 * 2;
} |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Mon Dec 15, 2008 2:22 pm Post subject: |
|
|
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int labelv;
int liczba;
int a = 3;
int b = 2;
int foo = System::Int32::Parse(textBox1->Text);
textBox1->Text = Convert::ToString(liczba);
labelv = (double)liczba / a * b;
textBox2->Text = Convert::ToString(labelv);
}
I'm somewhat surprised this wouldn't throw a warning... unless you just ignored it.
you never init labelv, or liczba to anything. Maybe .NET will handle it for you? I guess that would make sense as to why you don't get anything in your textboxes.
You try and convert liczba to a string, but nothing is there to begin with. There's your first 0. liczba still doesn't equal anything, so your math is meaningless. 0 / (3 * 2) = 0. There's your second 0. |
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Dec 15, 2008 2:41 pm Post subject: |
|
|
| gogodr wrote: | edited previous post, the problem is that you are not declaring anything to your variables
their inital value is 0 when declaring them and you are just saying there to change te textbox 1 text to o and then change the texbox 2 text to 0 / a * b wich is 0
try this one?
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX
TX = textBox1->Text
textBox2->Text == TX / 3 * 2;
} |
oh i see xd
you forgot few ;
now error appear about int -.-
| Code: | error C2440: '=' : cannot convert from 'System::String ^' to 'int'
error C2446: '==' : no conversion from 'int' to 'System::String ^'
error C2040: '==' : 'System::String ^' differs in levels of indirection from 'int' |
 |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Mon Dec 15, 2008 2:45 pm Post subject: |
|
|
| Wiw3K wrote: | | gogodr wrote: | edited previous post, the problem is that you are not declaring anything to your variables
their inital value is 0 when declaring them and you are just saying there to change te textbox 1 text to o and then change the texbox 2 text to 0 / a * b wich is 0
try this one?
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX
TX = textBox1->Text
textBox2->Text == TX / 3 * 2;
} |
oh i see xd
you forgot few ;
now error appear :O?
| Code: | error C2440: '=' : cannot convert from 'System::String ^' to 'int'
error C2446: '==' : no conversion from 'int' to 'System::String ^'
error C2040: '==' : 'System::String ^' differs in levels of indirection from 'int' |
 |
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = textBox1->Text;
textBox2->Text == Convert::ToString(TX / 3 * 2);
}
how about now ? |
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Dec 15, 2008 2:47 pm Post subject: |
|
|
| gogodr wrote: | private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = textBox1->Text;
textBox2->Text == Convert::ToString(TX / 3 * 2);
}
how about now ? |
| Code: | | error C2440: '=' : cannot convert from 'System::String ^' to 'int' |
only one  |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Mon Dec 15, 2008 2:53 pm Post subject: |
|
|
| Wiw3K wrote: | | gogodr wrote: | private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = textBox1->Text;
textBox2->Text == Convert::ToString(TX / 3 * 2);
}
how about now ? |
| Code: | | error C2440: '=' : cannot convert from 'System::String ^' to 'int' |
only one  |
oh , ok ok
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = textBox1->Text;
textBox2->Text = Convert::ToString(TX / 3 * 2);
}
this should do it |
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Dec 15, 2008 2:57 pm Post subject: |
|
|
| gogodr wrote: | | Wiw3K wrote: | | gogodr wrote: | private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = textBox1->Text;
textBox2->Text == Convert::ToString(TX / 3 * 2);
}
how about now ? |
| Code: | | error C2440: '=' : cannot convert from 'System::String ^' to 'int' |
only one  |
oh , ok ok
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = textBox1->Text;
textBox2->Text = Convert::ToString(TX / 3 * 2);
}
this should do it |
you just deleted one =
textBox2->Text == Convert::ToString(TX / 3 * 2);
xd , the error is in line:
TX = textBox1->Text;
(error C2440: '=' : cannot convert from 'System::String ^' to 'int') |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Mon Dec 15, 2008 3:01 pm Post subject: |
|
|
| Wiw3K wrote: | | gogodr wrote: | | Wiw3K wrote: | | gogodr wrote: | private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = textBox1->Text;
textBox2->Text == Convert::ToString(TX / 3 * 2);
}
how about now ? |
| Code: | | error C2440: '=' : cannot convert from 'System::String ^' to 'int' |
only one  |
oh , ok ok
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = textBox1->Text;
textBox2->Text = Convert::ToString(TX / 3 * 2);
}
this should do it |
you just deleted one =
textBox2->Text == Convert::ToString(TX / 3 * 2);
xd , the error is in line:
TX = textBox1->Text;
(error C2440: '=' : cannot convert from 'System::String ^' to 'int') |
since I don't have the error lines location I though the error was the secondary =
ok ok
make sure you include stdlib.h to your project
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = atof(textBox1->Text);
textBox2->Text = Convert::ToString(TX / 3 * 2);
} |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Mon Dec 15, 2008 3:02 pm Post subject: |
|
|
= is assignment.
== is comparison. |
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Dec 15, 2008 3:10 pm Post subject: |
|
|
| gogodr wrote: | since I don't have the error lines location I though the error was the secondary =
ok ok
make sure you include stdlib.h to your project
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int TX;
TX = atof(textBox1->Text);
textBox2->Text = Convert::ToString(TX / 3 * 2);
} |
ok so error appear:
error C2664: 'atof' : cannot convert parameter 1 from 'System::String ^' to 'const char *'
but i know i need to #include "stdlib.h" , after i include , still appear.
I Think i doesnt have that file so i downloaded it and put in project folder
and still error popup whats wrong  |
|
| Back to top |
|
 |
|