Google Account Registering Bot - vb.net

thanks for spending time on my post.
I'm currently experiencing a easier way to create a Google account, and apparently there is no Google account creating bot or such thing like that, so I decided to write one my self.(Well, It's not a actual bot, it asks you to manually enter the Captcha.) Then I had a problem when setting a value of a combo box and when grabbing the captcha image to a picture box.....
Here's a part of my code(where the error occurred):
'WebBrowser1 has been navigated to "https://accounts.google.com/SignUp?continue=https:%2F%2Faccounts.google.com%2FManageAccount"
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim r As System.Random = New System.Random
'Sets the value of other textboxes
WebBrowser1.Document.GetElementById(":0").InnerText = MonthSelect(r.Next(1, 12))
WebBrowser1.Document.GetElementById(":d").InnerText = GenderSelect(r.Next(0, 1))
Captcha.ImageLocation = WebBrowser1.Document.GetElementById("recaptcha_chanllenge_image").GetAttribute("src")
End Sub
Public Function MonthSelect(mon As Integer)
'Generates a month
End Function
Public Function GenderSelect(gen As Integer)
'Generates a gender
End Function
And the NullReferenceException occurred in these 3 lines...
WebBrowser1.Document.GetElementById(":0").InnerText = MonthSelect(r.Next(1, 12))
WebBrowser1.Document.GetElementById(":d").InnerText = GenderSelect(r.Next(0, 1))
Captcha.ImageLocation = WebBrowser1.Document.GetElementById("recaptcha_chanllenge_image").GetAttribute("src")
What's wrong?

Related

VB.NET - System.AccessViolationException: 'Attempted to read or write protected memory...' Occurs sporadically when using autoCompleteSource

System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
I started getting this exception after trying to implement AutoComplete into one of my text boxes. It seems to occur somewhat sporadically? It often occurs when trying to use AutoComplete within a couple seconds of loading it's panel but has occured upwards of 5/6 seconds afterwards too. Additionally if it doesn't occur, the AutoComplete can be used endlessly without crashing.
I've had the same error occur on two different machines so I'm really unsure of what could be causing this and would be endlessly grateful if someone could point me in the right direction!
I've tried to strip out all the parts that definitely aren't causing it to save space.
This code runs first:
Private Sub btnManagerEditItem_Click(sender As Object, e As EventArgs) Handles btnManagerEditItem.Click
refreshEditItemsScreen(False) ' clears all on screen data and repopulates DataGrid
txtManagerEditItemsSearchName.AutoCompleteMode = AutoCompleteMode.SuggestAppend
txtManagerEditItemsSearchName.AutoCompleteSource = AutoCompleteSource.CustomSource
End Sub
Private Sub refreshEditItemsScreen(refreshDatabase As Boolean)
dtgrdManagerEditItems.Rows.Clear() ' DataGridView displays items to user.
If refreshDatabase Then
updateItemDatabase() ' reads the database from file and updates _itemDatabase with it
End If
For Each entry In _itemDatabase ' Global variable holding the database
dtgrdManagerEditItems.Rows.Add(entry.Name, entry.Price.ToString("c"), entry.UniqueID, getStaffDictionary(entry.StaffID))
Next
End Sub
Private Sub updateItemDatabase()
_itemDatabase = readItemDatabaseFromFile()
End Sub
Private Function readItemDatabaseFromFile() As List(Of Item)
Dim pathtofile As String = IO.Path.Combine(My.Application.Info.DirectoryPath.Substring(0, My.Application.Info.DirectoryPath.Length - 21), "Item Database.xml")
Dim itemDatabaseFromFile As New List(Of Item)
If System.IO.File.Exists(pathtofile) Then
Dim objStreamReader As New StreamReader(pathtofile)
Dim xsSerialize As New XmlSerializer(itemDatabaseFromFile.GetType)
itemDatabaseFromFile = xsSerialize.Deserialize(objStreamReader)
objStreamReader.Close()
End If
Return itemDatabaseFromFile
End Function
Then this code runs when you start typing in the AutoCorrect box:
Private Sub txtManagerEditItemsName_TextChanged(sender As Object, e As EventArgs) Handles txtManagerEditItemsSearchName.TextChanged
txtManagerEditItemsSearchName.AutoCompleteCustomSource = _autoCompleteSource
End Sub
_autoCompleteSource gets it's value when this code is ran on form load (updateItemDatabase() is also ran on form load):
Private Sub updateAutoCompleteSource()
' reads the id dictionary from file and adds it to the auto complete source
For Each Itm In readItemIDDictionaryFromFile().Keys
_autoCompleteSource.Add(Itm)
Next
End Sub
Private Function readItemIDDictionaryFromFile() As Dictionary(Of String, String)
Dim pathtofile As String = IO.Path.Combine(My.Application.Info.DirectoryPath.Substring(0, My.Application.Info.DirectoryPath.Length - 21), "ID Dictionary.txt")
Dim output As New Dictionary(Of String, String)
If File.Exists(pathtofile) Then
For Each line In IO.File.ReadAllLines(pathtofile)
Dim parts() As String = line.Split(",")
output.Add(parts(1), parts(0))
Next
Return output
End If
End Function
Sorry if some of this code was unnecessary to post, I'm pretty lost as to what's causing the error so I just posted everything that runs before it occurs that I think could be related to it.
Thank you

