我希望程序执行的操作是要求用户输入,输入数字1-7,然后吐出正确的WriteLine语句。一切都可以正常编译,但是无论输入什么数字,我都能得到默认的WriteLine选项。我要去哪里错了?
Sub getData()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim symbol As Variant
Dim n As Integer
Dim lastrow As Long
Dim myrequest As Variant
Dim i As Integer
Set wb = ActiveWorkbook
Set ws = Sheets("Sheet1")
ws.Activate
'Last row find
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
Set rng = ws.Range("A4:A" & lastrow)
'Clear Prior Prices
ws.Range("B4:B" & lastrow).ClearContents
n = 4
'Get Symbols list
For Each symbol In rng
Set myrequest = CreateObject("WinHttp.WinHttpRequest.5.1")
myrequest.Open "Get", "https://api.iextrading.com/1.0/stock/" & symbol &
"/quote"
'myrequest.Open "Get", "https://www.bloomberg.com/markets/api/bulk-time-
series/price/" & symbol & "%3AUS?timeFrame=1_DAY"
myrequest.Send
Debug.Print myrequest.ResponseText
Dim Json As Object
Set Json = JsonConverter.ParseJson(myrequest.ResponseText)
MsgBox (myrequest.ResponseText)
i = Json(1)("latestPrice")
ws.Range(Cells(n, 2), Cells(n, 2)) = i
n = n + 1
Next symbol
ws.Columns("B").AutoFit
MsgBox ("Data is downloaded.")
ws.Range("B4:B" & lastrow).HorizontalAlignment = xlGeneral
ws.Range("B4:B" & lastrow).NumberFormat = "$#,##0.00"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:4)
您需要此:
int userInput = Convert.ToInt32(Console.ReadLine());