For loop- seems to be just going to last value

Hi guys, carrying on from the thread I created yesterday I have managed to get the socket working between my server and my client, but I am having an issue when re-constructing a string that is being sent from the client to the server. I am talking about the for loop in line 151, which seems to just going straight to the last value of the for loop and thus the board isn't being reconstructed properly.
I'm including both the server and client code which just needs to compiled (host is set to localhost on port 4500) and you will see what I mean after inputting a move from the client. Can anyone spot the problem?
Server code
import java.io.*;
import java.net.*;
import javax.swing.JOptionPane;
class Server
     public static void main (String []args) throws IOException
          try
               Server();     
          catch (IOException ex)
     public static void Server () throws IOException
          ServerSocket serverSocket=null;
          int portNo=4500;
          System.out.println("Starting");
          try
               serverSocket=new ServerSocket(portNo);     
          catch (IOException ex)
               System.err.println("Could not create socket on port" +portNo);
               System.exit(1);
          System.out.println("Socket listening");
          Socket clientSocket=null;
          try
               clientSocket=serverSocket.accept();
          catch (IOException ex)
               System.out.println("Accept failed");
               System.exit(1);
          PrintWriter out= new PrintWriter(clientSocket.getOutputStream(), true);
          BufferedReader in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
          //coordinates
          String coordinates[] [] = new String [8] [8];
          for (int i=0;i<8;i++)
               for (int j=0;j<8;j++)
                    if ((i%2!=0)&&(j%2!=0))
                         coordinates[i] [j]="#";
                    else if ((i%2!=0)&&(j%2==0))
                         coordinates[i] [j]=" ";
                    else if ((i%2==0)&&(j%2!=0))
                         coordinates[i] [j]=" ";
                    else
                         coordinates[i] [j]="#";
          coordinates[0][0]="R";
          coordinates[0][1]="N";
          coordinates[0][2]="B";
          coordinates[0][3]="Q";
          coordinates[0][4]="K";
          coordinates[0][5]="B";
          coordinates[0][6]="N";
          coordinates[0][7]="R";
          for (int i=0;i<8;i++)
               coordinates[1]="P";
          coordinates[7][0]="r";
          coordinates[7][1]="n";
          coordinates[7][2]="b";
          coordinates[7][3]="q";
          coordinates[7][4]="k";
          coordinates[7][5]="b";
          coordinates[7][6]="n";
          coordinates[7][7]="r";
          for (int i=0;i<8;i++)
               coordinates[6][i]="p";
          Board board1=new Board(coordinates);
          boolean gameStart=true;
          String coord="";
          String originX="";
          String originY="";
          String destinationX="";
          String destinationY;
          while (gameStart)
               System.out.println("trying to read from client");
               String input="";
               try
                    input=in.readLine();     
                    System.out.println(input);
               catch (IOException ex)
                    System.out.println("Read failed");
                    System.exit(1);
               originX=input.substring(65);
               originY=input.substring(66);     
               destinationX=input.substring(67);
               destinationY=input.substring(68);
               coord=input.substring(0,64);
               System.out.println(coord);
               for (int p=0;p<64;p++)
                    System.out.println(p);
                    for (int i=0;i<8;i++)
                         for (int j=0;j<8;j++)
                              coordinates [i] [j]=coord.substring(p);
                              if (i==(Integer.parseInt(originX))&&(j==(Integer.parseInt(originY))))
                                   String piece="";
                                   piece=coordinates [i] [j];
                                   if ((i%2!=0)&&(j%2!=0))
                                        coordinates[i] [j]="#";
                                   else if ((i%2!=0)&&(j%2==0))
                                        coordinates[i] [j]=" ";
                                   else if ((i%2==0)&&(j%2!=0))
                                        coordinates[i] [j]=" ";
                                   else
                                        coordinates[i] [j]="#";
                                   for (int s=0;s<8;s++)
                                        for (int t=0;t<8;t++)
                                             if (s==(Integer.parseInt(destinationX))&&(t==(Integer.parseInt(destinationY))))
                                                  coordinates [s] [t]=piece;
               board1.printBoard(coordinates);
          out.close();
          in.close();     
          clientSocket.close();
          serverSocket.close();          
