Unsure of how to send an api auth key in vb - vb.net

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")

Related

maplocationsfinder.findlocationsasync trouble

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?

Log in form and store username/passwords in a file in aray structure

Currently my code is:
Public Structure
Dim Username as String
Dim Password as String
Dim Read() As String = IO.File.ReadAllLines("Passwords.txt")
Dim PassArray(Read.Length - 1) As Account
For i = 0 To PassArray.Length - 1
Dim line() = Split(Read(i), ","c)
PassArray(i).Username = line(0)
PassArray(i).password = line(1)
Next
If PassArray(0).Username = txtUsername.Text Then
If PassArray(1).password = txtPassword.Text Then
Form1.Show()
End If
Else
MsgBox("Wrong Username or Password!")
End If
I get an 'index outside the bounds of the array at PassArray(i).password = line(1)
I think i may have structured this wrong
the test file looks like:
Username
Password
Try this, If you doesn't work, let me know and i will do my best to help you out :)
Imports System.IO
Public Class Form1
Public Structure info
Dim Username As String
Dim Password As String
End Structure
Dim details As info
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = details.Username And TextBox2.Text = details.Password Then
MessageBox.Show("Correct!")
Form2.Show()
Me.hide()
Else
MessageBox.Show("wrong")
Textbox1.Clear()
Textbox2.Clear()
End If
End Sub
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim FILE = System.IO.File.ReadAllLines("Passwords.txt")
Dim myArray As String() = FILE
details.Username = myArray(0)
details.Password = myArray(1)
End Sub
End Class
You don't have to use the Structure, but I included it because it was a part of your question. Happy Coding!

Login the user when he confirms the email address

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

DownloadStringAsync to get a text string?

