Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I've made a serial number activation program which tries to find a *.txt file in my hard drive location C:\try. If it locates the file that it's name is the which contains the text from the serial number textbox. The problem is that on the 9th line I take this exception: AmbiguousMatchException occurred. The parameter value cannot be converted to from 'ReadAllCollection(OfString to 'Char'. Can someone please help? Below you see the code:
VB
Public Class Form1

    Private Sub UnlockButton_Click(sender As Object, e As EventArgs) Handles UnlockButton.Click

        Dim SearchThere As Object = My.Computer.FileSystem.GetDirectories("C:\try")
        Dim SearchWithinThis As String = SerialNumber.Text
        Dim SearchForThis As String = SerialNumber.Text
        Dim FirstCharacter As String = SearchWithinThis.IndexOf(SearchForThis)
        Dim Location As Integer = FirstCharacter.IndexOf(SearchThere) 'here is the problem

        Dim todaysdate As String = String.Format("{0:dd/MM/yyyy}", DateTime.Now)
        If SerialNumber.Text = My.Computer.FileSystem.ReadAllText(Location) Then
            Form2.Show()
            My.Computer.FileSystem.WriteAllText(Location, Environment.NewLine, True)
            My.Computer.FileSystem.WriteAllText(Location, "successful access:",True)
            My.Computer.FileSystem.WriteAllText(Location, Space(2), True)
            My.Computer.FileSystem.WriteAllText(Location, todaysdate, True)
            My.Computer.FileSystem.WriteAllText(Location, Space(1), True)
            My.Computer.FileSystem.WriteAllText(Location, TimeOfDay, True)
        Else
            Form3.Show()
            My.Computer.FileSystem.WriteAllText(Location, Environment.NewLine, True)
            My.Computer.FileSystem.WriteAllText(Location, "access denied:", True)
            My.Computer.FileSystem.WriteAllText(Location, Space(2), True)
            My.Computer.FileSystem.WriteAllText(Location, todaysdate, True)
            My.Computer.FileSystem.WriteAllText(Location, Space(1), True)
            My.Computer.FileSystem.WriteAllText(Location, TimeOfDay, True)
        End If
    End Sub
End Class

Please can you help me?
That is experimental. My real goal is to make the program connect to my website and take the *.txt files from I use this code:
VB
Dim URL As String = "www.example.com"
       Dim request As HttpWebRequest = WebRequest.Create(URL)
       Dim response As HttpWebResponse = request.GetResponse()
       Dim reader As StreamReader = New StreamReader(response.GetResponseStream())

But I get an URI exception. If someone can help me in this too then I would be obliged.
Posted
Updated 8-Jun-13 23:33pm
v2
Comments
Member 10100038 9-Jun-13 6:16am    
Yes, thank you. Now can someone tell me what can I do to search the name of a file and if the name of the text is the same as the text in the serial number textbox, the program shows a form.
Surendra Adhikari SA 9-Jun-13 7:45am    
did you want to compare string of serial.text with the name of text file within the folder c:\try\ ??
Member 10100038 9-Jun-13 8:09am    
I want to compare the text of the serialnumber textbox with the filename of the text and if they are the same, the form of the real program will open

1 solution

GetDirectories returns a collection of strings: you can't use that to search for a character instance!
And that is ignoring that you are searching for the index of a string, within the same string,
VB
Dim SearchWithinThis As String = SerialNumber.Text
Dim SearchForThis As String = SerialNumber.Text
Dim FirstCharacter As String = SearchWithinThis.IndexOf(SearchForThis)

which returns an integer value which will always be zero.
And you then try to search within that (as a string) to find where in the string value "0" a collection of strings is located!

Stop what you are doing, go back to the start, and think about what you are trying to achieve - because I have absolutely no idea what that is, but I am damn sure that you aren't going to get anywhere near it like that!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900