Old 17-06-2008   #1 (permalink)
Monster Member
 
scott's Avatar
 
Join Date: Jun 2006
Location: Melbourne
Posts: 3,684
Rep Power: 12
Default 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
__________________
#RiceRockets
SR20DET
scott is online now   Reply With Quote
Old 17-06-2008   #2 (permalink)
Honorary Member
 
Zer0//'s Avatar
 
Join Date: Jan 2008
Location: pokemonville
Age: 17
Posts: 1,964
Rep Power: 13
Send a message via ICQ to Zer0// Send a message via AIM to Zer0// Send a message via MSN to Zer0// Send a message via Yahoo to Zer0//
Default

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


try something like that.
__________________
SilverBullet-endo-denwo-alphabet-reliant-Zer0-Twelve-60
#resistance & #stipe@ Gamesurge


Wanna feel stupid?.........click here
Zer0// is offline   Reply With Quote
Old 17-06-2008   #3 (permalink)
Monster Member
 
scott's Avatar
 
Join Date: Jun 2006
Location: Melbourne
Posts: 3,684
Rep Power: 12
Default

im sorrying html doesnt work in powershell :P
__________________
#RiceRockets
SR20DET
scott is online now   Reply With Quote
Old 17-06-2008   #4 (permalink)
Honorary Member
 
Zer0//'s Avatar
 
Join Date: Jan 2008
Location: pokemonville
Age: 17
Posts: 1,964
Rep Power: 13
Send a message via ICQ to Zer0// Send a message via AIM to Zer0// Send a message via MSN to Zer0// Send a message via Yahoo to Zer0//
Default

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
__________________
SilverBullet-endo-denwo-alphabet-reliant-Zer0-Twelve-60
#resistance & #stipe@ Gamesurge


Wanna feel stupid?.........click here
Zer0// is offline   Reply With Quote
Old 17-06-2008   #5 (permalink)
Monster Member
 
fury's Avatar
 
Join Date: May 2007
Location: Brisbane
Posts: 2,552
Rep Power: 8
Send a message via MSN to fury
Default

google is your friend,

` for line break
__________________
#COREPLAY
Anonymous . ethz . Fury . NTER . Sooty . Versatile
fury is online now   Reply With Quote
Old 17-06-2008   #6 (permalink)
Monster Member
 
scott's Avatar
 
Join Date: Jun 2006
Location: Melbourne
Posts: 3,684
Rep Power: 12
Default

Doesnt work with arrays :P
__________________
#RiceRockets
SR20DET
scott is online now   Reply With Quote
Old 17-06-2008   #7 (permalink)
Monster Member
 
fury's Avatar
 
Join Date: May 2007
Location: Brisbane
Posts: 2,552
Rep Power: 8
Send a message via MSN to fury
Default

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

try that
__________________
#COREPLAY
Anonymous . ethz . Fury . NTER . Sooty . Versatile
fury is online now   Reply With Quote
Old 17-06-2008   #8 (permalink)
Honorary Member
 
Zer0//'s Avatar
 
Join Date: Jan 2008
Location: pokemonville
Age: 17
Posts: 1,964
Rep Power: 13
Send a message via ICQ to Zer0// Send a message via AIM to Zer0// Send a message via MSN to Zer0// Send a message via Yahoo to Zer0//
Default

Well im no help lol

javascript and php is better :P
also ajax is badass **** but complicated ><
__________________
SilverBullet-endo-denwo-alphabet-reliant-Zer0-Twelve-60
#resistance & #stipe@ Gamesurge


Wanna feel stupid?.........click here
Zer0// is offline   Reply With Quote
Old 17-06-2008   #9 (permalink)
Monster Member
 
scott's Avatar
 
Join Date: Jun 2006
Location: Melbourne
Posts: 3,684
Rep Power: 12
Default

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
__________________
#RiceRockets
SR20DET
scott is online now   Reply With Quote
Old 17-06-2008   #10 (permalink)
Monster Member
 
fury's Avatar
 
Join Date: May 2007
Location: Brisbane
Posts: 2,552
Rep Power: 8
Send a message via MSN to fury
Default

hmm i see GL!
__________________
#COREPLAY
Anonymous . ethz . Fury . NTER . Sooty . Versatile
fury is online now   Reply With Quote
Old 17-06-2008   #11 (permalink)
New Member
 
Join Date: Jul 2006
Posts: 6
Rep Power: 0
Default

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?
MiMiX is offline   Reply With Quote
Old 17-06-2008   #12 (permalink)
Monster Member
 
scott's Avatar
 
Join Date: Jun 2006
Location: Melbourne
Posts: 3,684
Rep Power: 12
Default

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
__________________
#RiceRockets
SR20DET
scott is online now   Reply With Quote
Old 17-06-2008   #13 (permalink)
Member
 
Join Date: Jul 2006
Location: Perth
Posts: 134
Rep Power: 3
Default

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.
__________________
FaRMERZ
zebo[c] clate Subaru sk1z Prx
Intel C2D E8600 @ 4.40Ghz | ABiT IX38 QuadGT | 2x1GB Dominator 1066mhz 5-5-5-15 | 2x160GB SS SATA2 RAID0 | 1x500GB SS SATA2 | XFi Fatality | XFX 8800GT xXx | GenericCase + Thermalright IFX 14 + Generic600W | Samsung 2253BW | MS3.0 + Eveglide Titan
Subaru is offline   Reply With Quote
Old 17-06-2008   #14 (permalink)
New Member
 
Join Date: Jul 2006
Posts: 6
Rep Power: 0
Default

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
MiMiX is offline   Reply With Quote
Old 17-06-2008   #15 (permalink)
Pro Member
 
chemicalNova's Avatar
 
Join Date: Jun 2006
Posts: 5,863
Rep Power: 14
Default

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.
-
chemicalNova is online now   Reply With Quote
Old 18-06-2008   #16 (permalink)
ivo
GotGames GFX Designer
 
ivo's Avatar
 
Join Date: Jun 2006
Location: Vic
Posts: 2,857
Rep Power: 10
Default

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
__________________


"If you wanna get it through their head, talk to them ragely" - fakeh
ivo is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +10. The time now is 08:51 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
no new posts