class Board
     boolean gameStart=true;
     public Board()
     public Board(String [] [] coordinates)
          printBoard(coordinates);
     String [] [] getCoOrdinates(String [] [] coordinates)
          return coordinates;
     public static void update (String coordinates [] [])
          printBoard(coordinates);
     public static void printBoard(String coordinates[] [])
          for (int i=0;i<8;i++)
               for (int j=0;j<8;j++)
                    System.out.print(coordinates[i][j]);
               System.out.println();
}Client code:import java.io.*;
import java.net.*;
import javax.swing.JOptionPane;
class Client
     public static void main (String [] args) throws IOException
          Socket socket=null;
          PrintWriter out=null;
          BufferedReader in=null;
          String serverLocation="localhost";
          int portNo=4500;
          System.out.println("Starting");
          try
               socket= new Socket (serverLocation,portNo);
               out= new PrintWriter(socket.getOutputStream(),true);
               in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
          catch (UnknownHostException ex)
               System.out.println("Cannot find" + serverLocation);
               System.exit(1);     
          catch (IOException ex1)
               System.out.println("IO problem");
               System.exit(1);
          System.out.println("Connected");
          //coordinates
          String coordinates[] [] = new String [8] [8];
          for (int i=0;i<8;i++)
               for (int j=0;j<8;j++)
                    if ((i%2!=0)&&(j%2!=0))
                         coordinates[i] [j]="#";
                    else if ((i%2!=0)&&(j%2==0))
                         coordinates[i] [j]=" ";
                    else if ((i%2==0)&&(j%2!=0))
                         coordinates[i] [j]=" ";
                    else
                         coordinates[i] [j]="#";
          coordinates[0][0]="R";
          coordinates[0][1]="N";
          coordinates[0][2]="B";
          coordinates[0][3]="Q";
          coordinates[0][4]="K";
          coordinates[0][5]="B";
          coordinates[0][6]="N";
          coordinates[0][7]="R";
          for (int i=0;i<8;i++)
               coordinates[1][i]="P";
          coordinates[7][0]="r";
          coordinates[7][1]="n";
          coordinates[7][2]="b";
          coordinates[7][3]="q";
          coordinates[7][4]="k";
          coordinates[7][5]="b";
          coordinates[7][6]="n";
          coordinates[7][7]="r";
          for (int i=0;i<8;i++)
               coordinates[6][i]="p";
          Board board1=new Board(coordinates);
          boolean gameStart=true;
          String coord="";
          while (gameStart)
               String originMove=JOptionPane.showInputDialog(null,"Client Origin Move","Enter in origin of piece",JOptionPane.QUESTION_MESSAGE);
               String destinationMove=JOptionPane.showInputDialog(null,"Client Destination Move","Enter in destination of piece",JOptionPane.QUESTION_MESSAGE);
               for (int i=0;i<8;i++)
                    for (int j=0;j<8;j++)
                         coord=coord+coordinates[i][j];
               System.out.println(coord);
               out.println(coord+originMove+destinationMove);
               System.out.println("passed");
          out.close();
          in.close();
          socket.close();
class Board
     boolean gameStart=true;
     public Board()
     public Board(String [] [] coordinates)
          printBoard(coordinates);
     String [] [] getCoOrdinates(String [] [] coordinates)
          return coordinates;
     public static void update (String coordinates [] [])
          printBoard(coordinates);
     public static void printBoard(String coordinates[] [])
          for (int i=0;i<8;i++)
               for (int j=0;j<8;j++)
                    System.out.print(coordinates[i][j]);
               System.out.println();
}Cheers,
Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

