Objects in a FOR loop

Can anyone see why this loop won't work?:
for (int i = 0; i < name.length; i++)
System.out.println(instrument[ i ].getName());
- Where "name" is an array with 12 elements,
- Where "instrument" is an object (there are 12 objects each named instrument1, instrument2, instrument3 etc).
- Each instrument object has a "getName" method which returns it's name attribute.
- And obviously there's not really any spaces in the [ i ] - i've had to do that to prevent going into italics on this board!
I was hoping this would print out 12 lines - each line being the "name" of each instrument, but instead, on compilation i get the following error:
error75: variable instrument not found in class
But of course, instrument isn't a varbiable, it's an object!
Any help would really really be appreciated :)

thanks for replying so swiftly. Basically, i'm really really new to this so i think the best thing for me to do would be to post to whole program so far asi don't know if i've declared instrument wrongly somewhere else. In the below code i've got 2 classes within the same program:
public class instrumentArraySearch03
     public static void main(String[] args)
    String searchCriteria;   // variables
    int searchChoice;
       String againYesNo;
    String [] name = new String[13];   // create name array
    String [] type = new String[13];   // create type array
    String [] price = new String[13];   // create price array
    name[0] = "fender";
    name[1] = "gibson";
    name[2] = "squire";
    name[3] = "casio";
    name[4] = "korg";
    name[5] = "shure";
    name[6] = "akg";
    name[7] = "mcscott";
    name[8] = "pearl";
    name[9] = "ludwig";
    name[10] = "classical co.";
    name[11] = "sax co.";
    name[12] = "violin co.";
    type[0] = "electric guitar";
    type[1] = "acoustic guitar";
    type[2] = "electric bass";
    type[3] = "acosutic bass";
    type[4] = "banjo";
    type[5] = "violin";
    type[6] = "saxophone";
    type[7] = "clarinet";
    type[8] = "flute";
    type[9] = "bagpipes";
    type[10] = "keyboard";
    type[11] = "drumkit";
    type[12] = "microphone";
    price[0] = "49";
    price[1] = "59";
    price[2] = "99";
    price[3] = "149";
    price[4] = "199";
    price[5] = "249";
    price[6] = "300";
    price[7] = "350";
    price[8] = "399";
    price[9] = "450";
    price[10] = "599";
    price[11] = "799";
    price[12] = "999";
     // testing out whether objects work  - see class at bottom of page
    instrument instrument1 = new instrument(name[0], type[2], price[3]);
    instrument instrument2 = new instrument(name[11], type[2], price[0]);
    instrument instrument3 = new instrument(name[2], type[2], price[11]);
    instrument instrument4 = new instrument(name[0], type[2], price[7]);
    instrument instrument5 = new instrument(name[4], type[2], price[8]);
    instrument instrument6 = new instrument(name[8], type[2], price[6]);
    instrument instrument7 = new instrument(name[7], type[1], price[2]);
    instrument instrument8 = new instrument(name[1], type[2], price[9]);
    instrument instrument9 = new instrument(name[5], type[2], price[10]);
    instrument instrument10 = new instrument(name[6], type[2], price[5]);
    instrument instrument11 = new instrument(name[10], type[2], price[4]);
    instrument instrument12 = new instrument(name[3], type[2], price[1]);
          for (int i = 0; i < name.length; i++)
      System.out.println("instrument name is " + instrument.getName());
} // ends main method
} // ends class
class instrument
private String name;
private String type;
private String price;
public instrument(String nameIn, String typeIn, String priceIn) // constructor
name = nameIn;
type = typeIn;
price = priceIn;
public String getName()
return name;
public String getType()
return type;
public String getPrice()
return price;

