For Loop and Void Method Questions

Question 1: How would I write a for loop that repeats the according to the number entered, to prompt the user to enter a number (double) between 1 and 100. If the number is outside this range it is not accepted.
Question: 2 Also how would I write a for loop to do sum and find the average of the array numbers in a seperate void method( does not return anything to the main method)?
Question: 3 (first code snippet) With my for loop that is used to process each number in the array and square it and cube it and display the results to 2 decimal places. How do I make it so say I want the array to allow me to enter 2 numbers (so I enter 2 numbers) then it asks me to enter a number between 1 -100 (which will prompt 2 times) that it shows me the results for the entered numbers between 1-100 after one another instead of number then result number then result like I how it now.
for (int index = 0; index < howNum; index++) // process each number in the array
          enterYourNumbers = JOptionPane.showInputDialog   
                        ("Enter a number between 1 and 100");                       
          numArray = new double[howNum]; 
        try
            numArray[index] = Double.parseDouble(enterYourNumbers);
        catch (NumberFormatException e)
                enterYourNumbers = JOptionPane.showInputDialog
                          ("Enter a number between 1 and 100");                          
            DecimalFormat fmt = new DecimalFormat ("###,###.00");
            JOptionPane.showMessageDialog(null, enterYourNumbers + " "  + "squared is "  + fmt.format(calcSquare(numArray[index]))
                                          + "\n" + enterYourNumbers + " " +  "cubed is " + fmt.format(calcCube(numArray[index])));                                                                           
            wantToContinue = JOptionPane.showInputDialog ("Do you want to continue(y/n)? ");
  while (wantToContinue.equalsIgnoreCase("y"));
import javax.swing.*;
import java.text.DecimalFormat;
public class Array
    public static void main(String[] args)
        int howNum = 0;
        int whichNum = 0;     
        double[] numArray;
        boolean invalidInput = true;
        String howManyNumbers, enterYourNumbers, wantToContinue;
  do // repeat program while "y"
      do // repeat if invalid input
        howManyNumbers = JOptionPane.showInputDialog
                    ("How many numbers do you want to enter");                     
        try
             howNum = Integer.parseInt(howManyNumbers);
             invalidInput =  false;
        catch (NumberFormatException e )
            howManyNumbers = JOptionPane.showInputDialog
                        ("How many numbers do you want to enter");
      while (invalidInput);
      for (int index = 0; index < howNum; index++) // process each number in the array
          enterYourNumbers = JOptionPane.showInputDialog   
                        ("Enter a number between 1 and 100");                       
          numArray = new double[howNum]; 
        try
            numArray[index] = Double.parseDouble(enterYourNumbers);
        catch (NumberFormatException e)
                enterYourNumbers = JOptionPane.showInputDialog
                          ("Enter a number between 1 and 100");                          
            DecimalFormat fmt = new DecimalFormat ("###,###.00");
            JOptionPane.showMessageDialog(null, enterYourNumbers + " "  + "squared is "  + fmt.format(calcSquare(numArray[index]))
                                          + "\n" + enterYourNumbers + " " +  "cubed is " + fmt.format(calcCube(numArray[index])));                                                                           
            wantToContinue = JOptionPane.showInputDialog ("Do you want to continue(y/n)? ");
  while (wantToContinue.equalsIgnoreCase("y"));
    public static double calcSquare(double yourNumberSquared)
        return yourNumberSquared * yourNumberSquared;       
    public static double calcCube(double yourNumberCubed)
       return yourNumberCubed * yourNumberCubed * yourNumberCubed;              
    public static void calcAverage(double yourNumberAverage)
}

DeafBox wrote:
Question 1: How would I write a for loop that repeats the according to the number entered, to prompt the user to enter a number (double) between 1 and 100. If the number is outside this range it is not accepted. Use a while loop instead.
Question: 2 Also how would I write a for loop to do sum and find the average of the array numbers in a seperate void method( does not return anything to the main method)? Why would you want to use 2 methods. Use the loop to sum the numbers. Then after the loop a single line of code calculates the average.
Question: 3 (first code snippet) With my for loop that is used to process each number in the array and square it and cube it and display the results to 2 decimal places. How do I make it so say I want the array to allow me to enter 2 numbers (so I enter 2 numbers) then it asks me to enter a number between 1 -100 (which will prompt 2 times) that it shows me the results for the entered numbers between 1-100 after one another instead of number then result number then result like I how it now. If I understand you correctly, use 2 loops. One gathers user inputs and stores them in an array/List. The second loop iterates over the array/List and does calculations.

