Go Back   Flash Flash Revolution > General Discussion > Technology
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 07-7-2012, 06:03 PM   #1
SlayerApocalypse666
Banned
FFR Veteran
 
Join Date: Aug 2006
Posts: 324
Default Powershell Problem, VRY SIMPLE.

Here is a small script i made to enter 10 values, and then come out with the Highest of these value.....but its always returning me 9 as highest value, lets say my 10 values are 1,2,3,4,5,100,1000,9
then i get 9 as my highest value. What is wrong ?


Write-Host "Enter 10 number higher than -1:" #Output Text on the line.
$v = 0 #Variable
$vn = 0 #Variable

for ($a = 1; $a -le 10; $a++) { #For statement
$vn = Read-Host "Enter number # " $a #Output "enter value number $a" then get the value $vn from keyboard.
if ($vn -gt $v) { $v = $vn } #If $vn is higher than the value $v then i put $vn into $v
}

Write-Host "The highest value is " $v #Output "the highest value is" value $v


I i enter the value, 100,200,300,800,1000,900,768,654,543 my highest value will be 900 , i noticed that if the number dont have the same digital lenght, they gont get compared prolerly. Vry weird.

I fixed my problem by changing my first 2 varibles from $v and $nv to [int]$v and [int]$nv thx alot megamon for your answer.

Last edited by SlayerApocalypse666; 07-7-2012 at 10:51 PM..
SlayerApocalypse666 is offline   Reply With Quote
Old 07-7-2012, 06:09 PM   #2
megamon88
aka Assertive
Retired StaffFFR Simfile AuthorFFR Music ProducerFFR Veteran
 
megamon88's Avatar
 
Join Date: Feb 2006
Location: Waterloo, ON
Age: 29
Posts: 2,567
Default Re: Powershell Problem, VRY SIMPLE.

I don't know powershell, but from what I can tell, it looks like your variable $vn isn't reading the number with index $a on the list, but rather taking the actual value of $a. That's why your highest value is always 9, since $a counts up from 0 to 9.

Sorry if this doesn't help much, don't know the language :P
__________________
megamon88 is offline   Reply With Quote
Old 07-8-2012, 07:30 AM   #3
UserNameGoesHere
FFR Veteran
FFR Veteran
 
UserNameGoesHere's Avatar
 
Join Date: May 2008
Posts: 1,114
Send a message via AIM to UserNameGoesHere
Default Re: Powershell Problem, VRY SIMPLE.

I haven't used PowerShell but that code looks correct.

megamon, the contents of $a are merely printed to the user and $a is used as a counter of the for loop itself. I see where your confusion is, but this line
Code:
$vn = Read-Host "Enter number # " $a
does something like a print statement (for example if $a were 1 it would print "Enter number # 1") followed by waiting for user input: the user's input is exclusively what goes to $vn

It looks like the [int]$v syntax is a kind of data binding? (Again, I've not used PowerShell myself). But it looks like it's a way to "link" certain things? It's confusing because it is too similar to the array notation in other languages.
__________________
Quote:
Originally Posted by Crashfan3 View Post
Man, what would we do without bored rednecks?
[SIGPIC][/SIGPIC]
UserNameGoesHere is offline   Reply With Quote
Old 07-8-2012, 10:50 AM   #4
megamon88
aka Assertive
Retired StaffFFR Simfile AuthorFFR Music ProducerFFR Veteran
 
megamon88's Avatar
 
Join Date: Feb 2006
Location: Waterloo, ON
Age: 29
Posts: 2,567
Default Re: Powershell Problem, VRY SIMPLE.

Whoops, that's what I get for not paying attention. Thanks for pointing it out :P
__________________
megamon88 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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 Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 02:23 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution