monarchmk 24 Junior Poster in Training

Hi,

you did not read while post... I wrote

...You using switch..and while... when user enter that he like to VOTE you code goes to switch and enters case 2:... now in case 2 you ask for what team user likes to vote...
Here.. when user enters let say 2 for Barcelona.. you need to display
...

but i never tell you to delete this part of code :)
When you removed menu for voting, you remove input variable declaration and that's why you have number exception...

put this code back

String input = JOptionPane.showInputDialog(" Who will win the Champions League in 2010/11? "
                                                                  + "\n 1. Real Madrid"
                                                                  + "\n 2. Barcelona"
                                                                  + "\n 3. Chelsea"
                                                                  + "\n 4. Manchester United");

between line 49 and 50
and you are done program works...
For ++score you are ok, it is increment value of score than display new value, score++ is display score than increment value
But for case 3 no...
Now please remove case 3 (line 58-60) it will never execute because you intercept user answer for quit (3) in line 34 and quit program before it enters switch loop.

Like an extra for this code you can replace message in case 1: (lines 42-45) with this code

String messg="";
                   for (int a=1;a<game.length;a++)
                	   messg +=" Current Score for " + game[a] + " is: " + score[a] + " \n";
            	   JOptionPane.showMessageDialog(null,messg);

If you later add new team(s) you …

inni2626 commented: Excellent step by step guidance +1
monarchmk 24 Junior Poster in Training

Ok... you are almost done :)
You are missing this code.. I rearanged a little and add new array...

String game [] = new String [5];                
               int score[] = new int [5];
               game [1] = "Real Madrid ";
               score [1] = 250;
               
	       game [2] = "Barcelona ";
	       score [2] = 320;
               
               game [3] = "Chelsea ";
               score [3] = 140;
               
	       game [4]= "Manchester United ";
	       score [4]= 300;

This should be in your code... before while...
I aligned array numbers with vote question in line 36-40 (You asked 1 for Real 2 for Barcelona so i changed array game to be same as your question game[1]=Real, [2]=Barcelona...). Learn that code is yours... It is, maybe, "rule" that array starts from 0 but if you need array to start from other number... use it from that number, do not use arrays before it,that is not a mistake.

And also delete lines 53-65.. IF is not needed here. When you exit switch you are returned to while... code out of switch here is meaningless because in SWITCH we determine user actions and act upon them. Out of switch (in this code) we do not need anything, there is question what user like to do and that is all we need out of switch.

You using switch..and while... when user enter that he like to VOTE you code goes to switch and enters case 2:... now in case 2 you ask for what team user likes to vote...

monarchmk 24 Junior Poster in Training

hmmm...

Did not read whole post...

move this code

choice=Integer.parseInt(JOptionPane.showInputDialog("1. Display the current score for each possible response \n"
                                                               +"2. Vote \n " 
             	                                               +"3. Quit the program "));

below game[][] array definition... Array should e defined before anything..

how i'll give you an example what i think to do

i'll use WHILE condition... and SWITCH... just to make sample how this command can be used and implement in your code
I commented whole code.. copy code and try to execute it , and after that try to implement WHILE and SWITCH to your code (SWITCH will replace those IF... chains)

import java.io.*;
import javax.swing.*;  
public class monarch {

