Article View: borland.public.jbuilder.java.language
Article #15822Re: For-loops checking arrays ? Help
From: Aslak Poppe
Date: Wed, 21 Apr 1999 00:00
Date: Wed, 21 Apr 1999 00:00
157 lines
6442 bytes
6442 bytes
Thanks.
I did work out the problem eventually. You know sometimes a small typing error
(well maybe nor small) makes the difference.
In this case : for (j=1;i<=3;j++) should of course be for (j=1;j<=3;j++)
I went through this code maybe 30 times, and could not see why I got values
for the first group of three but not the rest of them. Its very easy som
etimes to get blind for the easiest parts of error checking.
The reason I can not do it the way you suggest is that I have to know wich
checkboxes are checked in sets of three. If two are checked I had to know
wether its 1 and 2, 1 and 3 or 2 and 3.
Richard Wilkman wrote:
> Aslak:
>
> Is this just a homework assignment to learn how to work with 2d
> arrays? Can you state the problem a little more directly?
>
> I may have missed something, but to me it looks like you have 36
> checkboxes whose values you want to store. Based on those "flag"
> values you want to make some changes to another 36 element array. I
> still don't see where the 2D array portion creeps in.
>
> So, let's make it smaller. You have an array of ones and zeros.
> String ones and zeros together and you get a number. The pattern of
> ones and zeros always comes out to only one number. Let's say you
> have 4 flags. The first one is one, the next two are off and the last
> one is on (1001). If you look at those as binary values you come up
> with 9. How about scanning your list of checkbox values, coming up
> with the decimal value and using that to determine.
>
> This may actually work for you as it appears you only care if a set of
> three is checked one way or another. A lot easier to work over things
> 3 bits at a time, too.
>
> Sorry for the "geek" solution. It's the best I could come up with.
>
> -Rich
>
> Aslak Poppe wrote:
> >
> > Good morning Newsgroup!
> >
> > I was wandering if any of you experienced programmers would be kind
> > enough to help me with the following problem.
> >
> > Im writing an aplet where i have 36 (series of 3 X 12 times) checkboxes
> > who are setting "flags" for my applet.
> > I have one two-dimentional array "Flag1" (byte Flag[ ][ ]=new
> > byte[12][3];) which is initiated with the byte value "0".
> >
> > The checkboxes are changing these values to 1 if the checkbox is
> > checked. So if checkbox no.9 is checked - Flag[2][2] is set to "1".
> > So far so good.
> > The next step i to manipulate these values in an new array called
> > "Flag2" (byte Flag2[ ][ ]=new byte[12][3];) to these values:
> >
> > According to the values in Flag 1, the values in Flag2 should change.
> > The point is to see if a serie of three checkboxes are checked with one,
> > two or three checkboxes, and which checkboxes are checked.
> > An example is the third serie -( Flag1[2][0]-Flag1[2][1]-Flag1[2][2]).
> >
> > If only one of the three checkboxes are checked, only the first value in
> > the serie in Flag2 should change.
> > If the first value in this serie is 1- the first value in the same serie
> > in Flag2 should be set to 1.
> > If the second value in this serie is 1- the first value in the same
> > serie in Flag2 should be set to 2.
> > If the third value in this serie is 1- the first value in the same serie
> > in Flag2 should be set to 3.
> >
> > If two of the checkboxes are checked the first 2 values in the same
> > serie in Flag2 should change.
> >
> > If the first and second value in this serie is 1- the first value in the
> > same serie in Flag2 should be set to 1 and the second value to 2.
> > If the first and second value in this serie is 1- the first value in the
> > same serie in Flag2 should be set to 1 and the second value to 2.
> > If the first and third value in this serie is 1- the first value in the
> > same serie in Flag2 should be set to 1 and the second value to 3.
> > If the second and third value in this serie is 1- the first value in the
> > same serie in Flag2 should be set to 2 and the second value to 3.
> >
> > If three of the checkboxes are checked, all values in the same serie in
> > Flag2 should change.
> > The first value should be set to 1, the second to 2 and the third to 3.
> >
> > That was the problem.
> > I tried to solve this using a nested for-loop like this:
> >
> > public void SetTheValuesInFlag2(){
> > byte i=0;
> > byte j=0;
> > byte iCount=0;
> > for (i=0;i<=11;i++)
> > {
> > iCount = 0;
> > for (j=1;i<=3;j++)
> > {
> > if (Flag1[i][j-1] == 1)
> > {
> > Flag2[i][iCount] = j;
> > iCount++;
> > }
> > }
> > }
> > }
> >
> > I then write the values to a string and print this string in a
> > TextField.
> > The only values that are changing are the first 3 and they are not
> > correct.
> > SetTheValuesInFlag2 is run every time a value in a checkbox is changed
> > and the values in Flag1 is set correct (I have another check for this).
> >
> > Can anyone please guide me to the right track here ???
> >
> > Best regards
> >
> > Aslak Poppe
> >
> > aslak.poppe@radsoft.no
> >
> > Internett: http://www.radsoft.no
>
> --
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Rich Wilkman
> Senior Quality Assurance Engineer
> Borland JBuilder Team
>
> If you see something that looks like an opinion up there,
> it's mine and mine alone.
>
> Mail sent to me from the newsgroups won't bounce but will
> be ignored. If I have time, I'll respond, but you have
> a better chance if you confine your posts to the newsgroups
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--
Med vennlig hilsen
RADsoft AS
Aslak Poppe
Adresse:
Kongens gt. 16
0153 Oslo
e-post: aslak.poppe@radsoft.no
Internett: http://www.radsoft.no
Tlf. 22 42 80 30
Fax. 22 42 80 20
Technical Details
Message-ID:
<371D8AFF.B54C4DD7@radsoft.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<371C2B96.8C9E78E9@radsoft.no> <371C9C54.C7A1D716@inprise.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,e327b780543d29b1 X-Google-Attributes: gidf74b3,public From: Aslak Poppe <aslak.poppe@radsoft.no> Subject: Re: For-loops checking arrays ? Help Date: 1999/04/21 Message-ID: <371D8AFF.B54C4DD7@radsoft.no> X-Deja-AN: 469056123 Content-Transfer-Encoding: 7bit References: <371C2B96.8C9E78E9@radsoft.no> <371C9C54.C7A1D716@inprise.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: RADsoft AS Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language