on 09-03-2010 1:02 AM
Dear SDN,
Pls help me in doing the code for the following scenario,
I have two dynamically populated drop downs with different sizes
now I want to loop through the firstdropdown and compare each value with the second drop down values,
if the first dropdown value does not exists in the second dropdown then it must return a message saying that the value does not exist in the second drop down..
I have tried using the followin code
for(int a =o;a<firstdropdown.size;a++){
string abc = firstdropdown.getelement(a).value
for(int b =o;a<seconddropdown.size;b++){
string xyz= seconddropdown.getelement(b).value
if(!abc .equals(xyz)
{
message abc is not found in the second dropdown
}
}
}
as it is a nested loop this code is returing some non relevant values
can some body pls help me in getting the correct code for comparing
Here i guess you are making some mistake...
if(!abc .equals(xyz)
{
message abc is not found in the second dropdown
}
Modify it as :
int found =0;
for(int a =o;a<firstdropdown.size;a++){
string abc = firstdropdown.getelement(a).value
for(int b =o;a<seconddropdown.size;b++){
string xyz= seconddropdown.getelement(b).value
if(abc.equals(xyz))
{
found = 1;
Break from outer loop;
}
}
}// end of outer loop;
if(found == 0)
{
// message string not found
}
Edited by: Saurabh Agarwal on Sep 3, 2010 5:39 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK...
just modify it little bit more :
Replace
}// end of outer loop;
if(found == 0)
{
// message string not found
}
with
if(found == 0)
{
// message string not found
}
}// end of outer loop;
AND
if(abc.equals(xyz))
{
found = 1;
Break from outer loop;
}
with
if(abc.equals(xyz))
{
found = 1;
Break from inner loop;
}
Edited by: Saurabh Agarwal on Sep 3, 2010 11:48 AM
Hi Saurabh,
here is my exact code
int found =0;
for(int c = 0; c<wdContext.nodefirst().size();c++){
String cNum = wdContext.nodefirst.getnodefirstAt(c).getId().toString();
for(int a=0; a<mV.getValuesCount(); a++){
String mId = mV.getValue(a).toString();
if(mId.equals(cNum)==true){
found =1;
Break ;
}
}else
msgMgr.reportSuccess("value"+cNum);
}
}
when I am printing I am getting the following vals instead of A3
value A2
value A3
value A3
value A3
value A3
value A4
value A4
value A5
value A5
value A5
I hope it is clear
Thanks
if(mId.equals(cNum)==true){
found =1;
Break ;
}
}else
msgMgr.reportSuccess("value"+cNum);
}// inner loop
}// outer loop
Remove else
AND
just put below condition between end peranthesis of loops.
if(mId.equals(cNum)==true){
found =1;
Break ;
}
}// inner loop
if(found==0)
{
msgMgr.reportSuccess("value"+cNum);
}
}// outer loop
Hi Saurabh,
if(found==0)
{
msgMgr.reportSuccess("value"+cNum);
}
no message returned.. I think found is not getting 0
if(mId.equals(cNum)==true){
found =1;
break;
}
this statement is exactly giving me the values which are equal. and it is not giving the ones which are not equal, as it is a nested loop it is getting too many values like this ..
value A2
value A3
value A3
value A3
value A3
value A4
value A4
value A5
value A5
value A5
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.