Similar Messages

  • Customizing order for setter and getter methods in ViewRowImpl

    I have problem to calculate value for one attribute of my viewObjectRow which depends on values of other attributes in my row and result of stored function. I menaged to do all of this except getting value one of attributes that i need. Order of calling getter methods doesn't fit me. I tried lot of things, but nothig worked! Is there some way to customize calling order for getter and setter methods in ViewRowImpl and How?
    Thanks!

    but why addign javadoc to a getter/setter anywhy?Oracle [url http://download.oracle.com/docs/cd/E16162_01/apirefs.1112/e17483/oracle/jbo/common/AccTravDefImpl.html#getAccTravQualifiers()]does, so it must be OK :)
    But as Timo says, there's no automatic way that I know of. I suppose you could do something like that by making your own code template.
    John

  • For loop and xml - how to point the right content in a XML file with a dynamically created button?

    Hi Everybody,
    as my first experience in AS3 I'm bulding a photo multigallery. In that gallery I have some buttons, each one pointing to its respective set of images.
    Each button is created with the for loop, that picks the information from a XML file. From this XML I get the text of the button, the position etc. What I did with some sucess. But there is a scary problem: I don't know how to make each button load the respective and unique set of images.
    I've tryied several different methods, with no effect, to make each loop to give to each button an unique identity to load the respective set of images.
    I imagine that the solution pass by the use of arrays. I wrote some code, and I guess that I'm almost there (but not sure). Here is my AS3 code until now:
    // CREATE MENU CONTAINER //
    var menuContainer:MovieClip = new MovieClip();
    menuContainer.x=10;
    menuContainer.y=300;
    addChild(menuContainer);
    // CREATE IMAGES CONTAINER //
    var imagesContainer:MovieClip = new MovieClip();
    imagesContainer.x=10;
    imagesContainer.y=10;
    addChild(imagesContainer);
    //// LOAD XML ////
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, whenLoaded);
    xmlLoader.load(new URLRequest("XML/roiaXML.xml"));
    var xml:XML;
    function whenLoaded(evt:Event):void {
         xml=new XML(evt.target.data);
         var mySetsList:XMLList=xml.children();
         //// MENU BUTTONS ////
         // CREATE ARRAYS //
         var totalArray:Array = new Array();
         var setNodesArray:Array = new Array();
         var setNamesArray:Array = new Array();
         // POSITIONING BUTTONS INSIDE MENU CONTAINER//
         var rowsQuantity:Number=3;
         var columnsQuantity:Number=Math.ceil(mySetsList.length()/rowsQuantity);
         var cellWidth:Number=160;
         // CREATE BUTTONS //
         for (var i:int=0; i< mySetsList.length(); i++) {
              var newSetButtonMC:setButtonMC=new setButtonMC();
              //what do I do here to make it works? To give each button created a unique id.
              setNodesArray.push(i);
              //trace(setNodesArray);
              var imageNodesArray:Array = new Array();
              for (var j:int=0; j<mySetsList[i].IMAGE.length(); j++) {
                   imageNodesArray.push(mySetsList[i].IMAGE[j].attribute("imageTitle"));
              totalArray.push(imageNodesArray);
              newSetButtonMC.setButtonText.text=mySetsList.attribute("galeriaTitle")[i];
              newSetButtonMC.setButtonText.autoSize=TextFieldAutoSize.LEFT;
              var cellX:Number=Math.floor(i/rowsQuantity);
              var cellY:Number=i%rowsQuantity;
              newSetButtonMC.x=cellX*cellWidth;
              newSetButtonMC.y=cellY*(newSetButtonMC.height+10);
              newSetButtonMC.addEventListener(MouseEvent.CLICK, onClick);
              menuContainer.addChild(newSetButtonMC);
         totalArray.push(setNodesArray);
         //// MENU BUTTONS ACTIONS ////
         function onClick(mevt:MouseEvent):void {
              trace(totalArray [0][0]);
              trace(totalArray [0][0]);
              // in the line above I achieved some success loading a specific info from XML.
              // but I don't know what to do with it.
              //what do I do here? To make each button to load its own node from XML.
    Here is my XML:
    <GALERIA galeriaTitle="galeria 01">
      <IMAGE imageTitle="imageTitle01">feio.jpg</IMAGE>
      <IMAGE imageTitle="imageTitle02">muitofeio.jpg</IMAGE>
      <IMAGE imageTitle="imageTitle03">aindamaisfeio.jpg</IMAGE>
    </GALERIA>
    <GALERIA galeriaTitle="galeria 02">
      <IMAGE imageTitle="imageTitle01">estranho.jpg</IMAGE>
      <IMAGE imageTitle="imageTitle02">maisestranho.jpg</IMAGE>
      <IMAGE imageTitle="imageTitle03">aindamaisestranho.jpg</IMAGE>
    </GALERIA>
    Thanks everyone . ABSTRATO

    you can assign each newSetButtonMC and ivar property that points to its i value or, even easier:
    // CREATE MENU CONTAINER //
    var menuContainer:MovieClip = new MovieClip();
    menuContainer.x=10;
    menuContainer.y=300;
    addChild(menuContainer);
    // CREATE IMAGES CONTAINER //
    var imagesContainer:MovieClip = new MovieClip();
    imagesContainer.x=10;
    imagesContainer.y=10;
    addChild(imagesContainer);
    //// LOAD XML ////
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, whenLoaded);
    xmlLoader.load(new URLRequest("XML/roiaXML.xml"));
    var xml:XML;
    function whenLoaded(evt:Event):void {
         xml=new XML(evt.target.data);
         var mySetsList:XMLList=xml.children();
         //// MENU BUTTONS ////
         // CREATE ARRAYS //
         var totalArray:Array = new Array();
         var setNodesArray:Array = new Array();
         var setNamesArray:Array = new Array();
         // POSITIONING BUTTONS INSIDE MENU CONTAINER//
         var rowsQuantity:Number=3;
         var columnsQuantity:Number=Math.ceil(mySetsList.length()/rowsQuantity);
         var cellWidth:Number=160;
         // CREATE BUTTONS //
         for (var i:int=0; i< mySetsList.length(); i++) {
              var newSetButtonMC:setButtonMC=new setButtonMC();
              //what do I do here to make it works? To give each button created a unique id.
              setNodesArray.push(i);
              //trace(setNodesArray);
              var imageNodesArray:Array = new Array();
              for (var j:int=0; j<mySetsList[i].IMAGE.length(); j++) {
                   imageNodesArray.push(mySetsList[i].IMAGE[j].attribute("imageTitle"));
             nextSetButtonMC.imageArray = imageNodesArray;
              //totalArray.push(imageNodesArray);
              newSetButtonMC.setButtonText.text=mySetsList.attribute("galeriaTitle")[i];
              newSetButtonMC.setButtonText.autoSize=TextFieldAutoSize.LEFT;
              var cellX:Number=Math.floor(i/rowsQuantity);
              var cellY:Number=i%rowsQuantity;
              newSetButtonMC.x=cellX*cellWidth;
              newSetButtonMC.y=cellY*(newSetButtonMC.height+10);
              newSetButtonMC.addEventListener(MouseEvent.CLICK, onClick);
              menuContainer.addChild(newSetButtonMC);
         totalArray.push(setNodesArray);
         //// MENU BUTTONS ACTIONS ////
         function onClick(mevt:MouseEvent):void {
              var mc:setButtonMC=setButtonMC(mevt.currentTarget);
    for(i=0;i<mc.imageArray.length;i++){
    trace(mc.imageArray[i]);
    Here is my XML:
    <GALERIA galeriaTitle="galeria 01">
      <IMAGE imageTitle="imageTitle01">feio.jpg</IMAGE>
      <IMAGE imageTitle="imageTitle02">muitofeio.jpg</IMAGE>
      <IMAGE imageTitle="imageTitle03">aindamaisfeio.jpg</IMAGE>
    </GALERIA>
    <GALERIA galeriaTitle="galeria 02">
      <IMAGE imageTitle="imageTitle01">estranho.jpg</IMAGE>
      <IMAGE imageTitle="imageTitle02">maisestranho.jpg</IMAGE>
      <IMAGE imageTitle="imageTitle03">aindamaisestranho.jpg</IMAGE>
    </GALERIA>
    Thanks everyone . ABSTRATO

  • Node removing in a Tree, for loop, and Enumeration

    Hi there
    it should be pretty easy, however i'm stuck with this code:
    public void supprNode(DefaultMutableTreeNode node){
    for(en = node.preorderEnumeration();e.hasMoreElements();){
    DefaultMutableTreeNode tmpNode= (DefaultMutableTreeNode) en.nexElement();
    if (tmpNode instanceof myderivedNodeClass)
        tmpNode.doSomething();
    if(!tmpNode.isRoot())
        removeNodeFromParent(tmpNode);
    }The problem is, the for loop doesn't traverse all the elements. That's if i call removeNodeFromParent. Is the enumeration updated twice?
    ie if my tree is
    root
    -1
    -2
    -3after the call of supprNode(root) i get:
    root
    -2And i really don't understand why.

    Hi!
    If you look at the apidoc of DefaultMutableTreeNode.preorderEnumeration() you will see following text:
    * Modifying the tree by inserting, removing, or moving a node invalidates
    * any enumerations created before the modification.
    So you should copy the elements of the enumeration in a separate list and iterate then over this list!
    With kind regard,
    Mathias

  • Best fit lines for loops and sine waves

    I am trying to find a best fit line that will work for sine waves and loops (hysteresis loops). I can get the sine wave just fine, but when I switch to a hysteresis it just puts a line across the middle (I assume because of the 2 y values for every x). I am doing data acquisition that will take in both forms and graph them. I tried a polynomial fit and it doesn't work at least the way I implemented it and I tried a few others but it looks like they are all function based. Also, my y values are coming out of a Bessel filter. I don't think this would be affecting anything but I thought I would put it in here incase it does.
    Did I miss one that I haven't tried that works for my application?
    Thanks
    Patrick

    RiversDaddy wrote:
    ... currently I am doing it by looping and reducing the error towards zero to fit the amplitude and phase. (I know the frequency).  If this is what you are looking to do then I will help, or should I be doing things differently? All of the functions I have found to filter or extract tones seem to introduce a larger frequency of phase error than i get using this method, but am I missing something?
    "looping" is a bit vague. What is the actual algorithm to find better estimates (e.g. levenberg marquardt, etc.)
    What problems did you have with extract single tone. Can you show some data where the results from it are not good?
    LabVIEW Champion . Do more with less code and in less time .

  • Where is the getString() implementation for RS and Object class question

    Dear all,
    I had these two questions ringing since a long time.
    1)ResultSet is an interface.
    In my jdbc code I have generally written rs.getString() and rs.getInt etc.. without giving a second thought as to where exactly is this getter implemented !
    I have RTF API .. without too much help.
    Could some one kindly explain Where is the implementation of the getString method ?
    2) Could you please tell why the Wait() Notify() and NotifyAll methods have been implemented in the Object class ? What was the need to define em in the Object class ?
    Thanks in advance for your time spent on this.
    Rgds

    Sarvananda wrote:
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    Rgds
    >
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    A desire to not have to couple your code to a particular database and JDBC driver. It's a classic example of the abstract factory pattern

  • Help with a FOR loop and an object array

    I need to make a for loop that takes an array of objects that contain the parameters year, type, and model (all ints) and sort by year, then divide the array in all the objects with the same year and sort them by type, then divide the array again into the objects with the same year AND type and sort them by model.
    the object a Dress objects, the get methods are get+nameof parameter.
    the array is a 1D array called Dresses.
    I have made a paralell array to store the value of the parameters and sort that then move the array acording to that sorted array. The problem is in the division of the array.

    We'll give your request to do (or finish) your homework for you the attention it deserves.

  • Event structure in "for loop" and stacked sequence

    I tried to put an event structure into a for loop sequence, then used a pause button to pause the program (one loop with event structure.vi). The pause button functioned normally since the program could be paused whenever the button was pressed. Then, I put this for loop sequence into a stacked sequence (Problem.vi), which has 2 frames and every frame has the for loop sequence in it. After the pause button was pressed once, the pause button and stop button will no longer effective anymore. Where should I modify so that this program will work properly? Thanks a lot.
    Attachments:
    Problem.vi ‏42 KB
    one_loop_with_event_structure.vi ‏27 KB

    Ah, at last something weird !
    The answer is simple : don't do that !
    You should either avoid having 2 event structures handling the same events, or learn how to process dynamic events.
    Why didn't you read the answers to a question posted a few hours ago (still on the overview page of this forum ?). See here.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • How to code a parallel 'for loop' and 'while loop' where the while loop cannot terminate until the for loop has finished?? (queues also present)

    I've attached a sample VI that I just cannot figure out how to get working the way that I want.  I've labeled the some sections with black-on-yellow text boxes for clarity during the description that follows in the next few sentences.  Here's what I want:
    1) overall -- i'm intend for this to be a subVI that will do data acquisition and write the data to a file.  I want it to use a producer/consumer approach.  The producer construct is the 'parallel for loop' that runs an exact number of times depending on user input (which will come from the mainVI that is not included).  For now I've wired a 1-D array w/ 2 elements as a test case.  During the producer loop, the data is acquired and put into a queue to be delt with in the consumer loop (for now, i just add a random number to the queue).
    2) the consumer construct is the 'parallel while loop'.  It will dequeue elements and write them to a file.  I want this to keep running continuously and parallel until two conditions are met.
          i. the for loop has finished execution
          ii. the queue is empty.
       when the conditions are met, the while loop will exit, close the queue, and the subVI will finish. (and return stuff to mainVI that i can deal with on my own)
    Here's the problems.
    1)  in the "parallel for loop" I have a flat sequence structure.. I haven't had time to incorporate some data dependency into these two sequential sections, but basically, I just care that the "inner while loop" condition is met before the data is collected and queued.  I think I can do this on my own, but if you have suggestions, I'm interested.
    2)  I can easily get the outer for and while loops to run sequentially, but I want them to run in parallel.  My reasoning for this is that that I anticipate the two tasks taking very different amounts of time. .. basically, I want the while loop to just keep polling the queue to get everything out of it (or I suppose I could somehow use notifiers - suggestions welcome)...  the thing is, this loop will probably run faster than the for loop, so just checking to see that the queue is empty will not work... I need to meet the additional condition that nothing else will be placed in the queue - and this condition is met when the for loop is complete. basically, I just can't figure out how to do this.
    3) for now, I've placed a simple stop button in the 'parallel while loop', but I must be missing something fundamental here, because the stop button is totally unresponsive.  i.e. - when I press it, it stays depressed, and nothing happens.
    suggestions are totally welcome!
    thanks,
    -Z
    Attachments:
    daq01v1.vi ‏59 KB

    I'd actually like to add a little more, since I thought about it a bit and I'm still not quite certain I understand the sequence of events...
    altenbach wrote:
    zskillz wrote:
    So i read a bit more about the 'dequeue element' function, and as I understand it, since there is no timeout wired to the dequeue element function, it will wait forever, thus the race condition I suggested above can never happen!
    Yes, you got it!
    As I've thought about it a bit more, there's a few things that surprise me... first, the reason the 'dequeue element while loop' errors is not because there's nothing in the queue, it's becaues the queue has been released and it's trying to access that released queue...   However the problem I have is this --- Even though there's no timeout wired to the dequeue element, I still would think that the while loop that contains it would continue to run at whatever pace it wanted -- and as i said before.. most of the time, it would find that there is nothing to dequeue, but once in a while, something is there.  however, it seems that this loop only runs when something has been enqueued.  the reason I say this is illustrated in the next code sample MODv2 that's attached below.  I've added a stop button to the "queue size while loop" so the program runs until that is pressed.  I've also added a simple conditional in the "dequeue while loop"  that generates a random number if it a button is pressed... but this button is totally non-responsive... which means to me that the "dequeue while loop" isn't actually continuously running, but only when an element is added to the queue.  this still seems almost like the 'dequeue while loop" waits for a notifier from the queue telling it to run.  can you explain this to me? because it is different from what I expect to be happening.
    rasputin wrote:
    I tried to open your VIs but it doesn't work. LV
    is launched, the dialog box (new, open, configure...) opens and then...
    nothing. Not even an error message. I guess it isn't a problem of LV
    version or a dialog box would appear saying this. Could you, please,
    send a image of the code?
    Thanks,
    Hi Rasputin, I'm using LV8.  I assume that was your problem, but who knows.  I've attached a pic of of altenbach's solution since it's what I needed.
    thanks
    -Z
    Message Edited by zskillz on 10-20-2006 11:49 AM
    Attachments:
    daq01v1MODv2.vi ‏63 KB
    daq01v1MODpic.JPG ‏116 KB

  • Getting new Mac for Aperture and have a question...

    I totally realize that this is a personal preference with no "wrong" way to do it. However, I would appreciate some thoughts so I can form a better idea of how I will set up an Aperture workflow that will work for me for a long time and how to configure my new iMac.
    I use the referenced library workflow and store both my masters and Aperture library on my current internal drive with both backed up to externals. I'm getting a new Mac with the SSD drive for apps and OS (and Aperture library as well). The question is, should I get the mega 2 TB internal HDD along with that SSD for all my masters (which would also include my music and home-made movies)?
    My current photo storage adds up to only 130GB right now and grows slowly. I don't even think I would double that in the next year. I realize that if I had, say, a 1.5 TB size Masters library, the the answer would be obvious that I would need to store externally because the iMac HDD isn't big enough. But that isn't my situation.
    But since I would be able to fit all my photos on an internal HDD (2TB) to use as referenced, is there a better reason to skip the internal 2TB HDD and just get hooked up with some good, high-speed external system and stick with an internal SSD to just handle the OS, music, and apps? In other words, all my media (photos and movies) would always be stored AND edited from an external drive (I will actually edit on the SSD and then move the referenced files to the external). This means that from now on all new Macs I ever get will only need a moderate sized SSD for OS and apps. I would basicallt forever keep all things media on externals.
    I hope this makes sense. Thanks for any help with this.

    jbshanks wrote:
    One other thing... the only way for me to get a 1GB VRAM now is to buy the top-of-the-line iMac. That's the issue.
    I've seen that also. That's why I added the "If you can wait.." statement.
    If you need to purchase before say late October, then the specs you list for the 21" iMac are quite good and the possibility of developers designing GPU threads that require caching in the VRAM may or may not need amounts beyond 512 MB. The fact that Apple offers an upgrade to the 2 GB VRAM video adapter on their high-end machine tells me that they know that the Pro Apps will be able to take advantage of that amount (not that it is necessary for the enthusiast looking to have a good Aperture experience).
    SierraDragon has much more experience than I with Aperture, so he may be able to shed some light on this one.
    For my part, I run a 17" MacBook Pro (late 2011) which has the 2.5 Ghz i7, 8 GB Apple provided RAM, and the AMD 6770 with 1 GB VRAM. I installed an OWC 480 GB SSD and I am connected to the Apple Thunderbolt Display (because this machine only offers a Thunderbolt port to connect video signals with). Aperture runs fine on my machine (although for some reason cropping takes a couple of seconds now, where it was immediate before the AP 3.3 update). I run Photoshop CS6 and Illustrator CS6 without any issues on this machine, so it is definitely capable of running in a professional environment.
    Since your specs call-out a 2.8 Ghz i7, 16+ GB RAM and an SSD, I personally would not hesitate to purchase that machine if you need to purchase soon. I just mentioned the 1 GB VRAM due to your wanting to be able to handle 4+ years of updates to the OS and software. That doesn't mean the 512 GB VRAM won't work great, just that the 1 GB VRAM would be additional insurance (sort of like Apple Care).

  • I need to take elements from within 2 nested for loops and place them in an array at the specific row and column that I need.

    I have tried intializing an array and replacing elements by specifying a particular row, and column, but in the end I get an array with only one element replaced, and I suspect that it is because as the for loops are running through their iterations each time the array is re-initializing. I have a simple vi that I will post below, it is not the exact situation that I have but is a good place for me to get some understanding. I have the row and column indexes being driven by the inner and outer loop iterations, which gives me the pattern I need. I am using the inner iterations as array elements. How do I set this up so that it works and d
    oes keep re-initializing my array.
    Attachments:
    Untitled.vi ‏26 KB

    I have fixed a number of things in your vi.
    You were right in thinking that the array was continuously re-initialized. To avoid this, use a shift register (right-click the loop border), which will pass the updated array into the next iteration.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    your_vi.vi.zip ‏13 KB

  • Creating a function with  a for loop and %type

    Hello,
    I am trying to create a function which contains a for loop as well as %type.
    This function is on a student table and i am trying to create a function which will display the zip which is a varchar2(5).
    I need to do this through this function.
    However, I can't seem to get it running.
    Can anyone help?
    below is what i tried as well as other options and was not successful.
    I also displayed my error with the show error command.
    SQL> create or replace function zip_exist
    2 return varchar2
    3 is
    4 v_zip student.zip%TYPE;
    5 cursor c_zip is
    6 select zip
    7 from
    8 student
    9 where zip=zip;
    10 begin
    11 open c_zip;
    12 v_zip IN c_zip
    13 loop
    14 v_zip:=c_zip%TYPE;
    15 end loop;
    16 close c_zip;
    17 end;
    18 /
    Warning: Function created with compilation errors.
    SQL> show error
    Errors for FUNCTION ZIP_EXIST:
    LINE/COL ERROR
    12/7 PLS-00103: Encountered the symbol "IN" when expecting one of the
    following:
    := . ( @ % ;
    16/1 PLS-00103: Encountered the symbol "CLOSE"
    SQL>
    kabrajo

    user10873577 wrote:
    Hello,
    I am trying to create a function which contains a for loop as well as %type.
    This function is on a student table and i am trying to create a function which will display the zip which is a varchar2(5).
    I need to do this through this function.
    However, I can't seem to get it running.
    Can anyone help?
    below is what i tried as well as other options and was not successful.
    I also displayed my error with the show error command.
    SQL> create or replace function zip_exist
    2 return varchar2
    3 is
    4 v_zip student.zip%TYPE;
    5 cursor c_zip is
    6 select zip
    7 from
    8 student
    9 where zip=zip;
    10 begin
    11 open c_zip;
    12 v_zip IN c_zip
    13 loop
    14 v_zip:=c_zip%TYPE;
    15 end loop;
    16 close c_zip;
    17 end;
    18 /
    Warning: Function created with compilation errors.
    SQL> show error
    Errors for FUNCTION ZIP_EXIST:
    LINE/COL ERROR
    12/7 PLS-00103: Encountered the symbol "IN" when expecting one of the
    following:
    := . ( @ % ;
    16/1 PLS-00103: Encountered the symbol "CLOSE"
    SQL>
    kabrajoTry This
    Create a sample table
    SQL> create table student(id number(10),zip varchar2(5));
    Table created.Insert the record
    SQL> insert into student values(1111,'A5454');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from student;
            ID ZIP
          1111 A5454
    SQL> create or replace function zip_exist(v_id number)
      2   return varchar2
      3   is
      4   v_zip student.zip%TYPE;
      5  BEGIN
      6   select zip
      7   INTO v_zip
      8   FROM student
      9   where id=v_id;
    10   Return v_zip;
    11  EXCEPTION WHEN NO_DATA_FOUND THEN
    12                  RETURN 'INVALD';
    13  WHEN OTHERS THEN
    14                 return  'NA!';
    15   end;
    16  /
    Function created.
    SQL> set serveroutput on
    SQL> select zip_exist(1111) from dual;
    ZIP_EXIST(1111)
    A5454
    SQL> select zip_exist(2222) from dual;
    ZIP_EXIST(2222)
    INVALDHope this helps
    Regards,
    Achyut K

  • Please help with the FOR loop and the array..

    I was trying to place some words in the Movie Clip
    "TextPanel" and set a
    random position to each of them.
    But it's not working.
    1) I created a Movie Clip "word" and inside that MC I created
    a text field
    and gave it an identifier "textFiled".
    2) The linkage name for Movie Clip "word" I set to "word".
    3) In the actionscript I created an Array called "aWords".
    4) Then I created a FOR loop that should
    place (attach) Movie Clips "word0", "word1", "word2" and
    "word3" to the
    movie clip TextPanel, and set the textField text for each of
    them to the
    text from the Array.
    But the script attaches 4 Movie Clips with a name
    "Undefined", instead of 4
    different names (from the Array).
    What is wrong with this script?
    var aWords:Array = [apple,banana,orange,mango];
    for(i=0;i<aWords.length;i++){
    var v = TextPanel.attachMovie("word","word"+i,i);
    v.textFiled.text = aWords
    v._x = randomNumber(0,Stage.width);
    v._y = randomNumber(0,Stage.height);
    Thanks in advance

    But in my Post I already wrote v.textFiled.text = aWords
    so I don't understand what were you correcting..
    And one more:
    I have tested it by changing the
    v.textFiled.text = aWords; to v.textFiled.text = "some
    word";
    and it's working fine.
    So there is something wrong with the Array element, and I
    don't know why..
    "aniebel" <[email protected]> wrote in
    message
    news:ft2d5k$lld$[email protected]..
    > Change:
    > v.textFiled.text = aWords;
    >
    > to:
    > v.textFiled.text = aWords
    >
    > It needs to know which element inside the array you want
    to place in the
    > textfield (or textfiled) :)
    >
    > If that doesn't work, double check that your instance
    name is correct
    > inside
    > of "word".
    >

  • I'm having problems manipulating array data within a for loop, and extracting the required sub-arrays generated.

    Hi,
    I'm using labVIEW V5.1
    I'm trying to generate 10 1D arrays, the first array is initialized to all zeroes, then I have set up a for loop which shifts the first element by 1, then a random number is placed into the first element position. I am using a shift register to feed back in the newly generated array into the start of the loop.
    By the end of the each loop I want to be able to use the array generated in an algorithm outside the loop. However I only want the Nx1 array that has just been generated.
    Unfortunately, I cannot figure out how to resize, reshape or index the output array to do this.
    I would like the loop to
    give me out a 1D array after each iteration.
    Any help would be greatly appreciated.

    I hope I've understood your problem.
    First your vi was lacking of the sub-vi working as shift register, I've replaced it with the rotate function.
    The indexing of your arrays create a 2D array whose rows are your 1D array.To pick only one of them you have to use the index array function and select which one you want.
    To use your temporary data in another part of your application you should use a local variable of array2.
    I did it in a separated while loop That I syncronized with the for loop using occurrence, in this way the while loop runs each time a new value is inserted in array2 (each loop of the for loop structure).
    If you don't need this syncronization just get rid of occurrence functions.
    I place a delay in the for loop to show what happens when running.
    Hope it was helpful.
    Alberto Locatelli
    Attachments:
    array_test_v3.vi ‏35 KB

  • Handle Error in for Loop and finish the iteration

    I am using a for Loop now i encounter an error.
    i want to handle this error but after that carry on with iteration of the loop.
    Any Parallel to "Continue" in JAVA or any other solution for this...
    Please Suggest.

    You can use pl/sql block with exception inside the loop
    Re: Continue beyond expcetion in proc...
    Message was edited by:
    jeneesh

