Mostrar precio de Bitcoin en TextBox
Publicado por Baator (1 intervención) el 04/12/2022 07:24:21
Hola, qué tal. Necesito conseguir la forma de agregar el precio del BTC dentro de un TextBox que se actualice al darle a un botón. Hasta los momentos tengo este código pero me da error en:
"Dim data As String = response.GetResponseStream()" El valor de tipo Stream no se puede convertir en String.
"Dim jObject As JObject = jObject.Parse(content)" No está definido el tipo JObject. La variable jObject se usa antes de que se le haya asignado un valor.
Código completo para esa función:
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
' Set the URL of the API endpoint
Dim url As String = "https://api.coindesk.com/v1/bpi/currentprice.json"
Try
' Create a new HTTP to=python
request = HttpWebRequest.Create(url)
' Send the request and get the response
response = request.GetResponse()
' Read the response and store it in a string
Dim data As String = response.GetResponseStream()
Dim content As String = reader.ReadToEnd()
' Close the response
response.Close()
' Parse the JSON response to get the current Bitcoin price
Dim jObject As JObject = JObject.Parse(content)
Dim price As Double = jObject("bpi")("USD")("rate_float")
' Update the text box with the current Bitcoin price
TextBox1.Text = price
Catch ex As Exception
' Show an error message if the request failed
MessageBox.Show("Error: " & ex.Message)
End Try
"Dim data As String = response.GetResponseStream()" El valor de tipo Stream no se puede convertir en String.
"Dim jObject As JObject = jObject.Parse(content)" No está definido el tipo JObject. La variable jObject se usa antes de que se le haya asignado un valor.
Código completo para esa función:
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
' Set the URL of the API endpoint
Dim url As String = "https://api.coindesk.com/v1/bpi/currentprice.json"
Try
' Create a new HTTP to=python
request = HttpWebRequest.Create(url)
' Send the request and get the response
response = request.GetResponse()
' Read the response and store it in a string
Dim data As String = response.GetResponseStream()
Dim content As String = reader.ReadToEnd()
' Close the response
response.Close()
' Parse the JSON response to get the current Bitcoin price
Dim jObject As JObject = JObject.Parse(content)
Dim price As Double = jObject("bpi")("USD")("rate_float")
' Update the text box with the current Bitcoin price
TextBox1.Text = price
Catch ex As Exception
' Show an error message if the request failed
MessageBox.Show("Error: " & ex.Message)
End Try
Valora esta pregunta


0