What should I do to make this calculator work? - calculator

I have to program a simple calculator in BASIC that asks for a number, then for a basic operator (+,-,*,/), then for another number, then another operator until the user inputs "=" as an operator. Then the program should stop and output the result. So far, I have done this :
10 Input "Entrez un nombre : " ; Nombre
20 Input "Entrez un opérateur (+,-,*,/) : " ; Operateur$
if Operateur$ <> "+" and Operateur$ <> "-" and Operateur$ <> "*" and Operateur$ <> "/" and Operateur$ <> "=" then goto 20
if Operateur$ = "+" or Operateur$ = "-" or Operateur$ = "*" or Operateur$ = "/" then goto 10
if Operateur$ = "=" then goto 30
30 Print "Résultat : " ; Resultat
I am stuck at how to actually calculate the result, I cannot figure out a way...

10 Input "Entrez un nombre : " ; Nombre
Resultat = Nombre
20 Input "Entrez un opérateur (+,-,*,/) : " ; Operateur$
if Operateur$ <> "+" and Operateur$ <> "-" and Operateur$ <> "*" and Operateur$ <> "/" and Operateur$ <> "=" then goto 20
if Operateur$ = "+" or Operateur$ = "-" or Operateur$ = "*" or Operateur$ = "/" then goto 30
if Operateur$ = "=" then goto 40 else goto 30
30 Input "Entrez un nombre : " ; Nombre2
if Operateur$ = "+" then Resultat = Resultat + Nombre2
if Operateur$ = "-" then Resultat = Resultat - Nombre2
if Operateur$ = "*" then Resultat = Resultat * Nombre2
if Operateur$ = "/" then Resultat = Resultat / Nombre2
goto 20
40 Print "Résultat : " ; Resultat

Related

Adding 100 users in powershell script not working