Maybe you are looking for

  • How to Delete Sales orders in BW which are  Archived  in R/3

    Hi All, Sales orders were archived in R/3 But it is still present in BW. I need to Delete the orders. Moroover i need to schedule a job for every two weeks checking in R/3 for archived and deleting it from BW. How this can be done. Can anybody help?

  • How to print logical page number in TOC of report

    My report has three sections - header, main, trailer. after each group break in the main section the page number is saved using the srw.get_page_num(pageNum). this records are used to build the toc in the trailer section. Problem: srw.get_page_num de

  • WLSE - AP/WDS fails to complete full authentication phase

    I need the patch for the following bug. I can't find it anywhere.. Can someone help.. I know people have used it to fix their issues before. This issue is documented in Cisco bug ID CSCsb47726. There is a pointed patch available for ACS 3.3.3 (both A

  • Oracle 9i Upgrade to 10g - Single Database instances to RAC

    Hi, We are considering migrating from single SAP database architecture into an Oracle 10g RAC architecture. The question i have is: Are multiple PHYSICAL databases supported in one Oracle 10g RAC environment? For example, Is it possible to install an

  • NOCOPY USAGE IN ORACLE FUNCTIONS

    Hi, what are the advantages of NOCOPY ? Can you please give an example for a function that uses NOCOPY? Thanks in advance