Storing text box input into an array and displaying it on to a list box in visual basic

What i need to do is take input 10 times from a text box, store it in an array and then display the array onto a list box.
I came up with this for loop but it doesn't work, all it does is display the first input and then the rest are just blank:
For i As Integer = 0 To 9
ArrNames(i) = txtUserInput.Text
txtUserInput.Clear()
Next i
and i have a different button to display the array and i used this:
lstDisplay.DataSource = ArrNames
can anyone help me? iv'e looked everywhere and nothing worked for me
Edit 1:
So i changed it a lot and came up with this:
Dim I As Integer
If sender Is btnEnter Then
I = I + 1
End If
ArrNames(I) = txtUserInput.Text
txtUserInput.Clear()
is what it does is if the button is pressed it increases I by one which makes it so the input goes to the right index right?
but now that i make this it stopped displaying anything at all so this:
Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnShow.Click
lstDisplay.DataSource = ArrNames
stopped working
Hopefully that I variable is declared at class level in the same place as the array.
To force the ListBox to refresh you have to set the .DataSource to Nothing and then back to your array again:
Public Class Form1
Private I As Integer
Private ArrNames(9) As String
Private Sub btnAddName_Click(sender As Object, e As EventArgs) Handles btnAddName.Click
If I < ArrNames.Length Then
If txtUserInput.Text.Trim.Length > 0 Then
ArrNames(I) = txtUserInput.Text
I = I + 1
lstDisplay.DataSource = Nothing
lstDisplay.DataSource = ArrNames
txtUserInput.Clear()
txtUserInput.Focus()
Else
MessageBox.Show("Enter a name first!")
End If
Else
MessageBox.Show("The array is full!")
End If
End Sub
End Class
I would first recommend you to use typed Lists instead of using the old fashioned array (discussions incoming.. but..).
You can also make use of the nice feature of Enumerable.Range().
I don't have my editor right now but it should look like:
Dim list = new List(Of string)
For i In Enumerable.Range(1, 10)
list.Add(txtUserInput.Text)
Next
txtUserInput.Clear()
lstDisplay.DataSource = list
If you plan to modify your list afterwards and e.g. keep it on class scope, then you should use a BindingList(Of String) which supports notifying about changes.
Edit 1:
You are calling txtUserInput.Clear() inside the loop after the first time your input has been received from the textbox. That means in each following iteration the textbox is cleared.

Variables to list box?

