0

我正在为“TechnoExpo”做一个学校项目。我需要知道如何将字符串拉到两个“()”之间,并且我需要知道如何计算四个变量。

Input One Example: 6(3)
Input Two Example: 2(7)

我需要将“6”设置为名为“X1”的变量,将“3”设置为名为“Y1”的变量,将“2”设置为名为“X2”的变量,最后将“7”设置为名为“Y2”的变量。接下来我需要计算 ("Y2"-"Y1") 除以 ("X2"-"X2")。从这里我可以自己显示信息。这是一个 beta 批处理文件版本。

@Echo Off
:StartUpConfiguration
Cls
Mode Con Cols=50 Lines=25
Color 0F

:Start
Set /P CordinateOne=[One]
Set /P CordinateTwo=[Two]
For /F "Tokens=1,2 delims=()" %%A In ("%CordinateOne%") Do Set "X1=%%A" & set "Y1=%%B"
For /F "Tokens=1,2 delims=()" %%A In ("%CordinateTwo%") Do Set "X2=%%A" & set "Y2=%%B"
Echo Slope:
Set /A Y=%Y2%-%Y1%
Set /A X=%X2%-%X1%
Set /A M=%Y%/%X%
Echo [%M%]
Echo.
Echo %Y2% - %Y1% [%Y%]
Echo %X2% - %X1% [%X%]
Pause
4

2 回答 2

2
strInput1 = UserInput( "CordinateOne=:" )
strInput2 = UserInput( "CordinateTwo=:" )


substr1=Split(strInput1,"(")
substr2=Split(strInput2,"(")

X1=CInt(substr1(0))
Y1=CInt(Split(substr1(1),")")(0))

X2=CInt(substr2(0))
Y2=CInt(Split(substr2(1),")")(0))

X=X2-X1
Y=Y2-Y1
M=Y/X
MI=Y Mod X

Wscript.Echo "[" & M & "]" & "or [" & M & "." & MI & "]"
Wscript.Echo ""
Wscript.Echo Y2 & "-" & Y1 & " [" & Y & "]"
Wscript.Echo X2 & "-" & X1 & " [" & X & "]"  


Function UserInput( myPrompt )
' This function prompts the user for some input.
' When the script runs in CSCRIPT.EXE, StdIn is used,
' otherwise the VBScript InputBox( ) function is used.
' myPrompt is the the text used to prompt the user for input.
' The function returns the input typed either on StdIn or in InputBox( ).
' Written by Rob van der Woude
' http://www.robvanderwoude.com
    ' Check if the script runs in CSCRIPT.EXE
    If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
        ' If so, use StdIn and StdOut
        WScript.StdOut.Write myPrompt & " "
        UserInput = WScript.StdIn.ReadLine
    Else
        ' If not, use InputBox( )
        UserInput = InputBox( myPrompt )
    End If
End Function

您可以使用cscript.exewscript.exe .No 验证输入来执行此操作。

于 2013-10-21T21:34:19.160 回答
1

回答你的标题How to extract part of string in Visual Basic Scripting (VBS)?

以下是您需要的所有信息:

MSDN:中间函数

W3Schools:中间功能

例子:

txt="This is a beautiful day!"
wscript.Echo(Mid(txt,1,1))
于 2013-10-21T20:43:22.473 回答