-1

can you help its say's (Function 'Start' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.)

Private Function Start() As Object
    Dim thr As Integer = TextBox4.Text
    Dim Threading As Integer = Nothing
    If CheckBox1.Checked = True Then
        Threading = thr + 300
    Else
        Threading = thr
    End If
    While Not stopp
        Try
            Try
                Dim i As String = Geting("https://i.instagram.com/api/v1/users/search?q=" & TextBox5.Text & "&access_token=" & Guid.NewGuid.ToString.ToUpper & "/")
                If i.Contains("""username"": """ & TextBox5.Text & """") Or Nothing Then
                    intt += 1
                    Me.Invoke(Sub() TextBox3.Text = intt)
                Else
                    If ChangeUserName(TextBox5.Text) Then
                        Me.Invoke(Sub() Label1.Text = "username claimed " & TextBox5.Text)
                        stopp = True
                    End If
                End If
            Catch ex2 As Exception
            End Try
            Thread.Sleep(Threading)
        Catch ex As Exception
        End Try
    End While
End Function
PMF
  • 14,535
  • 3
  • 23
  • 49
L0N3LY
  • 1
  • 2
  • 2
    Do you know what a function is for? It is to do some work and return a result. Where in that code are you returning any result at all? Other than if an exception is thrown, there should be no way to go through a function and not hit a `Return` statement. If you don't intend to return anything then write a `Sub` rather than a `Function`. If you do intend to return something then do so with a `Return` statement and make sure that EVERY path of execution through the function leads to `Return` statement. – jmcilhinney Sep 01 '18 at 09:22
  • 4
    Possible duplicate of [Difference between Private Sub, Function and Class](https://stackoverflow.com/questions/4059537/difference-between-private-sub-function-and-class) and [What is the difference between Sub and Function in VB6?](https://stackoverflow.com/questions/10141708/what-is-the-difference-between-sub-and-function-in-vb6) – Visual Vincent Sep 01 '18 at 09:22
  • By the way, I think you'll find that that is a warning rather than an error too. Note it says "could" in the message. The point is that if you call a function and assume that it will return an object and try to use that object but it fails to hit a `Return` statement so it does not return an object then a `NullReferenceException` will result. It won't result if you don't make that assumption though, hence the warning rather than error. – jmcilhinney Sep 01 '18 at 09:37
  • `Dim thr As Integer = TextBox4.Text Dim Threading As Integer = Nothing` ? Try using `Option Strict On` - this will help debug the code as well. – AJD Sep 01 '18 at 21:33
  • @jmcilhinney: You are right: https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/error-messages/function-procedurename-doesn-t-return-a-value-on-all-code-paths. This confuses me a bit though, since it's actually an error in C# (and for good reasons, I think). – PMF Sep 02 '18 at 16:43
  • C# and VB are different languages and work differently. In VB, each function has an implicit local variable with the same name as the method and the value of that variable is returned implicitly if there is no explicit `Return` statement. C# has no equivalent to that, so C# functions don't implicitly return `null` by default while VB functions do implicitly return `Nothing` by default. That also ties into the fact that `null` can't represent value types in C# while `Nothing` can in VB. – jmcilhinney Sep 02 '18 at 16:58

1 Answers1

0

You probably don't need to return a value from your function. Change

Private Function Start() As Object

into

Private Sub Start()

As a side note, your error handling is bad.

Try
    (Do something)
Catch Exception
End Try

should never be used. It prevents you from seeing when something goes wrong (even if your code has a flaw).

PMF
  • 14,535
  • 3
  • 23
  • 49