I am trying to create a Windows Phone 7.1 application, basically a currency converter. I am using DownloadStringAsync method to get a short string containing the exchange rate from a specific website. I tested in Visual Studio 2010, DownloadString worked just fine. But not for the phone application. What do I need to do here? I can't really make much sense of it.
Partial Public Class MainPage
Inherits PhoneApplicationPage
Dim webClient As New System.Net.WebClient
Dim a As String
Dim b As String
Dim result As String = Nothing
' Constructor
Public Sub New()
InitializeComponent()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
a = "USD"
b = "GBP"
webClient = New WebClient
Dim result As String = webClient.DownloadStringAsync(New Uri("http://rate-exchange.appspot.com/currency?from=" + a + "&to=" + b) as String)
TextBox1.Text = result
End Sub
End Class
A few things wrong here:
DownloadStringAsync does not return a value (void method in C# terms)
You need to handle the DownloadStringCompleted event for WebClient variable. You can get the result in the event handler.
You can change your code to something like this to get the above to work:
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
a = "USD"
b = "GBP"
webClient = New WebClient
'Add the event handler here
AddHandler webClient.DownloadStringCompleted, AddressOf webClient_DownloadStringCompleted
Dim url As String = "http://rate-exchange.appspot.com/currency?from=" & a & "&to=" & b
webClient.DownloadStringAsync(New Uri(url))
End Sub
Private Sub webClient_DownloadStringCompleted(ByVal sender as Object,ByVal e as DownloadStringCompletedEventArgs)
TextBox1.Text = e.result
End Sub
Just use DownloadStringTaskAsync:
Using WebClient As WebClient = New WebClient
Return Await WebClient.DownloadStringTaskAsync(New Uri(myurl))
End Using

Variable 'details' is used before it has been assigned a value.

Variable details is used before it has been assigned a value. What is the problem with details?
Option Explicit On
Imports System.Text
Imports System.IO
Public Class Main
Private SelectedItem As ListViewItem
Dim data As String
Dim strpriority As String
Dim task As String
Dim createdate As String
Dim duedate As String
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
AddTask.Show()
Me.Hide()
End Sub
Private Sub HistoryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HistoryToolStripMenuItem.Click
History.Show()
Me.Hide()
End Sub
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fpath As String
Dim splitdata
fpath = AppDomain.CurrentDomain.BaseDirectory
Dim filepath As String
filepath = fpath & "task.txt"
Dim details As String
details = My.Computer.FileSystem.ReadAllText(filepath)
splitdata = Split(details, vbCrLf)
Dim i As Integer
For i = 0 To UBound(splitdata)
lblTaskName.Items.Add(splitdata(i))
Next
lblTime.Enabled = True
Timer1.Interval = 10
Timer1.Enabled = True
lblDate.Text = DateTime.Now.ToString("dd MMMM yyyy")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblTime.Text = TimeOfDay
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
If lblTaskName.SelectedItem = "" Then
MsgBox("Please select a record")
Else
If lblTaskName.Items.Count > 0 Then
If MessageBox.Show("Do you really want to delete this record?", "Delete", MessageBoxButtons.YesNo) = MsgBoxResult.Yes Then
lblTaskName.Items.Remove(lblTaskName.SelectedItem.ToString())
Else
MessageBox.Show("Operation Cancelled")
End If
End If
End If
Try
Dim fpath As String
fpath = AppDomain.CurrentDomain.BaseDirectory
Dim filepath As String
filepath = fpath & "task.txt"
Dim details As String
If lblTaskName.Items.Count > 0 Then
details = lblTaskName.Items(0)
Dim i As Integer
For i = 1 To lblTaskName.Items.Count - 1
details = details & vbCrLf & lblTaskName.Items(i)
Next
End If
My.Computer.FileSystem.WriteAllText(filepath, details, False)
Catch ex As Exception
MsgBox("Values Can't be inserted this time")
End Try
End Sub
Private Function filepaths() As String
Throw New NotImplementedException
End Function
End Class
The problem is in the btnRemove_Click method in this part:
Dim details As String
If lblTaskName.Items.Count > 0 Then
details = lblTaskName.Items(0)
If the condition evaluates to false, the details variable is used before it is initialized, because it is only set in the if block up to now.
I suppose you want to move the following line into the if block to solve the problem:
My.Computer.FileSystem.WriteAllText(filepath, details, False)
Alternatively, you can come up with a default value for details so that it is set in any case. For performance reasons, you can set the default value (e.g. a text or String.Empty) in an else branch:
Dim details As String
If lblTaskName.Items.Count > 0 Then
' ...
Else
details = "Default Value"
End If
You need to think through the flow of your program. Consider this code:
Dim details As String
If lblTaskName.Items.Count > 0 Then
details = lblTaskName.Items(0)
Dim i As Integer
For i = 1 To lblTaskName.Items.Count - 1
details = details & vbCrLf & lblTaskName.Items(i)
Next
End If
My.Computer.FileSystem.WriteAllText(filepath, details, False)
You declare the details variable at the top. Then you check that there is at least 1 item in the lblTaskName control. If that test passes, then you assign the first item to details. But what if that test doesn't pass? What if there are 0 items in the lblTaskName control? In that case, the interior of the If block never runs, and nothing ever gets stored in details. Then in the final line, you try to use the value of the details variable *outside of the If block. This is illegal because it may not have been assigned a value.
Perhaps you meant for that WriteAllText line to be inside of If block? Otherwise, you'll need to add an Else clause to your If statement to handle the case where there are 0 items in lblTaskName.
Aside from that, stylistically speaking, you should prefer to initialize variables at the time of declaration whenever possible. So for example, instead of writing:
Dim fpath As String
Dim splitdata
fpath = AppDomain.CurrentDomain.BaseDirectory
Dim filepath As String
filepath = fpath & "task.txt"
Dim details As String
details = My.Computer.FileSystem.ReadAllText(filepath)
splitdata = Split(details, vbCrLf)
write it as:
Dim fpath As String = AppDomain.CurrentDomain.BaseDirectory
Dim filepath As String = fpath & "task.txt"
Dim details As String = My.Computer.FileSystem.ReadAllText(filepath)
Dim splitdata() As String = Split(details, vbCrLf)
(I'm OCD, so I line up my equals signs. That part is totally optional.)
It doesn't make the code run any faster, but it does make it easier to read! More importantly, it decreases the potential for bugs.