jverd wrote:
p595659 wrote:
1) I don't think that even compiles. Since you're catching IOException, your throws clause is bogus--that method can never throw IOE.I have removed the try and catch statements in the main method. I cannot, however get rid of the throws IOException in the main method other my program won't compile.Right. Don't catch it, since you're not handling it. Just declare that it throws it.
Indeed, this is what I have done :)
>
3) Don't name methods the same as your class name.See answer to 4.
4) Start method names with lowercase letters.
try
serverSocket=new ServerSocket(portNo);     
catch (IOException ex)
System.err.println("Could not create socket on port" +portNo);
System.exit(1);
ServerSocket is a part of the java.net package. I am just creating an instance of it. http://java.sun.com/j2se/1.4.2/docs/api/java/net/ServerSocket.html
I don't know what you're talking about. You had a class named Server and a method named Server. That's confusing.Changed- I didn't spot it, so I have named it startServer now.
>
5) There's almost no point to ever calling System.exit. Here, again, since you're not
actually handling the exception, don't bother catcing it.Sorry, but this was how I was taught when I started java. My understanding is that System.exit properly terminated applications so this freed up memory so it's abit of a habit of mine, is this wrong to do in this instance?Calling it in response to an exception is wrong. It's not that method's job to decide to shut down the VM. Just let the exception bubble up (or else handle it properly). You do not need to call System.exit to free up memory. It's freed up automatically when the VM exits. The OS takes care of that, without any help from you.Removed- thanks for clearing that up for me :)
JacobsB wrote:
line 151 of the server code or client code?Line 151 of my server code. My client is working fine up to this step of the programming I have done- it's just the server part I'm having issues with. You can compile and run the client fine- you can compile the server but as explained in the original post, I'm having a logical error when redrawing the board when it gets the 68 charecter string from the client (first 64 charecters are for the board, then the original position (x and y respectively), followed up the new position (x and y respectively again).
I'm including an updated version of the code, after all the comments above so we have an updated version for trying to solve the problem I'm having. The client code does not need to be updated as it has not changed yet, so you can use the code in the original post.
import java.io.*;
import java.net.*;
import javax.swing.JOptionPane;
class Server
     public static void main (String []args) throws IOException
          startServer();     
     public static void startServer () throws IOException
          ServerSocket serverSocket=null;
          int portNo=4500;
          System.out.println("Starting");
          try
               serverSocket=new ServerSocket(portNo);     
          catch (IOException ex)
               System.err.println("Could not create socket on port" +portNo);
               ex.printStackTrace();
          System.out.println("Socket listening");
          Socket clientSocket=null;
          try
               clientSocket=serverSocket.accept();
          catch (IOException ex)
               System.out.println("Accept failed");
               ex.printStackTrace();
          PrintWriter out= new PrintWriter(clientSocket.getOutputStream(), true);
          BufferedReader in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
          //coordinates
          String coordinates[] [] = new String [8] [8];
          for (int i=0;i<8;i++)
               for (int j=0;j<8;j++)
                    if ((i%2!=0)&&(j%2!=0))
                         coordinates[i] [j]="#";
                    else if ((i%2!=0)&&(j%2==0))
                         coordinates[i] [j]=" ";
                    else if ((i%2==0)&&(j%2!=0))
                         coordinates[i] [j]=" ";
                    else
                         coordinates[i] [j]="#";
          coordinates[0][0]="R";
          coordinates[0][1]="N";
          coordinates[0][2]="B";
          coordinates[0][3]="Q";
          coordinates[0][4]="K";
          coordinates[0][5]="B";
          coordinates[0][6]="N";
          coordinates[0][7]="R";
          for (int i=0;i<8;i++)
               coordinates[1]="P";
          coordinates[7][0]="r";
          coordinates[7][1]="n";
          coordinates[7][2]="b";
          coordinates[7][3]="q";
          coordinates[7][4]="k";
          coordinates[7][5]="b";
          coordinates[7][6]="n";
          coordinates[7][7]="r";
          for (int i=0;i<8;i++)
               coordinates[6][i]="p";
          Board board1=new Board(coordinates);
          boolean gameStart=true;
          String coord="";
          String originX="";
          String originY="";
          String destinationX="";
          String destinationY;
          while (gameStart)
               System.out.println("trying to read from client");
               String input="";
               try
                    input=in.readLine();     
                    System.out.println(input);
               catch (IOException ex)
                    System.out.println("Read failed");
                    ex.printStackTrace();
               coord=input.substring(0,64);                    
               originX=input.substring(64,65);
               originY=input.substring(65,66);     
               destinationX=input.substring(66,67);
               destinationY=input.substring(67,68);
               System.out.println(coord);
               for (int p=0;p<64;p++)
                    System.out.println(p);
                    for (int i=0;i<8;i++)
                         for (int j=0;j<8;j++)
                              coordinates [i] [j]=coord.substring(p);
                              if (i==Integer.parseInt(originX)&&(j==(Integer.parseInt(originY))))
                                   String piece="";
                                   piece=coordinates [i] [j];
                                   if ((i%2!=0)&&(j%2!=0))
                                        coordinates[i] [j]="#";
                                   else if ((i%2!=0)&&(j%2==0))
                                        coordinates[i] [j]=" ";
                                   else if ((i%2==0)&&(j%2!=0))
                                        coordinates[i] [j]=" ";
                                   else
                                        coordinates[i] [j]="#";
                                   for (int s=0;s<8;s++)
                                        for (int t=0;t<8;t++)
                                             if (s==(Integer.parseInt(destinationX))&&(t==(Integer.parseInt(destinationY))))
                                                  coordinates [s] [t]=piece;
               board1.printBoard(coordinates);
          out.close();
          in.close();     
          clientSocket.close();
          serverSocket.close();          
