I was testing the example by microsoft https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/geocoding
This code should give me a simple output (result = (47.6406099647284,-122.129339994863))
However I get an out of range exception on result.Locations(0). So I dont get any locations in my result.
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim addressToGeocode As String = "Microsoft"
Dim queryHint As New BasicGeoposition With {.Latitude = 47.643, .Longitude = -122.131}
Dim hintPoint As New Geopoint(queryHint)
Dim result As MapLocationFinderResult = Await MapLocationFinder.FindLocationsAsync(addressToGeocode, hintPoint, 3)
If result.Status = MapLocationFinderStatus.Success Then
Dim test = result.Locations(0)
Label1.Text = $"result = ({result.Locations(0).Point.Position.Latitude},{result.Locations(0).Point.Position.Longitude})"
End If
End Sub
If I try to debug native code I get an error "MapGeocoder.pdb could not be loaded". I dont know if this causes the same trouble with the locations.
Related
Im doing exactly the same as in this question:
How can I call MapLocationFinder.FindLocationsAsync() to get the coordinates for an address without already knowing the latitude and longitude?
However my result.locations list keeps running into an error while result.status is success
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim addressToGeocode As String = "Microsoft"
Dim queryHint As New BasicGeoposition With {.Latitude = 47.643, .Longitude = -122.131}
Dim hintPoint As New Geopoint(queryHint)
Dim result As MapLocationFinderResult = Await MapLocationFinder.FindLocationsAsync(addressToGeocode, hintPoint, 3)
If result.Status = MapLocationFinderStatus.Success Then
Dim test = result.Locations(0) 'xxx
End If
End Sub
"No type information for MapGeocoder.dll"
Have you any helpful references for this?
My bot sends an embed message to a specific channel, after that it automatically ads a reaction to the message.
Examples: "😊" and "😂"
Button to send the embed: (works fine)
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim embed As New EmbedBuilder With {
.ThumbnailUrl = discord.CurrentUser.GetAvatarUrl,
.Title = "Just title.",
.Description = "Enjoy",
.Color = New Discord.Color(255, 0, 0)
}
discord.GetGuild("12345..").GetTextChannel("54321..").SendMessageAsync("", False, embed)
End Sub
Now how to make it add the two reactions after the message is sent? ("😊" and "😂")
I figured out that it could work with the message received handler, here's what I tried. (I'm not sure if it works)
Private Async Function onMsg(message As SocketMessage) As Task
If message.Source = MessageSource.Bot Then
Dim reaction As SocketReaction
Dim rMessage = CType(Await message.Channel.GetMessageAsync(message.Id), RestUserMessage)
If reaction.Emote.Name.Equals("😊") AndAlso
reaction.Emote.Name.Equals("😂")
Else
Dim my_emo1 As Emoji = ("😊")
Dim my_emo2 As Emoji = ("😀")
rMessage.AddReactionAsync(my_emo1)
rMessage.AddReactionAsync(my_emo2)
End If
End Function
Using your current code:
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim embed As New EmbedBuilder With {
.ThumbnailUrl = discord.CurrentUser.GetAvatarUrl,
.Title = "Just title.",
.Description = "Enjoy",
.Color = New Discord.Color(255, 0, 0)
}
Dim msg = Await discord.GetGuild("12345..").GetTextChannel("54321..").SendMessageAsync(embed:=embed.Build)
Dim my_emo1 As New Emoji("😊")
Dim my_emo2 As New Emoji("😀")
Await msg.AddReactionAsync(my_emo1)
Await msg.AddReactionAsync(my_emo2)
End Sub
I am trying to make a small stat checking app for Fortnite Battle Royale. The TRN Api requires a key to be sent, which I do not have a clue how to do. Thanks in advance.
Public Class Form1
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim webClient As New System.Net.WebClient
Dim Platform As String = ""
Dim UName As String = ""
Dim TRNApiKey As String = "f4d79aad-381b-4b91-87f1-2a1c2ee14cb6"
Dim fortniteStatslookup As String
Dim URL As String
Select Case cboPlatform.Text
Case = "PC"
Platform = "pc"
Case = "Xbox"
Platform = "xbl"
Case = "Playstation"
Platform = "psn"
End Select
UName = txtUName.Text
URL = "https://api.fortnitetracker.com/v1/profile/" & Platform & "/" & UName
webClient.Headers.Add("f4d79aad-381b-4b91-87f1-2a1c2ee14cb6", URL)
fortniteStatslookup = webClient.DownloadString(URL)
txtOutput.Text = fortniteStatslookup
End Sub
End Class
See: MSDN Webclient.Headers documentation
System.Net.WebClient.Headers take a key-value pair, so you will want something like:
webClient.Headers.Add("key", "f4d79aad-381b-4b91-87f1-2a1c2ee14cb6")
or
webClient.Headers.Add("APIkey", "f4d79aad-381b-4b91-87f1-2a1c2ee14cb6")
When moving the form from side to side, it gives a small lag while checking every 5 seconds (using timer) a request in JSON from a website, is there any way to prevent this problem?
Sample Image
Here is the Code
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Dim jsonName = New IO.StreamReader(DirectCast(DirectCast(Net.WebRequest.Create("https://www.googleapis.com/youtube/v3/channels?part=snippet&id=" & ChannelID & "&fields=items(id%2Csnippet(title))&key=AIzaSyA1n4M-fo2Y5NHUj0RsvXEAis3H6_lIjRg"), Net.HttpWebRequest).GetResponse, Net.HttpWebResponse).GetResponseStream)
Dim rqn As Newtonsoft.Json.Linq.JToken = Newtonsoft.Json.Linq.JObject.Parse(jsonName.ReadToEnd)
ChannelName = $"{rqn.SelectToken("items")(0)("snippet")("title")}"
Label3.Text = ChannelName
Dim json = New IO.StreamReader(DirectCast(DirectCast(Net.WebRequest.Create("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" & ChannelID & "&fields=items(statistics(subscriberCount))&key=AIzaSyA1n4M-fo2Y5NHUj0RsvXEAis3H6_lIjRg"), Net.HttpWebRequest).GetResponse, Net.HttpWebResponse).GetResponseStream)
Dim rq As Newtonsoft.Json.Linq.JToken = Newtonsoft.Json.Linq.JObject.Parse(json.ReadToEnd)
Subs = $"{Convert.ToDecimal(rq.SelectToken("items")(0)("statistics")("subscriberCount")).ToString("#,###,###")}"
Label1.Text = Subs
Catch ex As Exception
Timer1.Stop()
MessageBox.Show("Erro ao tentar Conseguir os Dados do Canal!")
End Try
End Sub
Using Asynchronous operations may solve your problem
I can't properly test the code, but as shown bellow, changing the sub to a Async Sub and changing GetResponse to GetResponseAsync adding the await keword should do it.
Private Async Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Dim jsonName = New IO.StreamReader(DirectCast(Await DirectCast(Net.WebRequest.Create("https://www.googleapis.com/youtube/v3/channels?part=snippet&id=" & ChannelID & "&fields=items(id%2Csnippet(title))&key=AIzaSyA1n4M-fo2Y5NHUj0RsvXEAis3H6_lIjRg"), Net.HttpWebRequest).GetResponseAsync, Net.HttpWebResponse).GetResponseStream)
Dim rqn As Newtonsoft.Json.Linq.JToken = Newtonsoft.Json.Linq.JObject.Parse(jsonName.ReadToEnd)
ChannelName = $"{rqn.SelectToken("items")(0)("snippet")("title")}"
Label3.Text = ChannelName
Dim json = New IO.StreamReader(DirectCast(Await DirectCast(Net.WebRequest.Create("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" & ChannelID & "&fields=items(statistics(subscriberCount))&key=AIzaSyA1n4M-fo2Y5NHUj0RsvXEAis3H6_lIjRg"), Net.HttpWebRequest).GetResponseAsync, Net.HttpWebResponse).GetResponseStream)
Dim rq As Newtonsoft.Json.Linq.JToken = Newtonsoft.Json.Linq.JObject.Parse(json.ReadToEnd)
Subs = $"{Convert.ToDecimal(rq.SelectToken("items")(0)("statistics")("subscriberCount")).ToString("#,###,###")}"
Label1.Text = Subs
Catch ex As Exception
Timer1.Stop()
MessageBox.Show("Erro ao tentar Conseguir os Dados do Canal!")
End Try
End Sub
Using Microsoft.AspNet.Identity i have almost all I need to manage the users problems, but I ( a vb.net beginner) can't update this code to automatically sign in the user when he confirm the email address.
I think I need a method to get ApplicationUser just based on UsedId
This is the code I try to change:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim code As String = IdentityHelper.GetCodeFromRequest(Request)
Dim userId As String = IdentityHelper.GetUserIdFromRequest(Request)
If code IsNot Nothing AndAlso userId IsNot Nothing Then
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim result = manager.ConfirmEmail(userId, code)
If result.Succeeded Then
'>>>>>>>>login the user
successPanel.Visible = True
Return
End If
End If
successPanel.Visible = False
errorPanel.Visible = True
End Sub
In case someone else have this issue, this is the code i used
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim code As String = IdentityHelper.GetCodeFromRequest(Request)
Dim userId As String = IdentityHelper.GetUserIdFromRequest(Request)
If code IsNot Nothing AndAlso userId IsNot Nothing Then
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim result = manager.ConfirmEmail(userId, code)
If result.Succeeded Then
Try
Dim task = New UserStore(Of Sue.ApplicationUser)(Context.GetOwinContext().[Get](Of ApplicationDbContext)()).FindByIdAsync(userId)
Dim user = task.Result()
Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)()
signInManager.SignIn(user, isPersistent:=False, rememberBrowser:=False)
Context.Response.Redirect("/Account/UserData", False)
Catch ex As Exception
successPanel.Visible = False
errorPanel.Visible = True
Return
End Try
End If
End If
successPanel.Visible = False
errorPanel.Visible = True
End Sub