taking a VB class this term and I've been stumped on a problem I'm trying to figure out. We were asked to create a price calculator for movie titles at a movie rental place. Extra credit was storing them in a list and being able to print the list. I've gotten that far and now I want to go a step further and actually add titles to that list with an attached price. I figured the easiest way to do this would probably be with arrays but I don't have much experience working with arrays.
I was thinking something along the lines of storing each title(as its added) as well as the price in a variable to give a "Movie Title - $2.93" format in every line of the list box. For the sake of this problem I'm going to just post my full source code and that might make it easier to see what I'm trying to accomplish. ANY help would be MUCH appreciated. Thanks Stack overflow community!
A screenshot of my project can be viewed here: http://puu.sh/54SgI.jpg
Public Class Form1
'globablly declared because I might use them outside of btnAdd_Click event
Const decDiscount As Double = 0.9 '1-.10 discount = .9
Const decDVD As Decimal = 2D
Const decBlueray As Decimal = 2.5D
Const decDVDNew As Decimal = 3.25D
Const decBluerayNew As Decimal = 3.5D
Dim intCount As Integer
Dim decCost, decTotal As Decimal
Dim decDayTotal As Decimal
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AcceptButton = btnAdd
End Sub
Private Sub chkDiscount_Click(sender As Object, e As EventArgs) Handles chkDiscount.Click
If chkDiscount.CheckState = 1 Then
chkDiscount.Enabled = False
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
'Display error when no title entered
If txtAdd.Text = "" Then
MessageBox.Show("Please enter a movie title and select the appropriate item details.", "Complete details", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
listMovies.Items.Add(txtAdd.Text)
listMovies.SelectedIndex = listMovies.SelectedIndex + 1
End If
'update list
'clear txtbox
txtAdd.Text = ""
'Decision Statements to calculate correct price
If radDVD.Checked = True Then
decCost = CDec(decDVD.ToString("c"))
If chkNew.Checked = True Then
decCost = CDec(decDVDNew.ToString("c"))
End If
ElseIf radBlueray.Checked = True Then
decCost = CDec(decBlueray.ToString("c"))
If chkNew.Checked = True Then
decCost = CDec(decBlueray.ToString("c"))
End If
End If
If chkDiscount.Checked = True Then
decCost = CDec((decCost * decDiscount).ToString("c"))
End If
'display cost
txtCost.Text = CStr(CDec(decCost))
'calc total
decTotal = CDec(decTotal + decCost)
'display total
txtTotal.Text = CStr(CDec(decTotal))
'clear chkNew every item added to list
chkNew.CheckState = 0
End Sub
'Public so summary message box can access variable
Public Sub btnFinish_Click(sender As Object, e As EventArgs) Handles btnFinish.Click
'Add +1 to counter & update txtCounter
intCount = CInt(Val(intCount) + 1)
'add to day total
decDayTotal = CDec(Val(decDayTotal) + decTotal)
'Set Everything back to empty/enabled
chkDiscount.Enabled = True
chkDiscount.CheckState = 0
chkNew.CheckState = 0
txtAdd.Text = ""
txtCost.Text = ""
txtTotal.Text = ""
decTotal = 0
decCost = 0
'Instead of clearing radios each time, a more desirable result would be to have DVD always set back to the default checked radio
radDVD.Checked = True
radBlueray.Checked = False
listMovies.Items.Clear()
End Sub
Private Sub btnSummary_Click(sender As Object, e As EventArgs) Handles btnSummary.Click
If decTotal > 0 Then
MessageBox.Show("Please finish your current order before viewing a daily summary.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show(("Your total cutomer count is: " & intCount) + Environment.NewLine + ("Your total sales today is: $" & decDayTotal), "Daily Summary", MessageBoxButtons.OK)
End If
End Sub
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
listMovies.Items.Remove(listMovies.SelectedItem)
End Sub
I wont go very far here because you need to do the work. But, I would start with a class:
Public Class Movie
Public Title As String = ""
Public Cost As Decimal
' prevents you from adding a movie without critical info
Public Sub New(ByVal t As String, ByVal c As Decimal)
Title = t
Cost = c
End Sub
End Class
This would hold the info on one movie title rental, and keep it together (and can be added to in order to print exactly as you showed) . The plan (to the extent I understand what you are after) would be to create one of these for each movie rented and add it to a List(Of Movie) this is more appropriate than a Dictionary in this case.
To create a movie:
Dim m As New Movie(theTitle, theCost)
Things I would do:
You did a good job of declaring numerics as numbers. Fix the code that converts it to string and back to numeric. (edit your post)
You can use the Movie Class to populate the "Shopping Cart" listbox alone; at which point, listMovies.Items would BE the extra credit List. But it wouldnt hurt to use/learn about List (Of T). (BTW, does 'print' mean to paper, on a printer?)
What are you doing with chkDiscount? If they check it, you disable it (and never enable). Did you mean to disable the New Releases check? In THAT case, arent they really a pair of radios too?
Either way, CheckChanged is a better event for evaluating and there is no reason to manually set the check state for the user that happens by itself.
Check out List(of T) and HTH
A good thing to think about when doing assignments like this (particularly when learning your first language) is to think of the algorithm (the step you need to get to your goal).
1st, determine all the steps you need to get to your goal.
2nd, and I think this is the more import point for your question, figure out what order the steps need to be in (or better yet, what order they are most efficient in).
In your case I think that you are kind of ice skating up hill by adding the name of the movie to the list first, and then trying to add the price to the line later. Unless that kind of functionality was requested as part of the assignment I would require the user to enter both the name AND the price before accepting either (just like you do with the name currently). Like thus:
If txtAdd.Text <> "" AND txtCost.Text <> "" Then 'requiring both fields to not be null
''add moive code
Else
''MessageBox.Show("Yadda Yadda Yadda")
End If
I agree with Plutonix that creating a class, while overkill in your case, is a good idea, as it will give you practice for when it WILL be appropriate. Once you have that a class of Movie, you can then create lists of Movie(s) like this:
Dim MovieList as new List(of Movie)
So then, each time you press the btnAdd button, you can pass the values to a movie AND add it to the list.
Dim m As Movie
Dim MovieList as new List(of Movie)
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
'Display error when no title entered
If txtAdd.Text <> "" And txtCost.Text <> "" Then
myMovie = New Movie(txtAdd.Text, txtCost.Text)
myMovieList.Add(myMovie)
listMovies.Items.Clear()
For Each X As Movie In myMovieList
listMovies.Items.Add(X.DisplayMovie)
Next
Else
MessageBox.Show("Please enter a movie title and select the appropriate item details.", "Complete details", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
'Other Code
End Sub
Note the line ListMovies.Items.Add(X.DisplayMovie) I added a function to the class Movie (seen below) so that it will do the formatting as you suggested.
Public Function DisplayMovie()
Return Title & " - $" & Cost
End Function
This will get you much of the way. Try to extrapolate what Plutonix and myself have explained to further refine your code. For instance, try encapsulating your adjusted price calculation in its own function so you can call it from anywhere.

Visual Basic disappearing textbox?

I've looked all over the web for an answer to this, and been unable to replicate the bug myself, and somehow the textbox is appearing to be transparent and unable to be clicked; however it seems that if you set the "Text =" property to have a message in it, the textbox works fine.
I've looked at the properties and the code multiple times, nothing seems to be off. There's no calling of the textbox to be transparent, and nothing I've seen that would stop it from accepting user input.
The... "broken" code is:
Public Class GuessingGame
Const MIN As Integer = 1
Const MAX As Integer = 50
Private Sub btnCheckGuess_Click(sender As System.Object, e As System.EventArgs) Handles btnCheckGuess.Click
Randomize()
Static secretNumber As Integer = Int((MAX - MIN + 1) * Rnd() + MIN)
Static Count = 0
Dim guess As Integer
Count = Count + 1
guess = Val(Me.txtPlayerGuess.Text)
If guess < MIN Or guess > MAX Then 'invalid guess
MessageBox.Show("Guess out of range")
ElseIf guess = secretNumber Then
Me.lblMessage.Text = "You guessed it!" 'correct
MessageBox.Show(Count)
Else
Call GiveHint(secretNumber, guess)
End If
End Sub
Private Sub txtPlayerGuess_TextChanged(sender As System.Object, e As System.EventArgs)
'Clear the current answer when the user begins to type a new value
Me.lblMessage.Text = Nothing
End Sub
Private Sub GiveHint(firstNum As Integer, ByVal secondNum As Integer)
If firstNum > secondNum Then
MessageBox.Show("Too low.")
Else
MessageBox.Show("Too high.")
End If
End Sub
End Class
Anyone have any ideas as to what is causing this and how to fix it?

Community server library - issue deleting a user

I have been asked to fix a Community Server forum where thousands of users were created via a script. All of their profile pages are SEOspam for prescription drugs, etc. The forum was not using email verification or admin approval for newly registered users. I turned on the latter for now, but captcha would be nice.
My problem is that it is very cumbersome to mass delete these accounts. I set up a .net grid (Telerik Radgrid actually) so that I could mass select users and click delete. However the following code does not seem to be working (mind the VB nubbery):
Protected Sub rgUsers_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgUsers.NeedDataSource
rgUsers.DataSource = Users.GetUsers().Users()
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
For Each item As GridDataItem In rgUsers.SelectedItems
Dim selectedUserID As Integer = item.OwnerTableView.DataKeyValues(item.ItemIndex)("UserID")
Dim userToDelete As CommunityServer.Components.User = Users.GetUser(selectedUserID, False) ' User is definitely populated. '
Dim username As String = userToDelete.Username
Dim deleteStatus As DeleteUserStatus = Users.DeleteUser(User)
Trace.Write(String.Format("Delete result for user {0}: {1}", username, deleteStatus.ToString)) ' Returns enum value 3 (Success.) '
Next
rgUsers.Rebind()
End Sub
The UserDeleteStatus result returns 'Success', however the user is not actually deleted. Am i using the correct delete function? Any help is greatly appreciated, as this is sort of time sensitive (the client is not in the market for penis enlargment pills.)
The issue was that the UserDeleteStatus was actually returning 'AuthenticationRequired'