我有下面的代码,它应该找到一个范围内的第1,第2,第3和第4个最高值.
它目前是非常基础的,我有它在MsgBox中提供值,所以我可以确认它是否正常工作.
但是,它只能找到最高和第二高的值.第三个和第四个值返回0.我缺少什么?
Sub Macro1()
Dim rng As Range, cell As Range
Dim firstVal As Double, secondVal As Double, thirdVal As Double, fourthVal As Double
Set rng = [C4:C16]
For Each cell In rng
If cell.Value > firstVal Then firstVal = cell.Value
If cell.Value > secondVal And cell.Value < firstVal Then secondVal =
cell.Value
If cell.Value > thirdVal And cell.Value < secondVal Then thirdVal =
cell.Value
If cell.Value > fourthVal And cell.Value < thirdVal Then fourthVal =
cell.Value
Next cell …Run Code Online (Sandbox Code Playgroud) 我正在编辑我的一个旧脚本,向用户发送一封电子邮件,其中嵌入了图像。我正在尝试使用 Send-MailMessage 函数来发送电子邮件,而不是旧的 $smtp.send($msg) 方法。但是,当尝试更新脚本时,图像不再被嵌入。
我知道如何将它们作为实际附件附加到电子邮件中,但我不确定将它们显示为实际嵌入图像我做错了什么。
注意:为简洁起见,我删除了一些完整的电子邮件,因为它很大,只要我能得到一两个图像,它都会起作用。
# force powershell to run as an x86 process
Set-ExecutionPolicy -Scope CurrentUser Unrestricted
if ($env:Processor_Architecture -ne "x86") {
&"$env:windir\syswow64\windowspowershell\v1.0\powershell.exe" -file $myinvocation.Mycommand.path
exit
}
# initialize the script
if ($startupvariables) { try {Remove-Variable -Name startupvariables -Scope Global -ErrorAction SilentlyContinue } catch { } }
New-Variable -force -name startupVariables -value ( Get-Variable | ForEach-Object { $_.Name } )
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$Separator = ".", "@"
# advise what the script does
Add-Type -AssemblyName PresentationCore,PresentationFramework
$ButtonType …Run Code Online (Sandbox Code Playgroud) 我有一个包含多行数字的文本文件。我正在尝试使用 Get-Content 将每行上的值返回到它自己的变量,以便在电子邮件中使用。但是,无论我如何编写,它似乎都将值放在自己的行上(大多数情况下),而不是返回每个数字。我缺少什么?
输入文件有 3 个值,每个值都在自己的行上......88.6、72.2、0.01
目标是让脚本分配 $value1 = 88.6、$value2 = 72.2 和 $value3 = 0.01
我的PS代码如下:
$data = (Get-Content C:\CumulusMX\summaries\daily_values.txt -TotalCount 1)[-1]
$data2 = (Get-Content C:\CumulusMX\summaries\daily_values.txt -TotalCount 2)[-1]
$data3 = (Get-Content C:\CumulusMX\summaries\daily_values.txt -TotalCount 3)[-1]
echo $data
echo $data2
echo $data3
Run Code Online (Sandbox Code Playgroud)
然而,它正在返回:
。7 2 . 2 0 。0 1
每个角色都在自己的行上。