I am trying to add 100 user accounts with PowerShell in my domain system in Windows. I get an error message called "You cannot call a method on a null-valued expression" when running the script for import.
Error Message:
You cannot call a method on a null-valued expression.
At C:\Users\Administrator\Downloads\user-import.ps1:37 char:9
+ $brukernavn = ($fornavn.Substring(0,3) + $etternavn.Substring ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull*
The PowerShell Script:
Import-Module ActiveDirectory
$csvpath = $PSScriptRoot + "\produksjonsbrukereImport.csv"
if (Test-Path $csvpath) {
#$csvpath = "C:\script\produksjonsbrukereImport.csv"
$csv = Import-Csv -Delimiter "," -Path $csvpath -Encoding UTF7
$OUBasePath = ",OU=Produksjon,OU=OpMeis,DC=OpMeis,DC=local"
$logpath = "$PSScriptRoot\import-brukere-loggfil.txt"
}
foreach ($line in $csv) {
$fornavn = $line.fornavn
$etternavn = $line.etternavn
$navn = ($fornavn + " " + $etternavn)
$beskrivelse = $line.beskrivelse
$passord = $line.Passord
$avdeling = $line.avdeling
$brukernavn = ($fornavn.Substring(0,3) + $etternavn.Substring(0,3)).ToLower()
$brukernavn = $brukernavn -replace "æ", "a"
$brukernavn = $brukernavn -replace "å", "a"
$brukernavn = $brukernavn -replace "ø", "o"
$principal = $brukernavn + "#OpMeis.local"
$profPath = ($profBasePath + $brukernavn)
$profPathTrue = $profPath + ".V2"
$OU = ("OU=" + $avdeling + $OUBasePath)
}

Multiple monitors/graphic cards info using powershell

I am using the following script to get system information. The script works fine, I have problem when computers with two graphic cards or multiple monitors.
For more monitors I found this Get Screen resolution using WMI/powershell in Windows 7
but don't know how to format/implement it to fit my script.
$user = [Environment]::UserName
$System = Get-CimInstance CIM_ComputerSystem
$BIOS = Get-CimInstance CIM_BIOSElement
$OS = Get-CimInstance CIM_OperatingSystem
$CPU = Get-CimInstance CIM_Processor
$osup = Get-WmiObject win32_operatingsystem
$uptime = (Get-Date) - ($osup.ConvertToDateTime($osup.lastbootuptime))
$GPU = Get-CimInstance CIM_VideoController
$RES = Get-WmiObject Win32_VideoController
$used = ($System.TotalPhysicalMemory/1MB)-($OS.FreePhysicalMemory/1KB)
$EXTXT = "$env:USERPROFILE\Desktop\vq.txt"
Clear-Host
$user + "#" + $system.Name >> $EXTXT
"OS: " + $OS.caption + " " + $osup.OSArchitecture >> $EXTXT
"Model: " + $System.Model >> $EXTXT
"Kernel: " + $OS.Version >> $EXTXT
"Uptime: " + $Uptime.Days + "d " + $Uptime.Hours + "h " + $Uptime.Minutes + "m " >> $EXTXT
"Resolution: " + $RES.CurrentHorizontalResolution + "x" + $RES.CurrentVerticalResolution >> $EXTXT
"CPU: " + $CPU.Name >> $EXTXT
"GPU: " + $GPU.Name >> $EXTXT
"Memory: " + "{0:N0}" -f $used + "MB" + " / " + "{0:N0}" -f ($System.TotalPhysicalMemory/1MB) + "MB" >> $EXTXT
I basically want to get file with information in lines, with GPU separated with comma and detection for multiple screens and if there are multiple monitors printed their respective resolutions.
I suggest changing the line $GPU = to
$GPU=(Get-CimInstance CIM_VideoController|%{$_.Name}) -join("; ")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.Screens")
$Screens = ([system.windows.forms.screen]::AllScreens | %{"$($_.Bounds.width)x$($_.Bounds.Height)"}) -join("; ")
and "GPU: " + $GPU.Name >> $EXTXT to
"GPU: " + $GPU >> $EXTXT
"Resolution: " + $Screens

execute ftp with white space in path

The following PowerShell script runs an ftp command but returns an error as it cannot get find the absolute source path (which includes white space and does take the complete path as "File One” and “Destination One".
Output:
/usr/bin/lftp -c \"mirror --only-missing --verbose sftp://jason#10.1.1.1:/e:/Files/File One e:/Files/Destination One/File One\"
Access failed: No such file (e:/Files/File)
The values of each variables are hardcoded and cannot be changed for a reason. In that case, what are the changes required in the $ftppath or $ftpcmd to include these white spaces in the source and dest, so it can return the ftpcmd correctly. Could someone please help?
Script:
# these values are hardcoded and cannot be modified
$root = "/e:/Files"
$source = "File One"
$dest = "e:/Files/Destination One/File One"
$user = "jason"
$server = "10.1.1.1"
# ftp command
$ftppath = "sftp://$user" + '#' + $server + ':' + $root + '/' + $source + ' ' + $dest
$ftpcmd = '/usr/bin/lftp -c \"mirror --only-missing --verbose ' + "$ftppath"+'\"'
$ftpcmd
Invoke-Expression -command $ftpcmd
so i guess you can simply use it like thi:
# these values are hardcoded and cannot be modified
$root = "/e:/Files"
$source = "File One"
$dest = "e:/Files/Destination One/File One"
$user = "jason"
$server = "10.1.1.1"
# ftp command
$ftppath = "sftp://$user" + '#' + $server + ':' + $root + '/' + $source + ' ' + $dest
$ftpcmd = '/usr/bin/lftp -c \"mirror --only-missing --verbose ' + "$ftppath"+'\"'
$ftpcmd
Invoke-Expression -command $ftpcmd.replace(" ", "\ ")
```shell
ftp command
$ftppath = "sftp://$user" + '#' + $server + ':' + $root + '/' + $source + ' ' + $dest
```
replace by this,use quote wrap $dest
```shell
ftp command
$ftppath = "sftp://$user" + '#' + $server + ':' + $root + '/' + $source + ' ' + "${dest}"
```

powershell error-CategoryInfo : InvalidOperation: (split:String) [], RuntimeException

$Analog_File = "c:\temp\test\mt.txt"
#(Get-Item $Analog_File).length
if((Test-Path(-not $Analog_File)) -or ((Get-Item $Analog_File).length -eq 0kb))
{
exit
}
$m = Select-String -pattern ",T" c:\temp\test\mt_1.txt
#$m.length #Get the number of rows
For ($i=0; $i -le $m.length; $i++)
{
$s1 = $m[$i] -split ":"
$s1[2]
if ([int]$s1[2] -ge 9) #le = less than, ge = greater than, eq = equal to
{
$s2 = $s1[3] -split ","
$compid = $s2[2].split('''')[0] + "." + $s2[3].split('''')[0] + "." + $s2[4].split('''')[0] + "." + $s2[5].split('''')[0]
$matches = (Select-String -pattern $compid c:\temp\test\mt_1.txt).line
#($matches.split(';')[0])
#($matches.split(';')[0]).split(',')[0]
#($matches.split(';')[0]).split(',')[1]
if ($s2[6] -eq "T")
{
#$s2[2].split('''')[1]
#"Not in Service"
#"!" + ($matches.split(';')[0]).split(',')[0] + "!" + ($matches.split(';')[0]).split(',')[1] + "!0!" >> $fname
}
if ($s2[7] -eq "T")
{
#"Alarm inhibit"
#"!" + ($matches.split(';')[0]).split(',')[0] + "!" + ($matches.split(';')[0]).split(',')[1] + "!1!" >> $fname
}
if ($s2[8] -eq "T")
{
#"Manual update"
#"!" + ($matches.split(';')[0]).split(',')[0] + "!" + ($matches.split(';')[0]).split(',')[1] + "!2!" >> $fname
}
}
}
the error message:
You cannot call a method on a null-valued expression.
At line:17 char:31
$compid = $s2[2].split <<<< ('''')[0] + "." + $s2[3].split('''')[0] + "." + $s2[4].split('''')[0] + "." + $s2[5].split('''')[0]
CategoryInfo : InvalidOperation: (split:String) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
what can i do??

Powershell unexpected token

have a great 2013. I am getting my hands wet on my first PS Script and I am stuck on a very common error, the "Unexpected Token" error. I've searched the internet, but could not find an answer, so please help me out.
If ($_.Voorvoegsel.Trim() -ieq "") {
$dn = $_.Voornaam.Trim() + " "
$dn += $_.Achternaam.Trim()
$email = $_.Voornaam.substring(0,1).ToLower() + "."
$email+= $_.Achternaam.Trim().ToLower() + "#test.nl
} Else {
$dn = $_.Voornaam.Trim() + " "
$dn += $_.Voorvoegsel.Trim() + " "
$dn += $_.Achternaam.Trim()
$email = $_.Voornaam.substring(0,1).ToLower() + "."
$email += $_.Voorvoegsel.Replace(" ","").ToLower()
$email += $_.Achternaam.Trim().ToLower() + "#test.nl
}
The strange thing is that it errors on the $_.Voorvoegsel variable in the else statement:
Unexpected token '
$dn += $_.Voorvoegsel.Trim()
$dn += ' in expression or statement.
At C:\Users\Public\Documents\PSImportTest.ps1:42 char:12
+ $dn = $_ <<<< .Voornaam.Trim() + " "
+ CategoryInfo : ParserError: (
$dn += $_....m()
$dn += :String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
Anyone out there who sees what my blind spot is here?
It may be that you are missing an end quote on line 5:
$email += $_.Acternaam.Trim().ToLower() + "#test.nl"
It looks like you also may be missing one on line 12. Powershell may think the rest of the code, until the next quote character, is part of your string literal.