0

Problem with switch

Problem with this code is that, whatever code I input it outputs whats under deafult: here is code https://code.sololearn.com/cen2tdmYYuQX/?ref=app

16th Dec 2018, 4:00 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
8 Réponses
+ 1
Code is local and never set. It can't get anything from your GUI without you physically making some assignment to it such as retriving the text box contents. Line 24 looks like an attempt to retrive the text box that is backwards. Changing it to the following might be what is needed: code = Edit1->Text;
16th Dec 2018, 6:55 PM
John Wells
John Wells - avatar
+ 1
Other minor point, having all those ifs, why bother with the switch. It is extra code to execute as you have already done the equivalent with those ifs.
16th Dec 2018, 6:50 PM
John Wells
John Wells - avatar
+ 1
John Wells Thanks, it works
16th Dec 2018, 7:04 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
0
code doesn't get initialized so it isn't likely to match any if statements so br stays uninitialized. I can't address fmx or the undefined variables likely from there as they don't exist in my environment. However, maybe line 24 is backwards.
16th Dec 2018, 4:45 PM
John Wells
John Wells - avatar
0
John Wells br I used because switch command needed integer values for it. and fmx is what program creates by itself so I don't do anything with it. I'm using RAD Studio XE8 if complier might be the problem (but 80% its not)
16th Dec 2018, 6:32 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
0
Yes, but that doesn't change the fact code is defined, but never given a value. I'm not sure where the value is expected to come from, but it hasn't.
16th Dec 2018, 6:38 PM
John Wells
John Wells - avatar
0
John Wells I don't know what are you trying to say, probablg because I'm still a newbie. After user inputs the code and press the button, application will open an website inside it. But the problem is somewhere in switch part I guess
16th Dec 2018, 6:48 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
0
John Wells did it to set br since switch needed integer. But I know I can solve the issue with using ifs but wanted to improve switch skills
16th Dec 2018, 6:54 PM
Edin Hajdarevic
Edin Hajdarevic - avatar