Similar Messages

  • Multiple objects, multiple domains, for-loops the problem?

    Hi,
    I've based a small amount of Powershell code off the code I've found here: http://halfloaded.com/blog/powershell-using-posh-to-search-across-multiple-domains-in-forest/
    Ideally what I'm aiming for is for it to find the current forest, enumerate the domains, and then for each domain to search for a specific user. If it finds the user it should then do something, for now just clear a value extensionAttribute8.
    What I suspect is happening is it finds the users but then tries to modify them while attached to the current domain, which is child1.
    Domain structure:
     - Root
       - child1
       - child2
    cls
    $objForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
    $DomainList = @($objForest.Domains | Select-Object Name)
    $Domains = $DomainList | foreach {$_.Name}
    foreach($Domain in ($Domains))
    $ADsPath = [ADSI]"LDAP://$Domain"
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)
    $objSearcher.Filter = "SamAccountName=testuser"
    $objSearcher.SearchScope = "Subtree"
    $colResults = $objSearcher.FindAll()
    foreach ($objResult in $colResults)
    $userDomain = $objResult.GetDirectoryEntry()
    Set-ADUser $userDomain.DistinguishedName[0] -clear extensionAttribute8
    It errors with
    Set-ADUser : Cannot find an object with identity: 'CN=testuser,CN=Users,DC=root,DC=company,DC=co,DC=uk' under: 'DC=child1,DC=root,DC=company,DC=co,DC=uk'.
    At line:17 char:9
    + Set-ADUser $userDomain.DistinguishedName[0] -clear extensionAttribute8
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (CN=testuser,C...pny,DC=co,DC=uk:ADUser) [Set-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : Cannot find an object with identity: 'CN=testuser,CN=Users,DC=root,DC=company,DC=co,DC=uk' under: 'DC=child1,DC=root,DC=company,DC=co,DC=uk'.,Microsoft.ActiveDirectory.Management.Comman
    ds.SetADUser
    Set-ADUser : Cannot find an object with identity: 'CN=testuser,CN=Users,DC=child2,DC=root,DC=company,DC=co,DC=uk' under: 'DC=child1,DC=root,DC=company,DC=co,DC=uk'.
    At line:17 char:9
    + Set-ADUser $userDomain.DistinguishedName[0] -clear extensionAttribute8
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (CN=dttestuser,C...ita,DC=co,DC=uk:ADUser) [Set-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : Cannot find an object with identity: 'CN=dttestuser,CN=Users,DC=its,DC=ad,DC=capita,DC=co,DC=uk' under: 'DC=central,DC=ad,DC=capita,DC=co,DC=uk'.,Microsoft.ActiveDirectory.Management
    .Commands.SetADUser
    Please help!

    cls
    Import-Module ActiveDirectory
    Foreach ($Domain in (Get-ADForest).Domains)
    #Performing Search Operation per Domain
    $Objects = Get-ADObject -LDAPFilter "SamAccountName=dttestuser" -Server $Domain -Properties extensionAttribute8
    Foreach ($Object in $Objects)
    Set-ADUser $Object -clear extensionAttribute8
    If anyone could tell me why removing the loop:
    Foreach ($Object in $Objects)
    And saying
    Set-ADUser $Objects -clear extensionAttribute8
    Errors I'd be interested. $objects only finds 1 object so having the loop makes no sense but it does seem to stop it error'ing!

  • Can I use a for loop to add anonymous ActionListener objects?

    I have a setListener() method that has the following inside:
    for(int k = 0; k < buttons.length; k++)
        buttons[k].addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                g2.setColor(colors[k]);
    }I have a JButton array and a Color array and I was hoping I could add them quickly in one shot rather than manually adding an anonymous ActionListener 9 times (I have 9 components). It tells me I need to make k final for an inner class and when I tested it by removing the for loop and keeping k as a final integer, it works. Is there a medium such that I can achieve what I want more or less while respecting Java's syntax?
    Any input would be greatly appreciated!
    Thanks in advance!

    s3a wrote:
    The local variable exists on the stack for as long as the method is executing. Once the method ends, that variable no longer exists. The newly created object, however, can continue to exist long after the method has ended. So when it's referring to variable X, it cannot refer to the same X as the one in the method, because that variable may no longer exist.Sorry for picking on little details but I am still not fully satisfied.
    Earlier I questioned if the local variable changed, but now let's say that that variable no longer exists at all, why does that even matter if the inner class copied the value and is keeping it for itself? What do you mean? The variable that existed in the method ceased to exist when the method ended. The inner class, however, can continue to live on, and can continue to refer to what we see as the same variable. However, it obviously can't be the same variable, since, in the world of the inner class, it still exists, while in the world of the method, it does not.
    This is completely independent of whether the variable changes or not. Regardless or whether the variable changes we still need two copies--one that goes away when the method's stack frame is popped, and one that lives on as long as the inner object does.
    Then, because there are two copies, the designers decided that the variable has to be final, so that they wouldn't have to mess with the complexity of keeping two variables in sync.
    That explanation leads me to believe that there is no copy and that there is some kind of "permanent umbilical cord" between the inner class and the local variable.Wrong. There has to be a copy. How else could the inner class keep referring to it after the method ends?
    Also, does marking it as final force it to be a permanent constant "variable" even if it's not a field "variable"? Or, similarly, does making a "variable" final make Java pretend that it is a field "variable"?Making a variable final does exactly one thing: It means the value can't change after it's been initialized. This is true of both fields and locals.
    As for the "pointless" byte-counting, I really don't see how it's confusing unless you're an absolute beginner. If I see somebody using a byte, I assume they have a real reason to do so, not pointless byte-hoarding. Then when I see that it's just a loop counter, I wonder WTF they were thinking, and have to spend some time determining if there's a valid reason, or if they're just writing bad code. Using a byte for a loop counter is bad code.
    I could then ask, why are people not using long instead of int and saying that that's using int is too meticulous?Part of it is probably historical. Part of it is because at 4 bytes, and int is exactly on word on the vast majority of hardware that Java has targeted since it came out. 8-byte words are becoming more common (64-bit hardware) but still in the minority.

  • 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.

  • Garbage Collection: how many objects are created after for loop?

    Please see the fallowing java code
    1 public class Test1 {
    2     
    3     public static void main(String[] args) {
    4          
    5          MyObj obj = null;
    6          for(int i=0;i<5;i++){
    7               obj = new MyObj();
    8          }
    9 // do something
    10
    11     }
    12 }
    so my question is How may objects are eligible for garbage collection at line no: 9 (// do something)?

    so my question is How may objects are eligible for
    garbage collection at line no: 9 (// do something)?It's impossible to answer that question since we don't know how MyObj is implemented.
    Kaj

  • THREAD,  OBJECTS,  FOR LOOP

    HI FORM
    I have a method which does some heavy duty mathametical validation and this
    method accepts I/p args from a String[6] for ' n' times avaliable via a for loop .
    1) How to assign this method to run in a threads in parallel ,so the validation is
    avaliable at a same instance .
    Please Do advise me with some code.
    Thx in advance

    I can give more Clarification to this if needed.I think I understand what you're trying to do. Sort of. Enough to suggest how you should do things at least :P
    I'm not entirely sure really that threads are the best way to do this, but I also don't know what I/p stuff is :P
    But if you do go with the threads still, here's how I'd do it.
    for(int row=0; row < rows; row++){
        for (int col=0; col < col; col++) {
            /*this assumes that the textBoxes came from an array,  of the fashion TextBox[rows][cols] which I doubt                 they would.*/
            String text = textBox[row][col].getText()
            Whatever whatever = new Whatever(text);
            Thread t = new Thread(whatever);
            Thread.start();
    }public class Whatever implements Runnable {
    protected String text;
    /** Creates a new instance of Whatever. */
    public Whatever(String text) throws Exception{           
    this.text= text;
    //Whatever this whatever does.
    public void run() {     
    If you want to get the text as well in your whatever, you could pass it enough information to find it.
    As for what you replace my imaginary TextBox array with? I haven't done much with JSPs, and it was quite awhile ago so my memory might be a little fuzzy, but I think you get a Map with key value pairs. In which case you'd do something like
    for (String key: map.keySet()){
        String value=map.getValue(key);
        Whatever= new Whatever(text);
        Thread t = new Thread(whatever);
        Thread.start();
    }Does that help?

  • How to terminate or exit a for loop when the user clicks on stop button

    Actually my problem is to stop a loop when i click on stop button.
    example:i have two buttons 'start' and 'stop'
    in start buttom i wrote a for loop as
    dim i as integer
    For i=1 To 100000
    print i
    Next
    when i click on start buuton it prints 'i' value up tp 100000.
    my question is when i click on 'Stop' button the for loop has to terminate or Exit from the  loop and should stops the execution.
    Is it possible to termianate or Exit the 'for loop'
    PS.Shakeer Hussain
    Hyderabad

    I am unable to stop the loop and application not at all allowing to Press the Stop button.
    It seems like Hung, any advise ?
    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
            btnStop.Enabled = True
            btnSelectFile.Enabled = False
            btnStart.Enabled = False
            btnStop.Focus()
            Dim strFileName As String = txtFileName.Text.ToString
            Dim strLineText As String
            If System.IO.File.Exists(strFileName) = True Then
                Dim objReader As New System.IO.StreamReader(strFileName)
                While objReader.Peek() <> -1 And stopclick = False
                    strLineText = objReader.ReadLine()
                    MsgBox(strLineText, MsgBoxStyle.Information)
                    Application.DoEvents()
                    Thread.Sleep(My.Settings("strDelay") * 1000)
                    'System.Diagnostics.Process.Start(My.Settings("strFireFoxLocation"), strLineText)
                End While
            End If
        End Sub
        Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
            stopclick = True
            btnSelectFile.Enabled = True
            btnStart.Enabled = True
            btnStop.Enabled = False
        End Sub
    Raman Katwal
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How do I use For loop to check each node and import them to a new document?

    In my function I would like to use a For loop to get all the statutes (xml) inside the object
    objXmlBcaResponseDoc. In my case there are 2 statutes. I would like the output to look like the one I have posted here below. I am not sure how to do the For loop. The commented For loop is from another function but it is not working inside
    this function.
    The output is added into the **objXmlResponseMessageDoc** object and should look like this with 2 statutes (ns1:Statute) and a totalCount=2
    <BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
    <StatutesXml>
    <Statutes runType="Request" runDateTime="2015-03-17T10:23:04" totalCount="2">
    <ns1:Statute xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
    <Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    </Statutes>
    </StatutesXml>
    </BasicSearchQueryResponse>
    My xml doc is found inside objXmlBcaResponseDoc Here is xml inside
    objXmlBcaResponseDoc object
    <BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
    <ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    </BasicSearchQueryResponse>
    Here is my function
    Function GetStatutesByChapter(ByVal aobjXmlGetStatuteRequestNode As XmlNode, ByVal aobjXMLNameSpaceManager As XmlNamespaceManager, ByVal aobjBroker As ServiceCatalog.Library.v4.Broker) As XmlDocument
    Dim objXmlRequestMessageDoc As XmlDocument
    Dim objXmlResponseMessageDoc As XmlDocument
    Dim intCount As Integer
    aobjBroker.PostMessageWarehouseInformationalMessage("Chapter found.", 1)
    objXmlResponseMessageDoc = New XmlDocument
    'Add the first element into the document GetStatuteByChapter with its namespace
    objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("BasicSearchQueryResponse", "http://crimnet.state.mn.us/mnjustice/statute/service/4.0"))
    'Build the initial response document
    objXmlResponseMessageDoc = New XmlDocument
    'Add the first element into the document GetStatutesResponse with its namespace
    objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("GetStatutesResponse", "http://www.courts.state.mn.us/StatuteService/1.0"))
    'Add a child node to the GetStatutesResponse node
    objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("StatutesXml", "http://www.courts.state.mn.us/StatuteService/1.0"))
    objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("Statutes", "http://www.courts.state.mn.us/StatuteService/1.0"))
    'Convert the node Statutes into an element and set the runType attribute (runType="Request") by adding it's value Request
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runType", "Request")
    'Convert the node Statutes into an element and set the attribute (runDateTime="2015-03-05T10:29:40") by adding it
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runDateTime", Format(Now, "yyyy-MM-ddTHH:mm:ss"))
    'Create the BCA request message
    objXmlRequestMessageDoc = New XmlDocument
    objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns1:BasicSearchCriteria", aobjXMLNameSpaceManager.LookupNamespace("ns1")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Chapter", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Section", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Subdivision", aobjXMLNameSpaceManager.LookupNamespace("st")))
    'Uncomment last working section below
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Chapter", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Chapter", aobjXMLNameSpaceManager).InnerText
    'check if there is a section and or subdivision if it is there then set the value
    If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager) Is Nothing) Then
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Section", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText
    End If
    If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager) Is Nothing) Then
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Subdivision", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager).InnerText
    End If
    'check if there is a section and or subdivision if it is there then set the value
    aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
    'Call the BCA service
    intCount = 0
    'This is where I want to use a For loop to check for the statutes found using the Chapter
    'Loop through each Id
    'For Each objXmlStatuteIdNode In aobjXmlGetStatuteRequestNode.SelectNodes("ss:Statute/ss:StatuteId/ss:Id[string-length(.)>0]", aobjXMLNameSpaceManager)
    'Create the BCA request message
    'objXmlRequestMessageDoc = New XmlDocument
    'objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:SingleStatuteRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    'objXmlRequestMessageDoc.SelectSingleNode("ns:SingleStatuteRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns:statuteId", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    'objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns:statuteId", aobjXMLNameSpaceManager).InnerText = objXmlStatuteIdNode.InnerText aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
    'intCount = intCount + 1
    'objXmlBcaResponseDoc = New XmlDocument
    'File name is BCASearchQueryResponse.xml
    'objXmlBcaResponseDoc.Load("\\j00000swebint\mscapps\deve\appfiles\temp\BCASearchQueryResponse.xml")
    'objXmlResponseMessageDoc.DocumentElement.SelectSingleNode("ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.ImportNode(objXmlBcaResponseDoc.DocumentElement.SelectSingleNode("ns1:Statute", aobjXMLNameSpaceManager), True))
    'Next
    'Count how many Statute nodes found
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:BasicSearchQueryResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("totalCount", CStr(intCount))
    Return objXmlResponseMessageDoc
    End Function

    What is XPath and what does it do that you're impressed with?
    Yes, I see your link, but give me the abbreviated elevator speech on what it is please. It has me curious.
    http://searchsoa.techtarget.com/definition/XPath
    http://www.techrepublic.com/article/easily-navigate-xml-with-vbnet-and-xpath/
    http://www.techrepublic.com/article/using-xpath-string-functions-in-xslt-templates/
    The way that all this is being used by me now on a project is the HTML controls on the screen are built by XML not only about what the controls are and their attributes,   but the data from from the database is XML too with both going through transfermations
    vis XSLT as the HTML controls are built dynamically by XML data for the controls and the XML database data with decision being made in the transfermation on the fly.
    There are many usages with Xpath not just this one I am talking about with Xpath. You can do the same kind of thing with XAML and WPF forms as they are dynamically built. But it goes well beyond what I am talking about and the usage of Xpath. Xpath 3.0
    is the latest version. 
    http://www.balisage.net/Proceedings/vol10/html/Novatchev01/BalisageVol10-Novatchev01.html
    Thanks - I'll look into that at some point.
    Still lost in code, just at a little higher level.

  • Passing an array in a for loop to a procedure

    I am trying to pass an array in a cursor for loop to a procedure which performs a table insert using the array's contents. Somehow I am missing something, or it is not possible. The compile error states: PLS-00306: wrong number or types in call to 'insert_address' I checked to be sure I am creating the arrays in both cases from similar data objects. Both address and work_address_table contain the same 4 columns with the same data types.
    create or replace package work_address as
    FUNCTION populate_address return boolean;
    procedure insert_address(in_address IN work_address_table%ROWTYPE);
    end work_address;
    create or replace package body work_address as
    function populate_address return boolean is
    cursor c1 is
    select 'H' as header,
    street1 as street
    city as city,
    NULL as state
    from address
    where city = 'HANOVER';
    TYPE addressT IS TABLE OF c1%ROWTYPE INDEX BY BINARY_INTEGER;
    rec1 addressT;
    BEGIN
    OPEN c1;
    FETCH c1 BULK COLLECT INTO rec1 LIMIT 500;
    FOR i IN 1..rec1.count LOOP
    rec1(i).state := 'US'
    insert_address(rec1(i));
    exit when c1%notfound;
    END LOOP;
    CLOSE c1;
    return TRUE;
    END populate_address;
    PROCEDURE insert_address(in_address IN work_address_table%ROWTYPE) IS
    BEGIN
    INSERT INTO work_address_table
    VALUES (in_address.header,
    in_address.street,
    in_address.city,
    in_address.state);
    COMMIT;
    END insert_address;
    END work address;
    /

    Both address and work_address_table contain the same 4 columns with the same data types.Are you 100% sure about this?
    SQL> declare
      cursor c1
      is
        select 1 deptno, dummy dname, 'Loc' location from dual;
      type addresst is table of c1%rowtype
        index by binary_integer;
      rec1   addresst;
      procedure p (d dept%rowtype)
      as
      begin
        dbms_output.put_line(d.dname);
      end p;
    begin
      rec1 (1).dname := 'z';
      p (rec1 (1));
    end;
    z
    PL/SQL procedure successfully completed.but changing just the first column of the cursor:
    SQL> declare
      cursor c1
      is
        select 'xy' deptno, dummy dname, 'Loc' location from dual;
      type addresst is table of c1%rowtype
        index by binary_integer;
      rec1   addresst;
      procedure p (d dept%rowtype)
      as
      begin
        dbms_output.put_line(d.dname);
      end p;
    begin
      rec1 (1).dname := 'z';
      p (rec1 (1));
    end;
    Error at line 3
    ORA-06550: line 20, column 3:
    PLS-00306: wrong number or types of arguments in call to 'P'
    ORA-06550: line 20, column 3:
    PL/SQL: Statement ignored

  • Need help in creating for loop

    Hi,
    I want to create two different Xquery transformation by checking attribute value in the input xml.
    <n:DIAMessage xsi:schemaLocation="http://pearson.com/DIA C:/shashi/rewrite/DIA/DIA_Schemas/DIA_new.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n="http://pearson.com/DIA">
    <n:Customer>
    <n:Account sourceClassName="Account" sourceInstanceID="01560900" sourceSystem="MDR">
    <n:hasAccountRelation sourceClassName="AccountRelation" sourceInstanceID="01560900" sourceSystem="MDR">
    <n:hasAccountPerson name="BRIAN C STRICKLAND" sourceClassName="Person" sourceInstanceID="01560900|$|00114" sourceSystem="MDR"/>
    </n:hasAccountRelation>
    </n:Account>
    <n:Account sourceClassName="Account" sourceInstanceID="01560900" sourceSystem="MDR">
    <n:hasAccountRelation sourceClassName="AccountRelation" sourceInstanceID="01560900" sourceSystem="MDR">
    <n:hasAccountPerson name="BRIAN C STRICKLAND" sourceClassName="Person" sourceInstanceID="01560900|$|00114" sourceSystem="MDR"/>
    </n:hasAccountRelation>
    </n:Account>
    <n:Person name="BRIAN C STRICKLAND" sourceClassName="Person" sourceInstanceID="01560900|$|00114" sourceSystem="MDR">
    <n:hasIdentifier sourceClassName="Identifier" sourceInstanceID="01560900|$|00114" sourceSystem="MDR">
    <n:IDType>GENDER</n:IDType>
    <n:IDTypeName>GENDER</n:IDTypeName>
    <n:IDValue>M</n:IDValue>
    </n:hasIdentifier>
    </n:Person>
    <n:Person name="BRIAN C STRICKLAND" sourceClassName="Person" sourceInstanceID="01560900|$|00114" sourceSystem="MDR">
    <n:hasIdentifier sourceClassName="Identifier" sourceInstanceID="01560900|$|00114" sourceSystem="MDR">
    <n:IDType>GENDER</n:IDType>
    <n:IDTypeName>GENDER</n:IDTypeName>
    <n:IDValue>M</n:IDValue>
    </n:hasIdentifier>
    </n:Person>
    </n:Customer>
    </n:DIAMessage>
    From the above Message i need to create two transformation by checking
    if (DIAMessage/Customer/Account/@sourceClassName="Account")
    then call {
    Xquery1
    if(DIAMessage/Customer/Person/@sourceClassName="Person")
    then call{
    Xquery2
    Constraint here is Account and Person block occurence will be many times.As they are in same hierarchy how to create a for loop concept here?
    Please anyone can help me on this?

    Hi,
    Create a numeric variable to act as While loop counter and assign value of 1. Create a boolean variable to act as a flag to exit loop and assign value of true.
    Create a while object with a condition that while flag variable is true loop.
    Then you can create a switch with a case for each of your scenarios, referencing the xth record (defined by loop counter variable) in xml using ora:getElement
    When the count of required elements in input xml is less than your loop variable, assign the variable to exit loop as false...otherwise increment counter by one to loop to next record.
    Hope this helps.

  • Nested for loop in the collections

    Hi Experts,
    collection1
    ============
    SELECT o.object_id
          BULK COLLECT INTO l_obj_info
            FROM (SELECT     n.node_id, n.object_id
                        FROM nodes n
                  START WITH n.node_id = 100
                  CONNECT BY PRIOR n.node_id = n.parent_node_id) n
                 INNER JOIN
                 objects o ON n.object_id = o.object_id
           WHERE o.object_type_id = 285;
    collection2
    ============
    SELECT *
          BULK COLLECT INTO l_tab
            FROM ((SELECT     REGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL)
                         FROM DUAL
                   CONNECT BY REGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL) IS NOT NULL));
       END;
    collection3
    ============
    SELECT o.object_id
                   BULK COLLECT INTO l_fin_tab
                     FROM objects o JOIN ATTRIBUTES att
                          ON o.object_id = att.object_id
                    WHERE o.object_id = collection1.object_id
                      --AND att.VALUE = collection2.val;
    Please tell me how to implement for loop in the collection3 to get the values from collection1 and collection2.
    i have tried in the below way
    CREATE OR REPLACE TYPE LIST_OF_ATTRIBUTES_TYPE AS TABLE OF varchar2(4000);
    CREATE OR REPLACE TYPE LIST_OF_OBJECT_IDS_TYPE AS TABLE OF number(9);
    CREATE OR REPLACE FUNCTION f_get_objects_by_type_id (
       i_object_type_id   IN   NUMBER,
       i_l_text           IN   VARCHAR2,
       i_scope_node_id         NUMBER
       RETURN list_of_object_ids_type
    AS
       CURSOR objs_info
       IS
          SELECT o.object_id
            FROM (SELECT     n.node_id, n.object_id
                        FROM nodes n
                  START WITH n.node_id = i_scope_node_id
                  CONNECT BY PRIOR n.node_id = n.parent_node_id) n
                 INNER JOIN
                 objects o ON n.object_id = o.object_id
           WHERE o.object_type_id = i_object_type_id;
       l_tab       list_of_attributes_type := list_of_attributes_type ();
       --l_obj_info   list_of_object_ids_type := list_of_object_ids_type ();
       l_fin_tab   list_of_object_ids_type := list_of_object_ids_type ();
    BEGIN
       BEGIN
          SELECT *
          BULK COLLECT INTO l_tab
            FROM ((SELECT     trREGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL)
                         FROM DUAL
                   CONNECT BY REGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL) IS NOT NULL));
       END;
       IF l_tab.COUNT > 0
       THEN
          FOR i IN objs_info
          LOOP
             FOR j IN l_tab.FIRST .. l_tab.LAST
             LOOP
                SELECT o.object_id
                BULK COLLECT INTO l_fin_tab
                  FROM objects o JOIN ATTRIBUTES att ON o.object_id =
                                                                     att.object_id
                 WHERE
                                att.VALUE = l_tab (j) and o.object_id =objs_info(i);
             END LOOP;
          END LOOP;
       END IF;
       RETURN l_fin_tab;
    END f_get_objects_by_type_id;

    Why are you wanting to do this?
    It looks like you are trying to implement SQL joins in PL code.  Not only is that using up expensive PGA memory by storing the data in collections, but doing such retrieval of data to try and join it in PL loops, is never going to be as fast as just joining the SQL queries using SQL itself.
    Post some example data and your database version, with an example of what the output should look like from that example data.
    Re: 2. How do I ask a question on the forums?

  • For Loop in execDialog Description

    Hi all,
    I am using the Javascript execDialog function to create a dynamic popup to get some information from the user.  I have an array defined before the dialog and I need to be able to create a row that contains a checkbox and text area for each item in the array.  I'm not sure how I would/if I can use a for loop to do this.  I placed a For Loop around the entire thing but, of course, I end up getting one dialog box per array item which is not what I want.  I want a total of one dialog box with a variable number of rows.  Here's my code currently.  The area in red is what I need to perform the loop on and have it repeat for each element in my other array.  Please help - this is urgent!
    var fundsDialog = {
    description: {
         name: "Verify Current Info",
         elements:
                   type: "cluster",
                   align_children: "align_left",
                   elements:
                             item_id:"main_text1",
                             type: "static_text",
                             name: "You indicated the following...",
                             bold: true,
                             font: "dialog",
                             char_width: 30,
                             height: 20,
                             item_id:"main_text2",
                             type: "static_text",
                             name: "Name goes here",
                             bold: true,
                             font: "dialog",
                             char_width: 30,
                             height: 20,
                             item_id:"main_text3",
                             type: "static_text",
                             name: "Please confirm the below items exist and uncheck any that don't apply.",
                             bold: true,
                             font: "dialog",
                             char_width: 30,
                             height: 20,
                             type: "view",
                             align_children: "align_row",
                             elements:
                                       item_id:"box1",
                                       type: "check_box",
                                       //char_width: 30,
                                       height: 15,
                                       multiline: true,
                                       item_id:"text1",
                                       type: "static_text",
                                       name: itemToShow,
                                       font: "dialog",
                                       char_width: 30,
                                       height: 100,
                             type: "ok"

    Hi,
    You can pass in an array of dialog elements, so if you can build that up an array before the execDialog object.  Something like;
    var o1 = [];
    o1.push({
                item_id: "box1",
                type: "check_box",
                //char_width: 30,
                height: 15,
                multiline: true,
                item_id: "text1",
                type: "static_text",
                name: "Item 1",
                font: "dialog",
                char_width: 30,
                height: 100,
    o1.push({
                item_id: "box2",
                type: "check_box",
                //char_width: 30,
                height: 15,
                multiline: true,
                item_id: "text2",
                type: "static_text",
                name: "Item 2",
                font: "dialog",
                char_width: 30,
                height: 100,
    var fundsDialog = {
    description: {
         name: "Verify Current Info",
         elements:
                   type: "cluster",
                   align_children: "align_left",
                   elements:
                             item_id:"main_text1",
                             type: "static_text",
                             name: "You indicated the following...",
                             bold: true,
                             font: "dialog",
                             char_width: 30,
                             height: 20,
                             item_id:"main_text2",
                             type: "static_text",
                             name: "Name goes here",
                             bold: true,
                             font: "dialog",
                             char_width: 30,
                             height: 20,
                             item_id:"main_text3",
                             type: "static_text",
                             name: "Please confirm the below items exist and uncheck any that don't apply.",
                             bold: true,
                             font: "dialog",
                             char_width: 30,
                             height: 20,
                             type: "view",
                             align_children: "align_row",
                             elements: o1
                             type: "ok"
    Does that help?
    Bruce

  • How do I set a variable within a 'for' loop grid array

    I'm afraid I'm stuck again!
    The next stage in the animation that I'm working on,  is to set up a boolean, 'drilled = false', so that all instances of the attachMovie ('openCircle') have a boolean 'drilled = false' associated with them. Then when someone clicks on one of the instances of the attachMovie ('openCircle'), the boolean becomes 'drilled = true', but only for that instance that has been clicked.
    What I've done is to set the variable (boolean)(highlighted in bold below) within both 'for' loops within the grid array, but it just returns an undefined value. Do I need to setup a separate array? (see code below):-
    //set up grid for solid array
    var spacing:Number = 5.75;
    var cols:Number = 20; // number of columns in grid
    var rows:Number = 20; // number of rows in grid
    var leftMargin:Number = 154;
    var topMargin:Number = 169;
    var depth:Number = 100; // starting point for depth
    var drilled:Boolean;
    for (i=1; i<=rows; i++) {                                                                                                         
    for (j=1; j<=cols; j++) {                                                                                                                              
              drilled[rows,cols]=false;
                        trace(drilled);
              current = attachMovie("openCircle_mc", "openCircle_mc"+i+"_"+j, depth++);
              current._x = leftMargin + ((i-1) * (spacing + current._width));
              current._y = topMargin + ((j-1) * (spacing + current._height));
              current.row=i;
              current.col=j;
    //          current.oil = Math.floor(Math.random()*1.1);  // about 1/10 objects have oil=1, 9/10 oil=0
              //open circle initially invisible, visible on rollOver
              current._alpha = 0;
              current.onRelease=function(){
                        trace(this.row+" "+this.col);
       current.drilled = true;
              current.onRollOver = function() {
                                     this._alpha = 100;
              current.onRollOut = function() {
                                     this._alpha = 0;
    I'd be grateful for any help. Thanks.

    I'm sorry for asking this question again, but I really need to have the 'drilled' variable to be available at all times outside the openCircle_mc, so if I can set up the 'drilled' variable as an array that would be good. Below is the code that isn't working:
    /*  set all values of 'drilled' to false  */
    var col:Number = 20; // number of columns in grid
    var row:Number = 20; // number of rows in grid
    for (g=1; g<=row; g++) {
              for (h=1; h<=col; h++){
                          drilled[g,h] = false;
    Very many thanks

  • For loop vs Iterator

    I'm writing an application in which performance will be quite important and was looking into my collection classes. I recently saw the move towards using Iterator instead of for loops, while loops to retrieve objects from a List. I wanted to test to see which performed better and I saw that for about 1,000,000 Integer objects, an Iterator was 100ms slower in time in both Vector and ArrayList than a for loop using gets.
    1) Is the main cost the creation of the Iterator object?
    2) If I'm not worried about manipulation of my List while I'm retrieving objects and I will always be using a List in which I can always pull indexes (instead of say using HashSet)... is there any reason to use Iterator instead of a for loop?
    -- I read the recent tech tip on this and was just wondering if anyone had any other ideas of why to choose Iterator over for/while loops.
    Thanks.

    The purpose of Iterator
    The purpose of the Iterator pattern is to handle the traversal of a collection of objects.
    The advantages of Iterator has over other straightforward ways
    The direct access methods provided by some collection classes may not be as efficient or simple as using iterator pattern. And because the iterator keeps its own state, multiple traversals can be performed on a single collection simultaneously.
    An iterator hides the internal representation of the collection from the classes that need to access the contents of these collections.
    An Iterator pattern provides a consistent and sometimes efficient way to access the objects or values in some collections.
    What problems can arise if collection is changing?
    While using iterator, the changes of a collection such as that adding new elements or deleting old elements can result in inconsistency of the data, for example some objects may be missed or accessed more than once.
    How can they be avoided?
    A simple way is to make a copy of the collection and work on this copy but this can be very costly in terms of memory and time.
    Design a method that notifies the iterator whenever the collection is changed, and as soon as the change happens the iterator class throws an exception or restart whichever appropriate.
    A better way would be implements methods that monitor the changes and adjust the iterator and the results so they are consistent to the contents of the collection at any time.
    There are no general solutions to this problem and under different circumstance the proper solutions vary, however it is a good practice to taking possible changes of the source collections into account while designing the iterator, and it may be worth to let the user aware of the occurrence of any changes.

  • Config data refnums invalidate​d by for loop

    I have found the following problem with LabVIEW 7.0. This only occurs when running the application as built with the application builder and does not appear to be a problem in the development environment.
    Given an open refnum for a config file one can loop through several read key operations while passing the data and the refnum to outputs on the for loop. If you disable indexing on the refnum output of the for loop you should get a usable refnum out. What happens instead when you try to close the refnum is an error indicating that the refnum is invalid. If you simply route the refnum around the loop avoiding the for loop output altogether this doesn't happen. It appears that somehow, going through the indexing output of the f
    or loop invalidates or changes the refnum when in a built application using the runtime.
    If anyone can reproduce this or prove me wrong it would be helpful. This bug cost me days of chasing down why my "major app" would only work when in development but fail when built. The lack of debug capability in a built app of course leant to the effort that it took to track this down.
    Thanks,

    Hello, i'm french so scuse for my writting...
    I don't find where put this question so i writte here.
    I want to do a soft who's objective is to writte config data (open config data + write key + close..).
    you can find it in the join piece.
    this soft run correctly but when i do an exe with the application builder, when i try to run the exe, that saying me error 7 about the Nex file in Open config data...
    How can i solve this problem???
    Tanks for all....
    Attachments:
    chconfexe.vi ‏32 KB

Maybe you are looking for