	public static void main(String[] args) throws Exception
	{
		while (true) // real syntax is WHILE (condition)... i'll put true for infinite loop// I'll control it via break; command later in code
			// with break; you tell Java to exit from loops (applies to FOR also)
		{
			int question=Integer.parseInt(JOptionPane.showInputDialog("Please enter your choice: \n " +
					"1. something...\n " +
					"2. somthing else.... \n " +
					"3. something else too... \n " +
					"4. QUIT"));
// Here i declare question as integer so later i would not have to convert string value to integers for comapartion.
			//First we will check if user need program termination...
			if (question==4) 
				{
				JOptionPane.showMessageDialog(null,"You choose to quit... bye..."); //Inform user that we quit and...
				break; //end of program... with break you terminate while true condition and exit the loop
				}
			
			//If not …
monarchmk 24 Junior Poster in Training

I'll try to make you a plan how code in this class should be positioned...

1. Variable definition. All variables should be here (more or less, not strict rule)
2. Fill arrays with start values. (array should be prepared for later use. For start maybe it will be easier if you use 1 array for names and 1 for scores.. like String game[] for names and int score[] for votes and fill it parallel.)
3. Define User Action (Ask user what to do and do some action according to user choice)
. 3a. Display score
. 3b. Vote
. 3c. Quit

IF 3a is selected do...
. print all arrays with current values... FOR cycle...
IF 3b is selected do...
. Display all names to user ( array[X][0]) ... FOR cycle
. Ask user for vote ...showinputdialog
. Increment vote for team
. Return to menu "user actions" (3)
IF 3c quit code

Here is your code in clean version. I won't write code for you, but I'll be here to help you all the way with your code
First try to reposition your code by above plan... or you can redefine plan if you like, but reposition you code by final plan.
It does not matter if its not working from start... we'll have to add some more function to code to work...

import javax.swing.*;
import java.io.*;

public class ChampionLeague { …
monarchmk 24 Junior Poster in Training

Hi, inni2662

I remove you comments from your first post and added mine. I do not understand.. your 1st post and your 2nd post are not same code... i start to change 1st post...
However there is something that i could not understand... there is point in your code where you start doing different tasks... like starting part when you ask user for action, and then suddenly you declare game array with length of USER DEFINED ACTION??? (User choose to quit and you declare array for voting??) and than you fill strings with names from array that depends on chosen user action. I corrected parts of your code just to have some starting point.
Now your code can be started, but it still contains huge errors. Also arrays could not be filled with this kind of code, as if user choose 1 than array game will be declared as game[1][2] and will fail in line with Chelsea with ArrayOutOfBoundsException because in code game is defined for only 2x2 fields.

Now from you i need info what this code should do... like this code seams little chaotic...

import javax.swing.*;
import java.io.*;

public class ChampionLeague {
    public  static void main(String[] args) //Java main class starts always with this procedure. This line is starting point of Java class.
{ 
        int choice;
        int Quit = 0; //It's better from start to adopt Java rules for variable names, or if you really need adopt your own rules but keep …
monarchmk 24 Junior Poster in Training

You basically try to find if any of error list are equal or not equal to 0
Then put some sumerr integer and get sum of all errorLists...

int errsum=0;
for (int j=0;j<errorList.length;j++)
     errsum+=errorList[J]; // i'll make sum of all  errorList.If some of ErrLists are != 0 then sum is != 0

//Now check if sum is or not is equal to 0

  if (errsum ==0)
  {
    break; //you want to break if all are equal to 0you code if equal
  }
  else
  {
    //Your code if not equal
    for(int i=0; i<row; i++)
    {
        initialWeight[i] = newWeight[i];
    }
  }
monarchmk 24 Junior Poster in Training

Dear Sir,

Thanks for replying sir, "LstName" is the name of pop up menu. In my previous thread also some respected member suggested to use label. But my requirement is not that actually. I think i will not get the appropriate answer here. Any way, thank you once again sir.

giving up so easy?...

What about TextBox? If you do not like Label, use TextBox. If you make it property Flat(appearance=0) and BorderStyle=0 (none) it will look same as PopUp. Even with standar settings looks almost same as PopUp. Down you can find same code for textbox control with your measurements for position same as PopUp. Even you can select text or parts of text inside.

And if must be PopUp, there must be some specific reason. Let us hear it, maybe if this could not be solved with popup, We can try find similar control for you!

Private Sub List1_KeyUp(KeyCode As Integer, Shift As Integer)
    If Len(List1.Text) > 1 Then
        Text1.Text = List1.Text
        Text1.Width = Len(List1.Text) * 200
        Text1.Height = 400
        Text1.Left = List1.Left + List1.Width / 2
        Text1.Top = List1.Top + List1.Height / 2
        Text1.Visible = True
    Else
        Text1.Visible = False
    End If
End Sub
AndreRet commented: Nice suggestion. +7
P.manidas commented: I will use it sir +3
monarchmk 24 Junior Poster in Training

easy :)

replace line 18 (Line Input #1, LineA)
with this code

While Not EOF(1)
              Line Input #1, LineA 'Since all dates are same i will read only 1st row
        Wend

it will loop until it is end of File (EOF) 1 in parenthesis is index number of file that you opened in line 17.

And please mark thread SOLVED if everything is OK.

monarchmk 24 Junior Poster in Training

If my list box item is too long, and that is not visible in my list box because of list box width.

Then, you want to put all invisible (items out of bounds of list box) items in popup menu?

If this is point, why not put columns in list box?

Also how big will be popup window?
popup and List-box sizes are almost same size, so i do not thing that you will gain space using popup and not enlargeing listbox. Except on small forms.

debasisdas commented: Very good point. +7
monarchmk 24 Junior Poster in Training

When you put Maximum iterations to 1 that means with every cell change there will be only one level of recalculation in worksheets. Your cell B2, with every cell change or manual recalculate with F9, will receive A2 value + B2 value. You will not need to change cell values, simple double click and move focus to another cell or F2 and Enter combination, on any cell, will initiate recalculation which will add another A2 value in B2 cell. That why with any change anywhere in sheet your value in B2 changed. Any change in worksheet, triggers Excel to recalculate whole worksheet and that main reason why value in B2 changes whole time. If you put eq. 100 iterations, B2 cell will get 100times A2 cell + B2 cell. This is NOT correct way of calculating cell. If you made circular reference in any other cell in worksheet you will get same "phenomenon". You will probably need VBA to achieve you original idea.
You can test your problem with this...
If you put cell like this
B2: =A2+B2, C2: =B2+C2, D2: =C2+D2 (all three with circular references) and you put iterations to 1... and put 1 on cell A2 with each recalculation (press F9) will get these values
A B C D
1 1 1 1
1 2 3 4
1 3 6 10
1 4 10 20
1 5 15 35
1 6 21 56

it will be …

AndreRet commented: Well executed. +6