Multidimensional array with start-job

Hi! I'm trying to improve a script that will read in a CSV file to an array, divide it up to 4 chunks. So I will have 4 arrays and inside each array I have properties for computername, ip addresses and so forth. ($arrComputers[0][56].ComputerName)
So what I want to do is:
# Send 1 chunk array at a time to a Start-Job. 1 chunk consits of 100 computers.
# Read each object,  $arrComputers[index][row].Status ,
# If Status says "OK" don't continue to check, Else continue to fetch info and write back to
$arrComputers[index][row].<property>
So for I've only gotten to 
$Script={
Param($comp)
<Do Check, Read and Write for each computer here>
for($i=0;$i -lt 4;$i++)
$compCollection[$i] | Start-Job -ScriptBlock $Script -ArgumentList ($compCollection[$i]
I hope I have been clear what I'm trying to do. This is my first time trying it, so wouldn't surprise me if you guys got a better idea how to achieve what I want or what I've done wrong. I'm all ears and also to pointers to guides and such where I can read
up more about advanced powershelling. 

$computerlist | 
     ForEach-Object{
         Start-Job -Script $script
-ArgumentList $_
but
$script={Param($computer)
if($computer.Status -eq "OK"){
#Do Nothing
else
#Do Something
$computer.Status = #Assign new value
#write back the same chunk it derived from.
for($i=0;$i -lt 4;i++){
$computerlist[$i] |
ForEach-Object{
Start-Job -Script $script -ArgumentList $_

Similar Messages

  • Multidimensional arrays with enhanced for statement

    hello, do you know if it is possible to use enhanced for loop with multidimensional arrays, and if yes, then how?
    for example:
    int[][] arr = {{1,2},{3,4}};
    for(int i[][] : arr){
        doSomethingWith(i[][]);
    }

    The syntax is nice'n'easy:
    void f(int[][] m) {
        for(int[] row : m) {
            for(int x : row) {
    }

  • Any way to Initialize Java Array to start with 1

    Hi Friends,
    Is there anyway to initialize the java array with starting with 1 instead of normal 0.
    Thanks and Regards.
    JG

    JamesGeorge wrote:
    Hi Jacob,
    Thanks for you time..
    Coding like 1 - n will make everything uneasy, I find in other languages like vbscript,lotusscript it can be done..so just a thought to check in Java too..
    Is there any valid reason for Java/Sun guys to start the arrays,vectors and other collections with 0
    Thanks
    JJShort answer: Java is a C-based language, and C arrays are zero-based so the rest are also zero-based for consistency.
    Long answer: Arrays are implemented as contiguous areas of memory starting from a certain memory address, and loading from a zero-based array implies one less CPU instruction than loading from a one-based array.
    Zero-based:
    - LOAD A, ArrayAddress
    - LOAD B, Index
    - MUL B, ElementSize
    - ADD A, B
    - LOAD (A)
    One-based:
    - LOAD A, ArrayAddress
    - LOAD B, Index
    - ADD B, -1
    - MUL B, ElementSize
    - ADD A, B
    - LOAD (A)

  • Multi-dimensional array with dynamic size - how to?

    Hi
    I have a CONSTANT number of buckets. Each of them has to take a VARIOUS number of data series. The data series have one VARIOUS length per bucket. I'd like to index the buckets like an array to loop over them.
    So basically I need something like a multidimensional array with constant first dimension (bucket index), but dynamic second (data series index within bucket) and third (data point index within data series) dimension. What's the best way to do so?
    I should also remark that data series can get really big.
    Thanks in advance and best regards,
    Michael

    Hi Michael,
    the usual way is to use an array of cluster.
    Put your "2nd" and "3rd" data into a cluster and then make an 1D array of that cluster...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • PowerShell - Start-Job - Synchronised Array list

    Hi all,
    I am trying to write a script using start-job against a list of machines. The script is to query a target machine event log using get-winevent cmdlet. I supply the whole code that queries the eventlog in a scriptblock. In order to capture the output (one
    psobject for each of the scriptblock jobs) I am trying to use a synchronised arraylist. I do not know the full details of how to use the synchronised arraylist but I have put together the below script (by referring to some of the online articles). But the
    script does not work as intended. The individual scriptblocks do not seem to be referring to the global arraylist variable while appending the results.
    Would any of you be able to shed any light on it?
    Please note, the script without the PowerShell Jobs works fine(that is linear execution which is really time-consuming). Also, even with using psJobs, the script works when I try to dump the result of each job into a csv from within the job itself. But I
    want to avoid this situation because due to the asynchronous execution there might be contention for the csv by more than one jobs at the same time. Hence I want to use the synchronised array list.
    $InputCSV = "$(Split-Path $SCRIPT:MyInvocation.MyCommand.Path -parent)\backupexec.csv"
    $OutputCSV = "$(Split-Path $SCRIPT:MyInvocation.MyCommand.Path -parent)\Reports\BackupExec_Output_$(Get-Date -format "ddMMyyyy")_$((Get-Date).DayOfWeek).csv"
    $OutputArray = [System.Collections.ArrayList]::Synchronized((New-Object System.Collections.ArrayList))
    $counter=1
    $jobs=@{};
    $jobcounter=0;
    Import-CSV $InputCSV | ForEach {
    $Comp_Name=$_.ServerName;
    $Counter+=1;
    $Scriptblock={
    Try {
    $IsthereAnyResult= @()
    $IsthereAnyResult= Get-WinEvent -ComputerName $Using:Comp_Name -ErrorAction SilentlyContinue -FilterHashTable @{LogName='application';ProviderName='Backup Exec';ID=57755; StartTime=(Get-Date).AddDays(-1)}
    $props = @{
    "Server Name" = ($event.MachineName -split '\.')[0];
    "Event ID" = $event.ID;
    "Time Logged" = $event.TimeCreated;
    "Backup Result" = Switch ($event.ID) { '57755' {"Success - Skipped"}
    '34113' {"Failed"}
    '34112' {"Success"} };
    "Message" = $event.Properties[0].value -replace '\n' -replace '\r';
    $OutputArray += New-Object PSObject -Property $props
    } #end try get-winevent
    Catch { } #end Catch
    } #end scriptblock
    $jobs[$jobcounter]= Start-job -name $("Job_$jobcounter") -ScriptBlock $Scriptblock
    $jobcounter+=1;
    While((Get-Job -State 'Running').Count -ge 10) {
    Start-Sleep -Milliseconds 10
    } # end main foreach
    Get-Job | Wait-Job
    $OutputArray | Select-Object "Server Name","Event ID","Time Logged","Backup Result","Message" | Export-CSV -force -Path $OutputCSV -NoTypeInformation -Append

    How about this?
    I use wmi win32_ntlogevent which i prefer ..  Timeservice is just for example ...
    Change the scriptblock to your needs and report the result :]
    Param ([int]$BatchSize=2)
    #list of servers
    [array]$source = (get-adcomputer -filter {name -like "server*"}) |select -expandproperty dnshostname
    $blok = {
    get-wmiobject Win32_NTLogEvent -Filter "(Logfile='System') and (SourceName = 'Microsoft-Windows-Time-Service')" |select -first 10 |select __server,@{n="EventCode";e={switch($_.EventCode){37{"37 - Receiving"}35{"35 - Synchronizing"}129{"129 - NTP Fail"}default{"Other EventCode"}}}},@{n="Date";e={$_.ConvertToDateTime($_.TimeGenerated)}},message
    $elapsedTime = [system.diagnostics.stopwatch]::StartNew()
    $result = @()
    $itemCount = 0
    ## checking running jobs
    if (get-job|? {$_.name -like "Script*"}){
    write-host "ERROR: There are pending background jobs in this session:" -back red -fore white
    get-job |? {$_.name -like "Script*"} | out-host
    write-host "REQUIRED ACTION: Remove the jobs and restart this script" -back black -fore yellow
    $yn = read-host "Automatically remove jobs now?"
    if ($yn -eq "y"){
    get-job|? {$_.name -like "Script*"}|% {remove-job $_}
    write-host "jobs have been removed; please restart the script" -back black -fore green
    exit
    $i = 0
    $itemCount = $source.count
    Write-Host "Script will run against $itemcount servers!"
    ## Script start time mark
    write-host "Script started at $(get-date -uFormat "%Y/%m/%d %H:%M:%S")".padright(60) -back darkgreen -fore white
    write-host " (contains $itemCount unique entries)" -back black -fore green
    $activeJobCount = 0
    $totalJobCount = 0
    write-host "Submitting background jobs..." -back black -fore yellow
    for ($i=0; $i -lt $itemCount;$i += $batchSize){
    $activeJobCount += 1; $totalJobCount += 1; $HostList = @()
    $HostList += $source |select -skip $i -first $batchsize
    $j = invoke-command -computername $Hostlist -scriptblock $blok -asjob
    $j.name = "Script`:$totalJobCount`:$($i+1)`:$($getHostList.count)"
    write-host "+" -back black -fore cyan -nonewline
    write-host "`n$totaljobCount jobs submitted, checking for completed jobs..." -back black -fore yellow
    while (get-job |? {$_.name -like "Script*"}){
    foreach ($j in get-job | ? {$_.name -like "Script*"}){
    $temp = @()
    if ($j.state -eq "completed"){
    $temp = @()
    $temp += receive-job $j
    $result += $temp
    remove-job $j
    $ActiveJobCount -= 1
    write-host "-" -back black -fore cyan -nonewline
    elseif ($j.state -eq "failed"){
    $temp = $j.name.split(":")
    if ($temp[1] -eq "R"){
    $temp = @()
    $temp += receive-job $j
    $result += $temp
    remove-job $j
    $ActiveJobCount -= 1
    write-host "-" -back black -fore cyan -nonewline
    else{
    write-host "`nFailure detected in job: $($j.name)" -back black -fore red
    $temp = @()
    $temp += receive-job $j
    $result += $temp
    remove-job $j
    $ActiveJobCount -= 1
    if ($result.count -lt $itemCount){
    sleep 3
    write-host " "
    write-host "Script finished at $(get-date -uFormat "%Y/%m/%d %H:%M:%S")".padright(60) -back darkgreen -fore white
    write-host (" Elapsed Time : {0}" -f $($ElapsedTime.Elapsed.ToString())) -back black -fore green
    $result |select __server,eventcode,Date,message |ft -auto
    write-host " Script completed all requested operations at $(get-date -uFormat "%Y/%m/%d %H:%M:%S")".padright(60) -back darkgreen -fore white
    write-host (" Elapsed Time : {0}" -f $($ElapsedTime.Elapsed.ToString())) -back black -fore green

  • Cannot start job with Management Console

    Hi,
    The Management Console displays the status of batch jobs started with DI Designer, but when attempting to run a  batch job via the Management Console nothing happens.
    The execute command displays "Job started successfully", but does nothing.
    Any ideas would be appreciated.
    Thanks in advance.
    Regards,
    Meet

    Hi Meet,
    Do execute the job again from Central Management Console and go to following path
    C:\ProgramData\SAP BusinessObjects\Data Services\log
    Here in the log folder you will find those many number of folders with job server names as there are job servers in your server.
    Go to the respective job server folder(which is used to run your particular job).
    In this folder you can find, all the repository folders associated with that job server.
    Go to the respective repository in which you have the job.
    Here comes the best part.In this repository folder Data services created 6 files for every job execution, which are
    ERROR_DATE_NUMBER(.txt,and .idx)
    MONITOR_DATE_NUMBER(.txt and .idx)
    TRACE_DATE_NUMBER(.txt and .idx)
    Open the trace.txt file which has been created recently.(check date and time after running your job).
    Now this file will tell you whether the job has been executed, started and stopped due to some error or never executed.
    Case1:
    If there's a trace.txt file then job had started
    Case2:
    If it executed successfully then you will find the start and end time stamps in the trace.txt file.
    Case3:
    If there's an error, open the recent error.txt file, you'll find the error log!!
    Hope this will help you. Do update the status of your issue!!
    Regards,
    Mubashir Hussain

  • Synthesis bug with SV packed multidimensional array slices

    I've been using SV packed multidimensional arrays to do things like representing a bus which is many bytes wide, e.g. a 128-bit bus can be declared like this:
    logic [15:0] [7:0] myBus;
    You should be able to write "myBus[15:8]" to get the upper 64 bits (8 bytes) of this 128-bit wide packed value. However, I've found that in some expressions this produces some very buggy behavior. I've reduced it to a simplified example, with comments to show what works and what doesn't.
    `timescale 1ns / 1ps
    module sv_array_select (
    input logic sel,
    input logic [3:0] [1:0] i,
    output logic [3:0] outA,
    output logic [3:0] outB,
    output logic [3:0] outC
    // Works; equivalent to assign outA = {i[1], i[0]};
    assign outA = i[1:0];
    // Works; equivalent to assign outB = {i[3], i[2]};
    assign outB = i[3:2];
    // FAILURE
    // Synthesizes to equivalent of:
    // assign outC[2:1] = sel ? i[2] : i[0];
    // assign outC[3] = 1'bZ;
    // assign outC[0] = 1'bZ;
    assign outC = sel ? i[3:2] : i[1:0];
    endmodule
     I get this result in Vivado 2015.2 and 2013.2, haven't tried other tool versions.

    ,
    Yes, I can see that incorrect logic is getting generated by the tool.
    I will file a CR on this issue and will let you know the CR number.
    Thanks,
    Anusheel
    Search for documents/answer records related to your device and tool before posting query on forums.
    Search related forums and make sure your query is not repeated.
    Please mark the post as an answer "Accept as solution" in case it helps to resolve your query.
    Helpful answer -> Give Kudos
     

  • Unable to start-job with credentials

    I cannot get any jobs to run while using the credential parameter and I'm absolutely sure the credentials are correct. Has anyone had this issue?
    PS C:\Windows\system32> Start-Job -credential $creds -scriptblock {start-sleep 10}
    Id              Name            State      HasMoreData     Location             Command
    1               Job1            Failed     False           localhost            start-sleep 10
    Dan

    Same result with version 3. 
    PS H:\> start-job -name newjob1 -Credential $credential -ScriptBlock {start-sleep 10}
    Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
    8      newjob1         BackgroundJob   Failed        False           localhost            start-sleep 10
    PS H:\> (get-job -name newjob1).ChildJobs[0].JobStateInfo |fl
    State  : Failed
    Reason : System.Management.Automation.Remoting.PSRemotingTransportException: There is an error launching the
             background process. Error reported: The directory name is invalid. ---> System.ComponentModel.Win32Exception:
             The directory name is invalid
                at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
                at System.Management.Automation.Runspaces.PowerShellProcessInstance.Start()
                at System.Management.Automation.Remoting.Client.OutOfProcessClientSessionTransportManager.CreateAsync()
                --- End of inner exception stack trace ---
    Dan

  • Start external application with oracle job

    I'm trying to start external program with oracle job.
    Here is an example (I used SYS as SYSDBA):
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
    job_name => 'my_job',
    job_type => 'executable',
    job_action => 'C:/WINDOWS/system32/cmd.exe',
    enabled => true,
    auto_drop => false );
    END;
    But job STATE comes FAILED.
    How should I do this?
    Result was not better when I used
    BEGIN
    DBMS_SCHEDULER.CREATE_PROGRAM (
    program_name => 'my_prg',
    program_type => 'EXECUTABLE',
    program_action => 'C:/WINDOWS/system32/cmd.exe',
    enabled=>TRUE);
    DBMS_SCHEDULER.CREATE_JOB (
    job_name => 'my_job',
    program_name => 'my_prg',
    enabled => TRUE,
    auto_drop => false );
    END;
    Edited by: user458393 on Feb 16, 2010 1:55 AM

    Take a look at this thread: Running a Windows BAT file using DBMS_SCHEDULER
    C.

  • Working with MultiDimensional arrays

    Hi,
    Just wondering if anyone could help with a problem Im
    having with multi-dimensional arrays in Java:-
    I want to create a multi-dimensional array (e.g. 3 dimensions). I know this can be defined by code such as:-
    int[ ][ ][ ] my_array = new int[10][10][10];
    (would create a 10x10x10)
    My problem is that I want to address the array with indexes that aren't known at compile time, trying to do this causes an error:-
    e.g. my_array[0][0][0] = 1; is ok (i.e. the element at 0,0,0 is set to 1)
    but if the indexes 0,0,0 are replaced by the return value of some function,
    e.g.
    my_index1 = generateIndex(x, y, .... etc);
    my_index2 = generateIndex(a, b, ...etc);
    my_index3 = generateIndex(f,g, .. etc);
    (where generateIndex is some function that returns an integer)
    and the array element set with
    my_array[my_index1][my_index2][my_index3] = 3;
    This generates an error. I know that this problem can be overcome through the use of pointers in C++ but since Java doesn't use pointers, im a bit stuck!
    I have come across a method that overcomes this for a 1D array, using the setInt function of the Array class, e.g.
    Array.setInt(my_1Darray, 0, 1); (would set the first value of my_1Darray to 1);
    (i.e. Array.setInt(array_name, int index, int value);
    But I can't see how this works with multidimensional arrays.
    If anyone could shed any light on this problem, that would be great.
    Thanks,
    Peter

    public class NDArray {
            public static void main(String[] s) {
                    int[][][] _3D = new int[10][10][10];
                    for (int c = 0; c < 1000; c++)
                            _3D[rnd()][rnd()][rnd()]=rnd();
                    for (int i=0; i < 10; i++) {
                      for (int j=0; j < 10; j++) {
                        for (int k=0; k < 10; k++) {
                            System.out.print(_3D[i][j][k]);
                            System.out.print(" ");
                      System.out.println();
                    System.out.println();
            static int rnd() {return (int) (10*Math.random());}
    /* output (example):
    7 0 0 4 9 9 3 0 0 2
    0 1 8 9 6 0 0 0 0 0
    5 3 0 5 0 0 1 0 0 3
    5 6 0 5 0 0 3 0 0 0
    0 0 0 0 4 0 0 5 8 6
    0 9 0 9 0 1 0 2 0 0
    3 3 8 6 0 0 1 0 3 4
    9 6 7 0 0 0 3 6 6 3
    2 0 8 7 0 1 4 0 7 0
    8 0 4 4 3 0 0 5 4 0
    0 0 0 0 3 0 1 0 0 4
    9 0 8 9 1 0 9 0 9 0
    0 8 3 4 1 0 8 0 0 2
    3 0 0 7 3 3 0 5 0 0
    0 0 0 1 4 6 0 0 0 3
    3 5 8 5 8 0 8 2 0 4
    4 0 1 7 0 1 0 4 4 0
    6 0 5 0 0 4 0 8 1 0
    0 0 6 6 2 0 0 4 5 0
    0 6 7 0 4 0 7 5 0 0
    2 4 0 5 0 0 0 2 1 7
    0 6 0 9 0 0 6 1 2 0
    0 5 9 0 1 2 4 0 8 6
    0 0 8 0 0 3 3 8 0 0
    4 7 5 9 0 8 1 0 0 9
    2 0 0 3 0 0 8 3 0 7
    0 6 0 6 0 0 0 0 1 0
    0 9 9 8 4 2 0 0 7 2
    4 0 0 9 0 0 0 1 0 6
    7 0 6 5 2 3 7 8 0 2
    0 0 3 5 0 0 0 0 0 0
    3 0 0 0 0 2 0 0 6 0
    6 0 3 3 6 0 4 0 1 6
    0 0 7 2 0 8 0 0 0 0
    0 0 9 0 6 8 2 1 0 0
    9 0 4 1 3 9 3 2 7 7
    0 3 1 0 3 0 0 9 0 5
    0 0 0 0 6 0 4 8 0 5
    1 8 4 6 7 0 0 4 4 0
    0 4 8 0 0 0 6 0 4 0
    0 9 3 0 0 0 6 0 0 8
    6 8 2 9 6 0 0 7 9 0
    7 1 9 0 0 5 0 2 3 0
    0 0 0 0 9 9 0 7 0 9
    9 8 8 2 9 8 0 5 8 0
    2 3 0 4 0 4 1 0 6 9
    3 3 0 0 0 0 7 6 9 3
    6 2 2 1 0 5 8 3 0 6
    0 6 0 0 0 0 0 0 7 5
    0 6 0 0 0 3 3 0 2 0
    3 6 5 5 8 2 0 9 1 0
    8 0 7 0 9 0 9 0 2 0
    0 2 9 0 0 1 2 4 0 2
    3 1 0 2 0 0 0 0 0 0
    0 5 0 3 8 8 3 0 0 0
    9 0 9 0 5 1 0 9 5 0
    8 0 0 8 8 7 0 3 1 0
    4 0 0 0 1 8 0 9 0 5
    0 0 6 6 0 0 5 2 6 8
    0 4 0 9 0 0 2 0 0 3
    0 5 8 1 7 0 0 4 2 0
    6 5 0 0 2 0 6 8 8 7
    0 0 0 0 3 0 8 4 0 0
    2 3 3 0 0 7 6 8 0 4
    4 1 7 3 8 0 2 3 3 0
    1 5 0 0 4 1 3 7 3 1
    0 0 0 6 0 6 0 0 3 0
    3 7 0 4 5 9 5 5 0 8
    3 8 6 4 0 0 0 1 6 0
    0 0 2 0 2 9 0 0 0 5
    0 5 6 0 5 5 4 0 6 7
    0 2 2 0 9 7 4 2 9 0
    4 0 5 4 8 3 0 0 2 0
    0 0 9 3 3 0 8 8 7 0
    0 7 9 7 0 0 0 7 1 0
    2 0 0 0 5 8 2 0 0 5
    2 4 9 6 6 0 0 0 6 0
    0 6 6 7 0 2 0 0 5 2
    0 9 0 4 8 5 1 0 7 6
    0 0 7 0 4 0 3 8 0 9
    9 4 0 0 0 4 0 0 0 5
    2 0 4 7 7 5 4 0 9 0
    0 0 1 0 5 0 1 0 6 0
    0 6 0 9 0 9 0 4 7 0
    5 9 6 6 2 8 8 4 1 4
    9 7 3 2 7 6 0 2 3 0
    3 1 5 0 8 0 0 0 0 0
    9 0 0 3 0 8 7 0 4 0
    8 6 6 4 0 4 6 4 5 0
    0 0 0 0 0 4 4 0 0 9
    8 8 0 2 0 0 0 1 0 0
    6 2 1 1 9 0 5 1 0 0
    0 9 1 0 6 0 4 0 0 0
    9 4 0 3 0 1 0 7 6 0
    0 9 0 7 8 6 0 5 0 0
    0 8 8 9 0 5 7 0 0 0
    0 4 5 1 6 0 5 2 9 3
    6 0 0 0 0 0 0 9 1 0
    5 9 1 9 2 5 3 0 0 9
    2 9 5 1 7 0 0 0 9 0
    */Seems to work just fine. How is your code different from mine?

  • Start-job with datetime arguments

    Hi,
    It is working (of course), I get all objects which are newer then $timeFrom:
    $timeFrom = "2014-03-25 9:00"
    Get-ChildItem c:\temp | ?{$_.CreationTime -gt $timeFrom}
    But is not working:
    $timeFrom = "2014-03-25 9:00"
    Start-Job -ScriptBlock {Get-ChildItem c:\temp | ?{$_.CreationTime -gt $args[0]}} -ArgumentList @($timeFrom)
    I get all objects, but if I replace -gt to -lt the list will be empty. Teherefore any kind of compare working, but I can't understand how...
    Anybody can help me?

    When you're using variables defined outside of the scriptblock you have to pass them into the scriptblock.  I prefer to keep them all the same just because it's easier to understand for me.  Yours probably would have worked if you'd included the
    param part:
    Start-Job -ScriptBlock {param($args)Get-ChildItem c:\temp | ?{$_.CreationTime -gt $args[0]}} -ArgumentList
    @($timeFrom)
    but I'm not sure whether or not using $args works at all in this context.  It probably does, but without param it definitely wouldn't.
    I hope this post has helped!

  • Need help with starting a simple calculator

    I have this simple calculator I just started on, and I'm having just a few problems. First of all, I don't know how to append text to a textfield. Maybe I would have to create a string buffere or something. Then, when the user clicks one of the buttons, the compiler goes crazy, and nothing is displayed.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Calculator extends JFrame implements ActionListener
         JButton[] btnNums;
         JButton btnBack;
         JButton btnClear;
         JButton btnCalculate;
         String[] strNames;
         JTextField txtDisplay;
         public Calculator()
              Container content = getContentPane();
              setSize(210,250);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              /*  construct a JPanel and the textfield that
               *  will show the inputed values and outputed
               *  results
              JPanel jpDisplay = new JPanel();
              jpDisplay.setLayout(new BorderLayout());
              txtDisplay = new JTextField(15);
              txtDisplay.setHorizontalAlignment(JTextField.RIGHT);
              jpDisplay.add(txtDisplay);
              /*  contstruct a JPanel that will contain a back
               *  button and a clear button.
              JPanel jpRow2 = new JPanel();
              btnBack = new JButton("Backspace");
              btnClear = new JButton("Clear");
              btnClear.addActionListener(this);
              jpRow2.add(btnBack);
              jpRow2.add(btnClear);
              /*  construct a string array with all the names of the
               *  buttons, then in a for loop create the new buttons
               *  and add their name and an actionListener to them.
              String[] strNames = {"7","8", "9","/", "4", "5", "6","*", "1", "2", "3","+", "0", "+/-", ".", "-"};
              btnNums = new JButton[16];
              JPanel jpButtons = new JPanel();
              jpButtons.setLayout(new GridLayout(4,4));
                for (int i = 0; i < 16; i++)
                     btnNums[i] = new JButton(strNames);
                   btnNums[i].addActionListener(this);
                   jpButtons.add(btnNums[i]);
              /* construct the final JPanel and add a
              * calculate button to it.
              JPanel jpLastRow = new JPanel();
              btnCalculate = new JButton("Calculate");
              btnCalculate.addActionListener(this);
              jpLastRow.add(btnCalculate);
              /* set the contentPane and create the layout
              * add the panels to the container
              setContentPane(content);
              setLayout(new FlowLayout());
              setResizable(false);
              content.add(jpDisplay, BorderLayout.NORTH);
              content.add(jpRow2);
              content.add(jpButtons);
              content.add(jpLastRow);
              setTitle("Mini Calculator");
              setVisible(true);
         public void actionPerformed(ActionEvent ae)
              for (int i =0; i < 16; i++)
                   if (ae.getSource() == btnNums[i])
                        txtDisplay.setText(strNames[i]);
         public static void main(String[] args)
              Calculator calc = new Calculator();

    First of all, I don't
    know how to append text to a textfield.
    textField.setText( textField.getText() + TEXT_YOU_WANT_TO_APPEND );
    Then,
    when the user clicks one of the buttons, the compiler
    goes crazy, and nothing is displayed.No, the compiler doesn't go crazy, the compiler has done it's job by then. However, you do get a NullPointerException, and the stacktrace tells you that the problem is on the following line:
    txtDisplay.setText(strNames);
    It turns out that strNames is null. I leave it to you to find out why. ;-)

  • Multidimensional Arrays + Me + OOP = Fear

    node.java
    class node {
         int[][] grid = new int[0][0];
         void detect(){
              System.out.println(grid);
    game.java
    class game {
         public static void main(String args[]) {
              node a = new node();
              a.detect();
    The output of this code is:
    http://img237.imageshack.us/img237/6556/outputxy7.png
    I am trying to create an imaginary grid so I can implement A* algorithm into my game which will later be an applet.
    Why did the output of this come out so weird? I do not understand multidimensional arrays and I struggle to understand object oriented programming.
    I have known Java since Nov 2006, but I have always dodge some of this difficult stuff. I am totally self taught and I have been learning through the Internet and a very old Java 2 book. So please speak "dumb" to me.
    Thank you,
    Andrew.

    Oh, grow up. If you get insulted this easily, you'll be inconsolable when you have to get a real job. I'm so sick of these children who want help but also want their genius to remain unquestioned.
    Anyway my point wasn't that you altered the image, but rather that you were careless in what you presented as data. Some of the stuff on that image couldn't possibly have worked with the code you posted. (In particular "java node" would not have even run. It wouldn't produce any output at all other than an error message.)
    Part of debugging is gathering real, useful, accurate information. And if you want help debugging you have to share real, useful, and accurate information. If you gather output and then change your code, you should at the very least make this clear.

  • Reading characters from a text file into a multidimensional array?

    I have an array, maze[][] that is to be filled with characters from a text file. I've got most of the program worked out (i think) but can't test it because I am reading my file incorrectly. However, I'm running into major headaches with this part of the program.
    The text file looks like this: (It is meant to be a maze, 19 is the size of the maze(assumed to be square). is free space, # is block, s is start, x is finish)
    This didn't paste evenly, but thats not a big deal. Just giving an idea.
    19
    5..................
    And my constructor looks like follows, I've tried zillions of things with the input.hasNext() and hasNextLine() to no avail.
    Code:
    //Scanner to read file
    Scanner input = null;
    try{
    input = new Scanner(fileName);
    }catch(RuntimeException e) {
    System.err.println("Couldn't find the file");
    System.exit(0);
    //Set the size of the maze
    while(input.hasNextInt())
    size = input.nextInt();
    //Set Limits on coordinates
    Coordinates.setLimits(size);
    //Set the maze[][] array equal to this size
    maze = new char[size][size];
    //Fill the Array with maze values
    for(int i = 0; i < maze.length; i++)
    for(int x = 0; x < maze.length; x++)
    if(input.hasNextLine())
    String insert = input.nextLine();
    maze[i][x] = insert.charAt(x);
    Any advice would be loved =D

    Code-tags sometimes cause wonders, I replaced # with *, as the code tags interprets # as comment, which looks odd:
    ******...*.........To your code: Did you test it step by step, to find out about what is read? You could either use a debugger (e.g., if you have an IDE) or system outs to get a clue. First thing to check would be, if the maze size is read correctly. Further, the following loops look odd:for(int i = 0; i < maze.length; i++) {
        for(int x = 0; x < maze.length; x++) {
            if (input.hasNextLine()) {
                String insert = input.nextLine();
                maze[x] = insert.charAt(x);
    }Shouldn't the nextLine test and assignment be in the outer loop? And assignment be to each maze's inner array? Like so:for(int i = 0; i < maze.length; i++) {
        if (input.hasNextLine()) {
            String insert = input.nextLine();
            for(int x = 0; x < insert.size(); x++) {
                maze[i][x] = insert.charAt(x);
    }Otherwise, only one character per line is read and storing a character actually should fail.

  • PowerShell using start job to run multiple code blocks at the same time

    I will be working with many 1000’s of names in a list preforming multiple function on each name for test labs.
    I notice when it is running the functions on each name I am using almost no CPU or memory.  That led me to research can I run multiple threads at once in a PowerShell program. That lead me to articles suggesting start-job would do just want I am looking
    for. 
    As a test I put this together.  It is a simple action as an exercise to see if this is indeed the best approach.  However it appears to me as if it is still only running the actions on one name at a time.
    Is there a way to run multiple blocks of code at once?
    Thanks
    Start-Job {
    $csv1 = (Import-Csv "C:\Copy AD to test Lab\data\Usergroups1.csv").username
    foreach ($name1 in $csv1) { Write-Output "Job1 $name1"}
    Start-Job {
    $csv2 = (Import-Csv "C:\Copy AD to test Lab\data\Usergroups2.csv").username
    foreach ($name2 in $csv2) { Write-Output " Job2 $name2"}
    Get-Job | Receive-Job
    Lishron

    You say your testing shows that you are using very little cpu or memory in processing each name, which suggests that processing a single name is a relatively trivial task.  
    You need to understand that using a background job is going to spin up another instance of powershell, and if you're going to do that per name what used to require a relatively insignificant amount of memory is going to take around 60 MB.  
    Background jobs are not really well suited for multi-threading short-running, trivial tasks.  The overhead of setting up and tearing down the job session can be more than the task itself.
    Background jobs are good for long-running tasks.  For multi-threading short, trivial tasks runspaces or a workflow would probably be a better choice.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

Maybe you are looking for

  • Vendor master data - Single material with multiple price

    Hi Gurus, Per our set-up, we have 1 purchasing organization to handle the central procurement function for purchases to various countries/destination.  As such, whenever we seek for quotation from a single vendor, the vendor will provide their price

  • Local copy of file during Display

    Hi, I have mainitained C:\temp\ as the path for the frontend in DC20. Whenever the file is displayed in CV03N I have noticed that the file does get copied to this location but there is one more copy of the file created in local temp directory (C:\DOC

  • POWL - Travel Assistant

    Dear Expert, I'm Using POWL Travel Assistant for switch personnel number, but the problem is i  select employee from list the it would error " Infotype 0001 does not exist for " I already make sure that the person do have 0001 & 0017 and all other pr

  • RMAN-05001: auxiliary filename +ARS_DAT9/ars/datafile/arsystem1.259.6326886

    Hi Forum I'm trying to create a standby database, but rman was returning this error: Recovery Manager: Release 10.2.0.3.0 - Production on Sun Sep 9 14:57:57 2007 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to target database: ARS

  • Can't install kernel 24

    here is the output: [root@blue qax]# pacman -Syu :: Synchronizing package databases... core is up to date extra is up to date community is up to date :: Starting full system upgrade... warning: dnsutils: forcing upgrade to version 9.4.2-1 warning: fl