class Board
     boolean gameStart=true;
     public Board()
     public Board(String [] [] coordinates)
          printBoard(coordinates);
     String [] [] getCoOrdinates(String [] [] coordinates)
          return coordinates;
     public static void update (String coordinates [] [])
          printBoard(coordinates);
     public static void printBoard(String coordinates[] [])
          for (int i=0;i<8;i++)
               for (int j=0;j<8;j++)
                    System.out.print(coordinates[i][j]);          
               System.out.println();
}Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • On my iPod touch, (4th gen, iOS 6.1.5) it won't let me get into my purchase history. It says loading in the middle of the screen for like 3 seconds then just goes blank. What is the solution to this problem?

    It won't work because I really want to get flappy bird back!!

    Try:
    - Reset the iOS device. Nothing will be lost       
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Go to Settings>iTunes and App Store and sign out and sign back in
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                                
    iOS: How to back up                                                                                     
    - Restore to factory settings/new iOS device.             

  • How to pass the sequence number of current loop in a for loop in FPGA vi to the host

    PCI-7830R
    LV 8.2
    What I was trying to do is to use multiple DIO to generate pulse at different sequence. Mode one is to automatically sweep from DIO1 to DIO20; mode 2 is several DIOs generate pulse simoutaneously.  So I use a case structure to make the selection, in the mean time, I set up two for loop in each case so that I can use multiple pulse generations. For example, in scanning mode, if I set 2 exposures, it sweeps from 1 to 20 then do it again.  
    Then I need to get the loop sequence number, i of each scenario. So I put an indicator within the first loop, and create a local variable of it and put in the second one.  Running the FPGA vi alone, I can see the indicator change in each case from 0 to N-1, N being the for loop time.But in the host vi, I tried to add this indicator as an element in the read/write invoke method, in the debugging mode, I could only see it directly jump to N-1 without all the changes I saw in FPGA vi. 
    Is it possible to get this number passed correctly from FPGA vi to the host vi? Thanks

    Thanks for the reply Jared.
    Excuse me if it looks incorrect, but I'm new to FPGA programming, so I would have to look into the FIFO you referred to.  I used local variables because for one thing I have several different cases containing for loop in each of them, and I only want one indicator for the "i".  If I put the indicator out of any for loop, it's only gonna show the last number which is N-1.  For the other thing, it seems like property nodes are not allowed in FPGA vi.  And by doing this, I can see the i number changing from 0 to N-1 in each case, well, in FPGA vi's front panel.  But while I ran the host vi with everything, the indicator in host vi's front panel only showed the last number N-1. It may be the reason you said, it happened too fast before the indicator in host vi can catch it.
    What I want to realize is to group the data I collect in host vi, for example, when I choose multiple exposure in each mode, and the FPGA runs 1 through 20 then do it again, I want the data stored in two groups using the loop sequence number as the seperator in file name.  So it goes like 1-1, 2-1.......20-1; then 1-2, 2-2,.....20-2.

  • Ever since the last IOS update, my Iphone 5c has been acting weird. The time is always off; It says that its 9:30 in the morning when it's actually 2pm. I try to fix it, but it just goes back to not working. Please help!!

    I go to settings and switch "Automatic time" off and then back on. It works for a while, but then just goes back to being off. I've tried manually setting the time, but it just goes back to what it was before. If I send a text, it sends and then disapears. I can't see what I wrote! I went in to Apple to try and get it fixed, but they just restored my phone. It's still not working. Please help!

    It's not hacker or a virus. You are experiencing what a number of users of iOS 5 are experiencing now - sluggish or less than perfect iPad performance. It seems that for some of us - memory management has gotten a little out of whack with this most recent update. Some of the basic troubleshooting steps that you can try are ....
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    Close apps in the recents tray. Go to the home screen first by tapping the home button. Quit/close open apps by double tapping the home button and the task bar will appear with all of you recent/open apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner to close the apps. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    If you have Safari crashing issues - Go to Settings>Safari>Clear History, Cookies and Data. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    None of these steps should be necessary as part of your daily routine - the iOS is supposed to handle all of this without any user input. Once again - for some of us - the iOS is letting us down.
    Until Apple releases another update that resolves this issue for the "few" that suffer, keep these steps in mind and use them as needed.

  • Whenever I try to open a new tab, the tab just goes blank and says "New tab". I can't open any websites. What do I do?

    It started very suddenly. The tab just went blank when I tried to open a new one, and then just continued every time I open a new tab. It loads the selected website for a milisecond, and then just goes blank and says "New tab". In my own language of course. I tried reinstalling, rebooting and nothing seems to do it. I have Tab Mix Plus as a tab manager.
    What can I do? Please help.

    That did the trick. But I had to start Firefox in safe mode, because it just went to the blank page where the Troubleshooting page should have been, of course. Thanks for the help anyway. Now I just need to get my old addons back.

  • While loop and for loop condition terminal

    Hello friends,
    I am using labview 8.6. The condition terminal of the while loop and conditional for loop is behaving in just the opposite way.
    When i wire a true to the condition terminal of my loop, the while loop continues to run when I click on run. when I wire a FALSE, it stops.
    Is there any setting change that I have to make it to get it work properly.
    Please suggest on this.
    Thanks and regards,
    Herok

    Please do NOT attach .bmp images with the extension changed to .jpg to circumvent the forum filters!
    Herok wrote:
    I am sending you the VI. I am not sure if this would help you because only in 2 computers this behaviour is seen. In others, it works as it is supposed to work.
    Whatever you are seeing must be due to some corruption or folding error. It all works fine here.
    To make sure there are no hidden objects, simply press the cleanup button which would reveal any extra stuff (which is obviously not there). Does it fix itself if you click the termination terminal an even number of times? What if you remove the bad loop and create a new one?
    Could it be you have some problems with the graphics card and the icon of the conditional terminal does not update correctly?
    Whay happens if you connect a control instead of a diagram constant?
    What is different on the computers where it acts incorrectly (different CPU (brand, model), #of cores, etc.) 
    LabVIEW Champion . Do more with less code and in less time .

  • For loop wont loop through array built from spread sheet

    im probably doing sonthing really silly but........
    first i build and array out of data from a spreadsheet (RefLookup)
    the spreadsheet contains 3 rows the top row is my label (to be returned later)
    the second row it my maxmum value
    the third row is my minimum value.
    Ref in is my live feed of data to be looked up.
    i then put this into a for loop, to loop through the array untill it finds which range of data the Ref in lies.....
    then i simply stop the loop and output the index value.
    this index value is the used to look up the spreadsheet data again and return the label for that index.
    from what i can gather the code should.... work. but it doesnt seem to go passed the first itteration of the for loop 
    any ideas?
    please and thanks
    John
    Solved!
    Go to Solution.
    Attachments:
    jmRange.vi ‏13 KB
    RefLookup.csv ‏1 KB
    InRange.PNG ‏34 KB

    You need to set the delimiter to comma, else you don't get all data. (read from spreadsheet file)
    You are doing this way too complicated. Here's equivalent code. I am sure it can be simplified much more!  
    You don't need the outer while loop. finding it once is sufficient. 
    You probably want to add a "select" after the loop that selects NaN instead of the last value if nothing is found, based on the boolean. 
    Message Edited by altenbach on 03-30-2010 02:55 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    finder.png ‏8 KB

  • Help with Mathscipt and for loop

    I have a code in Mathscript/matlab and I need to output the array out. One option is my first code,the other option is using a for loop, but I am only getting the last ouput out. I need to get the whole output out.
    Any help.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Help with Mathscript_for loop.vi ‏115 KB
    Help with Mathscript_for loop2.vi ‏84 KB

    Here's how it should look like.
    Message Edited by altenbach on 10-30-2008 05:12 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    MathscriptInFOR.png ‏15 KB

  • Having trouble with inner for loop values in my procedure

    Hi ...
    I am using oracle 10g and here is my procedure ...
    create or replace procedure sales_information is
    v_qty number(10);
    rem_qty number(10):=0;
    cursor pck_quantity is
    select * from sales_info;
    cursor no_of_labels is
    select ceil(sum(nvl(total_quantity,actual_quantity))/400) from sales_info;
    begin
    for j in no_of_labels
    loop
    for i in pck_quantity
    loop
    select nvl(i.total_quantity,i.actual_quantity) into v_qty from sales_info;
    if v_qty>=i.packed_quantity and rem_qty=0 then
    insert into sales_order values------------
    rem-qty:=v_qty-i.packed_quantity;
    v_qty:=rem_qty;
    exit;
    else if v_qty>=i.packed_quantity and rem_qty>=400 then
    insert into sales_order values-----------
    rem_qty:=v_qty-rem_qty;
    v_qty:=rem_qty;
    exit;
    else if v_qty>=i.packed_quantity and rem_qty>0 then
    rem_qty:=v_qty+rem_qty-i.packed_quantity;
    v_qty:=rem_qty;
    insert into sales_order values-----------
    else if v_qty is null and rem_qty>0 and then
    insert into sales_order values-----------
    else if v_qty<i.packed_quantity and rem_qty:=0 then
    rem_qty:=v_qty;
    else if v_qty<i.packed_quantity and rem_qty>0 then
    if (v_qty+rem_qty)>400 then
    insert into sales_order values-----------
    rem_qty:=v_qty+rem_qty-i.packed_quantity;
    v_qty:=rem_qty;
    end if;
    end if;
    end loop;
    end loop;
    The inner for loop will retrieve the same values of v_qty for every iteration of outer for loop when it runs the following select statement:
    select nvl(i.total_quantity,i.actual_quantity) into v_qty from sales_info;
    and thus loses the previously computed values of v_qty and rem_qty
    in the previous iteration of outer for loop whereas i want the inner for loop to iterate over it's previously computed values of v_qty and rem_qty but cant think of a workaround.

    h4. Thanks Dave for explanation. Hope I understood your requirement and below code resolves that
    -- Creating table SALES_INFO
    CREATE TABLE SALES_INFO
    (    S_NO             NUMBER(1),
         ACTUAL_QUANTITY  NUMBER(10),
         TOTAL_QUANTITY   NUMBER(10),
          PACKED_QUANTITY  NUMBER(10)
    -- Creating table sales_order
    CREATE TABLE SALES_ORDER
    (    S_NO             NUMBER(1),
         LABEL            VARCHAR2(30),
         ORDER_QUANTITY   NUMBER(10)
    -- Push SALES_INFO data
    INSERT INTO SALES_INFO VALUES(1,1000,800,400);
    INSERT INTO SALES_INFO VALUES(2,800,600,400);
    INSERT INTO SALES_INFO VALUES(3,800,NULL,400);
    INSERT INTO SALES_INFO VALUES(4,NULL,600,400);
    CREATE OR REPLACE PROCEDURE populate_sales_order AS
    CURSOR get_sales_info IS
    SELECT s_no,
               NVL(total_quantity,actual_quantity) total_quantity,
            packed_quantity
    FROM   sales_info;
    v_s_no          PLS_INTEGER := 0;
    v_rem_qty     PLS_INTEGER := 0;
    v_label_num   PLS_INTEGER := 1;
    BEGIN
    FOR rec IN get_sales_info LOOP
        v_rem_qty := rec.total_quantity + v_rem_qty;
        v_s_no    := rec.s_no;
         WHILE v_rem_qty >= rec.packed_quantity LOOP
           INSERT INTO sales_order( s_no, label, order_quantity)
           VALUES ( v_s_no, 'LABEL' || v_label_num, rec.packed_quantity );
           -- Reduce the packed qty from total qty and increment label counter
           v_rem_qty   := v_rem_qty - rec.packed_quantity ;
           v_label_num := v_label_num + 1;
         END LOOP;
    END LOOP;
    -- Put the last lot remaining qty into last carton
    IF v_rem_qty > 0 THEN
    INSERT INTO sales_order( s_no, label, order_quantity)
    VALUES (v_s_no, 'LABEL' || v_label_num, v_rem_qty );
    END IF;
    COMMIT;
    END;
    S_NO    LABEL                                ORDER_QUANTITY
      1          LABEL1                                    400
      1          LABEL2                                    400
      2          LABEL3                                    400
      3          LABEL4                                    400
      3          LABEL5                                    400
      4          LABEL6                                    400
      4          LABEL7                                    400
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Build array of elements in a for loop

    Hello, I have a program where I am taking voltage measurements and computing resistances inside of a for loop. I then want to take these values an place them in individual arrays which are then sent to another subVI to compute the mean and standard deviation. Currently it appears the arrays are getting overwritten and only one value is stored in the array. Please let  me know what I have to do to fix this. Thank you.
    I have attached my VI and the area I am talking about is in the case statement inside the big for loop for case 1.
    Message Edited by BJalbert on 05-25-2007 09:57 AM
    Attachments:
    StdTest2.vi ‏159 KB

    The image shows two possibilities:
    Still, you should really simplify your data structures. For example you could have all your 7 results as a single 1D array and built it as a 7xN 2D array, etc. You probably can reduce the clutter on the diagram by 90%!
    It is a nightmare to deal with subVIS containing so many individual connectors.
    Message Edited by altenbach on 05-25-2007 08:24 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ArrayBuildingInLoop.png ‏5 KB

  • HT201272 i am trying to download facebook for iphone3gs, it seems that everytime i try to click the free button, it just goes blank green button, and would not continue downloading or does not show any movement

    i am trying to download facebook for iphone3gs, it seems that everytime i try to click the free button, it just goes blank green button, and would not continue downloading or does not show any movement

    Delete your old Firefox Profile and create new one
    *http://kb.mozillazine.org/Creating_a_new_Firefox_profile_on_Windows
    Backup and Restore your profile data's
    *https://support.mozilla.org/en-US/kb/back-and-restore-information-firefox-profiles
    *http://kb.mozillazine.org/Profile_backup

  • I pull fiftyfour bytes of data from MicroProcessor's EEPROM using serial port. It works fine. I then send a request for 512 bytes and my "read" goes into loop condition, no bytes are delivered and system is lost

    I pull fiftyfour bytes of data from MicroProcessor's EEPROM using serial port. It works fine. I then send a request for 512 bytes and my "read" goes into loop condition, no bytes are delivered and system is lost

    Hello,
    You mention that you send a string to the microprocessor that tells it how many bytes to send. Instead of requesting 512 bytes, try reading 10 times and only requesting about 50 bytes at a time.
    If that doesn�t help, try directly communicating with your microprocessor through HyperTerminal. If you are not on a Windows system, please let me know. Also, if you are using an NI serial board instead of your computer�s serial port, let me know.
    In Windows XP, go to Start, Programs, Accessories, Communications, and select HyperTerminal.
    Enter a name for the connection and click OK.
    In the next pop-up dialog, choose the COM port you are using to communicate with your device and click OK.
    In the final pop
    -up dialog, set the communication settings for communicating with your device.
    Type the same commands you sent through LabVIEW and observe if you can receive the first 54 bytes you mention. Also observe if data is returned from your 512 byte request or if HyperTerminal just waits.
    If you do not receive the 512 byte request through HyperTerminal, your microprocessor is unable to communicate with your computer at a low level. LabVIEW uses the same Windows DLLs as HyperTerminal for serial communication. Double check the instrument user manual for any additional information that may be necessary to communicate.
    Please let me know the results from the above test in HyperTerminal. We can then proceed from there.
    Grant M.
    National Instruments

  • LabVIEW 6.1 If For Loop count terminal is zero then value going through the loop is not passed on to the output of the loop

    Hello, one of our customers just encountered an execution error in a vi running under LabVIEW 6.1, which doesn't exist under LabVIEW 5.1 or 6.01. I have a simple vi that has two encapsulated For Loops. Two string arrays go in, one goes out of the outer loop. Inside the outer loop the first array is indexed. The string which results from this indexing is compared with all other strings from the second string array in the inner loop. If it matches one of the strings of the second array, it is not outputted, otherwise this string goes through the inner For Loop to the output of the inner loop and from there to the output of the outer loop. The count
    terminal of the outer/inner loop is connected to the Array Size of the first/second string array. If the second array is empty, that means that the element in test from the first arry cannot match anything from the second array, so the element in test is send to the output of the inner loop and from there to the output of the outer loop. This works fine in LabVIEW 5.1 and 6.01, but NOT in LabVIEW 6.1. In LabVIEW 6.1 the inner loop is never executed if the count value is zero (which is correct), but the data line running through the loop is not executed either, which is different to what LabVIEW 5.1 and 6.01 do. There, the input string is sent to the output of the inner loop correctly even if the loop counter is zero. The solution is easy - I just have to connect the output of the outer loop to the data line BEFORE it enters the inner loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is supposed to be a feature, but it brings some incompatibility in programming between the
    different LabVIEW versions.
    Best regards,
    Gabsi

    Hi,
    When a for-loop runs zero times, all outputs are 'undefined' (and should
    be).
    Besides, how would LV know what the output of a not executed routine should
    be?
    It might be handled differently in LV5 and LV6, which is unfortunate. In
    both cases, the result is undefined.
    It's not a bug. It's just something that should be avoided in any LV
    version.
    > The solution is easy - I just have to connect the
    > output of the outer loop to the data line BEFORE it enters the inner
    > loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is
    In some cases this does the trick. But if the data is changed in the inner
    loop, this will effect the results if the N is not zero.
    Technically, I think the output in this construction is also 'undefined'.
    But LV handles this as expected / desired.
    Another solution is to use a shift register. If N is zero, the input is
    directly passed through to the output.
    Regards,
    Wiebe.
    "Gabs" wrote in message
    news:[email protected]...
    > LabVIEW 6.1 If For Loop count terminal is zero then value going
    > through the loop is not passed on to the output of the loop
    >
    > Hello, one of our customers just encountered an execution error in a
    > vi running under LabVIEW 6.1, which doesn't exist under LabVIEW 5.1 or
    > 6.01. I have a simple vi that has two encapsulated For Loops. Two
    > string arrays go in, one goes out of the outer loop. Inside the outer
    > loop the first array is indexed. The string which results from this
    > indexing is compared with all other strings from the second string
    > array in the inner loop. If it matches one of the strings of the
    > second array, it is not outputted, otherwise this string goes through
    > the inner For Loop to the output of the inner loop and from there to
    > the output of the outer loop. The count terminal of the outer/inner
    > loop is connected to the Array Size of the first/second string array.
    > If the second array is empty, that means that the element in test from
    > the first arry cannot match anything from the second array, so the
    > element in test is send to the output of the inner loop and from there
    > to the output of the outer loop. This works fine in LabVIEW 5.1 and
    > 6.01, but NOT in LabVIEW 6.1. In LabVIEW 6.1 the inner loop is never
    > executed if the count value is zero (which is correct), but the data
    > line running through the loop is not executed either, which is
    > different to what LabVIEW 5.1 and 6.01 do. There, the input string is
    > sent to the output of the inner loop correctly even if the loop
    > counter is zero. The solution is easy - I just have to connect the
    > output of the outer loop to the data line BEFORE it enters the inner
    > loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is
    > supposed to be a feature, but it brings some incompatibility in
    > programming between the different LabVIEW versions.
    > Best regards,
    > Gabsi

  • New Build ... Windows Update Never Shows Updates. Checking for Updates just goes round and round

    I've got a brand new installation of Server 2008 Standard, full with GUI and I've setup the server with a public IP so I can get to the internet.  Even tested getting to Dell Support website.
    But when checking for updates the "Checking for updates" just goes round and round.  It never stops and shows me what updates are available.
    I'm trying to create an image of this build for testing purposes.
    I ran into the same issue when I was doing a VM test and only had a private IP.  I thought I wasn't able to get to Windows Update using our internal proxy with the private IP.  But now there seems to be more of an issue.
    I've already setup the Windows Update service the same way we have for 2003 and 2008 ... Automatic and started.
    Any suggestions?

    Please run the system update readiness tool.
    http://windows.microsoft.com/en-us/windows7/What-is-the-System-Update-Readiness-Tool?SignedIn=1
    Then post the contents of;
    %SYSTEMROOT%\Logs\CBS\CheckSUR.log
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • About a month ago, I began periodically getting the spinning wheel while trimming, adding titles or transitions, etc.  It lasts for about 15 seconds and then goes away.  This seems to happen once every minute or two.  I have more than enough RAM/Power.

    About a month ago, I began periodically getting the spinning wheel while trimming, adding titles or transitions, etc.  It lasts for about 15 seconds and then goes away.  This seems to happen once every minute or two.  I have more than enough RAM/Power, etc.  About every other time I use FCPX it will spontaneously close (typically when editing a title).  None of these things were happening previously.  I have lots of projects that I store on Promise Pegasus drives via Thunderbolt.  I only keep a few projects and the associated events open in FCPX at a time, otherwise I use Event Managaer X to keep track of them.  Can anybody give me any suggestions as to why this is occurring and what I can do to remedy it?  I have the latest version of FCPX as far as I can tell.  This is driving me mad and costing me significant time while editing.  By the way, I am doing just basic editing.  Essentially trimming, cutting and adding some transitions and a few title screens.  Thanks in advance for your help.

    These apperarances of the spinning wheel tend to be related to some io operation that takes too long. Maybe the finder is trying to reach a network server that became unavailable.
    I would try clearing caches and do an overall maintenance with an utility like OnyX.
    Also, trashing preferences does no harm and is often the first troubleshooting measure when FCP X misbehaves.

Maybe you are looking for

  • [Solved] Can't add my Google account to GNOME 3.2 anymore!

    A few days ago I started getting a notification about my Google password being expired(inside GNOME online accounts). So I went there to re-enter it but I couldn't, so I deleted the account to recreate it again. From that point I couldn't get it to s

  • EEIND IS IN WHICH TABLE?

    EEIND IS IN wHICH TABLE?

  • A website that I use does not support 3.6.8 but does support 3.6.7, can I downgrade?

    I cannot view my contract notes on this site and they suggest that I need to downgrade to 3.6.7. How do I do this? == URL of affected sites == http://www.natweststockbrokers.com

  • I want a NEW APP to be created what do I do ?

    How does one request for a New App to be Made for MAEMO-5/N900. I mean I know by logging on to the website talk.maemo.org. But exactly where and how ? And what is the guarantee it would be looked in to ? Can they virtually make an application for wha

  • WEB AS Conection Error

    Hi Guys, I am trying to test connection to the WEB AS system in portal. I am getting the following error, Can you guys guide me where to look for correcting this error. The Web AS ping service http://devep01:50000/sap/bc/ping was not pinged successfu