Reply to Thread
Results 1 to 16 of 16

Thread: Array Help

  1. #1
    Monster Member scott's Avatar
    Join Date
    Jun 2006
    Location
    Melbourne
    Posts
    4,752

    GGLive
    Offline offline

    Rep Power
    12

    Array Help

    Just trying to finish my powershell assignment, but even if you can explain how to do it in any language i can prob just grab the concept..

    I have a data driven loop that accepts multiple inputs and the stores then in an arary.

    Only problem is when i display the array its got all the info on just the one line i need to have it display 1 line for one loop of inputs.

    This makes the array
    $details +=($type,$description,$price,$quantity)
    $count = $count +1

    And this is displaying it.
    do
    {
    write-host "item $i is "$details
    $i = $i + 1
    }
    while ($i -lt $count)

    Is there something i can add that so it adds another line each time it adds to the array ??

    it out puts like this

    Scott Field 1 1 Tony Ganly 2 2
    Scott Field 1 1 Tony Ganly 2 2

    And needs to come out like this
    Scott Field 1 1
    Tony Ganly 2 2

    Thanks
    I live my life one handbrake entry at a time....



  2. #2
    Monster Member Zer0//'s Avatar
    Join Date
    Jan 2008
    Location
    Sydney
    Age
    20
    Posts
    3,407

    GGLive
    Offline offline

    Rep Power
    13
    do
    {
    write-host "item $i is "$details "</ br>"
    $i = $i + 1
    }
    while ($i -lt $count)


    try something like that.

  3. #3
    Monster Member scott's Avatar
    Join Date
    Jun 2006
    Location
    Melbourne
    Posts
    4,752

    GGLive
    Offline offline

    Rep Power
    12
    im sorrying html doesnt work in powershell :P
    I live my life one handbrake entry at a time....

  4. #4
    Monster Member Zer0//'s Avatar
    Join Date
    Jan 2008
    Location
    Sydney
    Age
    20
    Posts
    3,407

    GGLive
    Offline offline

    Rep Power
    13
    ah shnap. i have no idea what powershell is >< .

    I did bit of google searching.. read this it should fix your problem

    How to put line breaks into a text string in Windows Powershell | SearchMarked.com

  5. #5
    GotGames Moderator fury's Avatar
    Join Date
    May 2007
    Posts
    6,544

    GGLive
    Offline offline

    Rep Power
    26
    google is your friend,

    ` for line break

  6. #6
    Monster Member scott's Avatar
    Join Date
    Jun 2006
    Location
    Melbourne
    Posts
    4,752

    GGLive
    Offline offline

    Rep Power
    12
    Doesnt work with arrays :P
    I live my life one handbrake entry at a time....

  7. #7
    GotGames Moderator fury's Avatar
    Join Date
    May 2007
    Posts
    6,544

    GGLive
    Offline offline

    Rep Power
    26
    do
    {
    write-host "item $i is "$details `
    $i = $i + 1
    }
    while ($i -lt $count)

    try that

  8. #8
    Monster Member Zer0//'s Avatar
    Join Date
    Jan 2008
    Location
    Sydney
    Age
    20
    Posts
    3,407

    GGLive
    Offline offline

    Rep Power
    13
    Well im no help lol

    javascript and php is better :P
    also ajax is badass **** but complicated ><

  9. #9
    Monster Member scott's Avatar
    Join Date
    Jun 2006
    Location
    Melbourne
    Posts
    4,752

    GGLive
    Offline offline

    Rep Power
    12
    Yeah the problem is with the array itself not printing it so doing that will just display the array twice is a line break under it.

    Thanks neway i think ill try go about it a dif way
    I live my life one handbrake entry at a time....

  10. #10
    GotGames Moderator fury's Avatar
    Join Date
    May 2007
    Posts
    6,544

    GGLive
    Offline offline

    Rep Power
    26
    hmm i see GL!

  11. #11
    New Member
    Join Date
    Jul 2006
    Posts
    6

    GGLive
    Offline offline

    Rep Power
    0
    can you not just add \n to your output?

    works in c# formats to force new line...

    cant you also use VB.net or C# commands within powershell and interact with the objects the same way you would as if it was a win/asp app?

  12. #12
    Monster Member scott's Avatar
    Join Date
    Jun 2006
    Location
    Melbourne
    Posts
    4,752

    GGLive
    Offline offline

    Rep Power
    12
    Okay well im going about it a different way now.

    this makes the array
    $details =($type,$description,$price,$quantity)
    this outputs the array to a txt file
    $details | out-file test.txt
    but the out put of the txt file is this
    Scott
    lol
    1
    2

    and i want them to all be side by side.
    ne idea
    I live my life one handbrake entry at a time....

  13. #13
    Member
    Join Date
    Jul 2006
    Location
    Perth
    Posts
    144

    GGLive
    Offline offline

    Rep Power
    6
    What about using an if or while loop to check if it should print a newline or not? That way you could include an endline character of your own and tell it to only print a new line if it encounters the character? Might be using more system overhead than you want though... It could at least be a starting point for a more efficient solution.
    Intel Core i7 860 | Gigabyte P55A UD6 | 2x2GB XMS3 1600mhz | 2x500GB WD Black SATA2 RAID0 | XFi Fatality | eVGA GTX285 | TJ10 + Corsair 1KW | Samsung P2370 | Ikari + Goliathas

  14. #14
    New Member
    Join Date
    Jul 2006
    Posts
    6

    GGLive
    Offline offline

    Rep Power
    0
    instead of piping to out-file, why not set the input object by the parameter provided? Not sure if that will fix it?

    eg: out-file test.txt -inputobject $details

  15. #15
    Pro Member chemicalNova's Avatar
    Join Date
    Jun 2006
    Posts
    6,256

    GGLive
    Offline offline

    Rep Power
    14
    Sorry.. how is AJAX complicated?

    Haha scott.. I wasn't on MSN between work and now so you had to post. SUCKS2BU.

    Also.. I've known about powershell for like, 3 weeks now.. and I don't think I like it.

    chem
    There are no stupid questions... but there are alot of inquisitive idiots.
    -

  16. #16
    Ivo
    Ivo is offline
    GotGames Moderator Ivo's Avatar
    Join Date
    Jun 2006
    Location
    Vic
    Posts
    6,062

    GGLive
    Offline offline

    Rep Power
    34
    Do a string merge of $type,$description,$price,$quantity, then output that to the file.

    like $details = $type " " $description " " $price " " $quantity
    or <insert loop here> $details[i] = $type[i] " " $description[i] " " $price[i] " " $quantity[i]

    or something


    "It wasn't a DDOS." - xr6_turbo, on syntax
    [ep'] Ivoz - BC2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Joseph
CEVO
Gametech
Activision
Activision
Blizzard
Gamestah