Click here to Skip to main content
15,911,039 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionError Trying to connect to a database after restoring Pin
dilkonika22-Jun-14 11:17
dilkonika22-Jun-14 11:17 
AnswerRe: Error Trying to connect to a database after restoring Pin
Eddy Vluggen23-Jun-14 7:12
professionalEddy Vluggen23-Jun-14 7:12 
GeneralRe: Error Trying to connect to a database after restoring Pin
dilkonika23-Jun-14 8:24
dilkonika23-Jun-14 8:24 
GeneralRe: Error Trying to connect to a database after restoring Pin
Eddy Vluggen25-Jun-14 8:15
professionalEddy Vluggen25-Jun-14 8:15 
QuestionWhy does this Array.FindIndex for case insensitive return 2 not 0 Pin
QuickBooksDev21-Jun-14 4:15
QuickBooksDev21-Jun-14 4:15 
AnswerRe: Why does this Array.FindIndex for case insensitive return 2 not 0 Pin
Dave Kreskowiak21-Jun-14 5:38
mveDave Kreskowiak21-Jun-14 5:38 
GeneralRe: Why does this Array.FindIndex for case insensitive return 2 not 0 Pin
QuickBooksDev22-Jun-14 1:14
QuickBooksDev22-Jun-14 1:14 
GeneralRe: Why does this Array.FindIndex for case insensitive return 2 not 0 Pin
Dave Kreskowiak22-Jun-14 5:18
mveDave Kreskowiak22-Jun-14 5:18 
Remember, I keep emphasizing that a non-zero value evaluates to True and a zero value is False.

You're not actually understanding how the FindIndex and IndexOf methods work. FindIndex will return the first item passed to the comparator function you provide that returns True (a non-zero value).

Keeping that in mind, IndexOf returns an integer value of the index in the string where the string you're searching for is found. Zero if the term to search for is Empty(False), a value of 0 or greater if it is found (True) and -1 if it is NOT found (True!).

So, rewrite your code to break things out a bit more and step through the code in the debugger. Launch it by hitting F11, not F5, and step through the code one line at a time by hitting F11 and then hover the mouse over the variables you want to inspect the values of.
Sub Main()

        Dim i As Integer
        Dim s As String = "Aaa"
        Dim ar() As String = Split("aaa,AAA,bbb,BbB,ccc,CcC", ",")

        i = Array.FindIndex(ar, Function(x) Contains(x, s))

        Console.WriteLine("I is " & i)
    End Sub

    Private Function Contains(a As String, b As String) As Integer
        Dim returnValue As Integer = a.IndexOf(b, StringComparison.CurrentCultureIgnoreCase)
        Console.WriteLine("Searching for '{0}' in '{1}'   returning: {2}", b, a, returnValue)

        Return returnValue
    End Function


To fix this version, it's that same as before:
Sub Main()

        Dim i As Integer
        Dim s As String = "Aaa"
        Dim ar() As String = Split("aaa,AAA,bbb,BbB,ccc,CcC", ",")

        i = Array.FindIndex(ar, Function(x) Contains(x, s) = 0)

        Console.WriteLine("I is " & i)
    End Sub

    Private Function Contains(a As String, b As String) As Integer
        Dim returnValue As Integer = a.IndexOf(b, StringComparison.CurrentCultureIgnoreCase)
        Console.WriteLine("Searching for '{0}' in '{1}'   returning: {2}", b, a, returnValue)

        Return returnValue
    End Function



modified 23-Jun-14 17:16pm.

SuggestionRe: Why does this Array.FindIndex for case insensitive return 2 not 0 Pin
Richard Deeming23-Jun-14 2:16
mveRichard Deeming23-Jun-14 2:16 
GeneralRe: Why does this Array.FindIndex for case insensitive return 2 not 0 Pin
Dave Kreskowiak23-Jun-14 2:42
mveDave Kreskowiak23-Jun-14 2:42 
GeneralRe: Why does this Array.FindIndex for case insensitive return 2 not 0 Pin
Richard Deeming23-Jun-14 11:09
mveRichard Deeming23-Jun-14 11:09 
GeneralRe: Why does this Array.FindIndex for case insensitive return 2 not 0 Pin
Dave Kreskowiak23-Jun-14 11:16
mveDave Kreskowiak23-Jun-14 11:16 
QuestionIs there a TimeZoneInfo in VB.NET 2005 Pin
hansoctantan20-Jun-14 3:12
professionalhansoctantan20-Jun-14 3:12 
AnswerRe: Is there a TimeZoneInfo in VB.NET 2005 Pin
Richard Deeming20-Jun-14 4:00
mveRichard Deeming20-Jun-14 4:00 
QuestionRun Program from Within Folder Pin
Parament Technologies18-Jun-14 16:44
Parament Technologies18-Jun-14 16:44 
AnswerRe: Run Program from Within Folder Pin
Dave Kreskowiak18-Jun-14 17:32
mveDave Kreskowiak18-Jun-14 17:32 
GeneralRe: Run Program from Within Folder Pin
Parament Technologies18-Jun-14 17:45
Parament Technologies18-Jun-14 17:45 
GeneralRe: Run Program from Within Folder Pin
Dave Kreskowiak19-Jun-14 2:06
mveDave Kreskowiak19-Jun-14 2:06 
GeneralRe: Run Program from Within Folder Pin
Parament Technologies19-Jun-14 4:10
Parament Technologies19-Jun-14 4:10 
GeneralRe: Run Program from Within Folder Pin
Dave Kreskowiak19-Jun-14 4:30
mveDave Kreskowiak19-Jun-14 4:30 
GeneralRe: Run Program from Within Folder Pin
Parament Technologies19-Jun-14 5:59
Parament Technologies19-Jun-14 5:59 
GeneralRe: Run Program from Within Folder Pin
Dave Kreskowiak19-Jun-14 9:49
mveDave Kreskowiak19-Jun-14 9:49 
GeneralRe: Run Program from Within Folder Pin
Eddy Vluggen19-Jun-14 5:14
professionalEddy Vluggen19-Jun-14 5:14 
QuestionVB6 CommonDialog in WIndows 7 Pin
Liefie200017-Jun-14 6:11
Liefie200017-Jun-14 6:11 
AnswerRe: VB6 CommonDialog in WIndows 7 Pin
Eddy Vluggen17-Jun-14 7:30
professionalEddy Vluggen17-Jun-14 7:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.