I am making a library that will load UI files in which a user can customize the UI of the program.
The UI file is arranged that it is like vb code and that to set the text and location of a button the user would use the following UI code.

button1.text = "Hello My Name Is MRClark"
button1.top=10
button1.left=15

In a library that i have made to read and intrepret this code, i am encountering an error, that i send the function a strign to look for "button1.text" as it goes through all lines of the code. However, when going through step by step, even once the string that i have entered is equal to the code in the line of the file, it goes to endif, as is they were not equal.

Function GetValue(ByVal ValueToGet As String, Optional ByVal ValueAsInteger As Boolean = False)

        ValueToGet = ValueToGet.ToLower

        'UIText is defined earlier in the program and is the string of each line in the file being read.
        'LineText(X) is each line split into its parts at the = sign

        Try
            For x = 0 To 3000
                LineText = UIText(10).Split("=")
                LineText(0) = LineText(0).ToLower
                LineText(0) = LineText(0).Replace(" ", "")
                'In the following line, even if the two values are equal, it goes directly to EndIf
                If ValueToGet = LineText(0) Then 'NOT WORKING!!!! ARG!!!
                    If ValueAsInteger = True Then
                        Dim ValueToReturn As String
                        ValueToReturn = LineText(1).Replace(" ", "")
                        Return Val(ValueToReturn)
                    Else
                        Dim ValueToReturn(2) As String
                        ValueToReturn = LineText(1).Split(Chr(34))
                        Return ValueToReturn(1)
                    End If
                End If
            Next
        Catch
            Return "Value Not Found"
        End Try

    End Function

Any and all help is greatly appreciated, as i have hit a wall..
Thanks
~Matt

Please, can you be so kind to clarify:

1) Where do you define LineText as String()
2) The contents of UIText(10) you use to split
3) Why to you compare 3000 times if the UIText(10) has the ValueToGet

Thanks in advance

Please, can you be so kind to clarify:

1) Where do you define LineText as String()
2) The contents of UIText(10) you use to split
3) Why to you compare 3000 times if the UIText(10) has the ValueToGet

Thanks in advance

oops. I forgot to change the code back when from debugging, i was walking through it step by step, and insted of going thorugh 3000 times i just went to line 10, the line that i was using to compare from.

The line 10 contained "button1.text = "Hello My Name Is Matt"

and i was calling the library using

GetValue(button1.text",false)

I was just using that for myself, and should be an 'x'

LineText is assigned as a global stringarray, and a value is placed in it in another sub where a text files contents are read to it, and split at environment.newline

Just to clearly undertand:

When you call GetValue, the string passed contains or not the quotes? You show one.

The line 10 contained "button1.text = "Hello My Name Is Matt"

This means that the string starts with quote?

If you compare ["button1.text] againts [button1.text"] this will fail because the quotes.

Did you try to loop over the char to verify si some thing is wrong?

Edited 6 Years Ago by lolafuertes: n/a

The string that i pass to the function is yes in quotes, but i use the string.split(chr(34)) to split the string, so that
Text=InString.split(chr(34))
Text(0) = everything before quotes 'ignored
Text(1) = everything in quotes 'used
Text(2) = everything after quotes 'ignored

i have also tried returning the values right before the IF that is giving me the problem, and it shows me that the strings are equal, but it still skips over it. so it has something different that i am not seeing..

Yes, but you split it 'after' the compare.

Just for test purposes you can add the code in red to verify 'where' are the differences.

Function GetValue(ByVal ValueToGet As String, Optional ByVal ValueAsInteger As Boolean = False)

        ValueToGet = ValueToGet.ToLower

        'UIText is defined earlier in the program and is the string of each line in the file being read.
        'LineText(X) is each line split into its parts at the = sign

        Try
            For x = 0 To 3000
                LineText = UIText(x).Split("=")
                Dim DefinitionText as String = LineText(0).ToLower.Trim.Replace("""","")
                'In the following line, even if the two values are equal, it goes directly to EndIf
                If ValueToGet.Length = DefinitionText.Length Then
                    Dim AreEquals As Boolean = True
                    For I as Integer = 0 to ValueToGet.Length
                        If ValueToGet.Chars(I) <> DefinitionText.Chars(I) then
                            AreEquals = False
                            MsgBox "The strings are not equal at " & I.ToString
                        End If
                    Next
                Else
                    MsgBox "The strings have distinc length"
                End If
                If ValueToGet = DefinitionText Then 'NOT WORKING!!!! ARG!!!
                    If ValueAsInteger = True Then
                        Dim ValueToReturn As String
                        ValueToReturn = LineText(1).Replace(" ", "")
                        Return Val(ValueToReturn)
                    Else
                        Dim ValueToReturn(2) As String
                        ValueToReturn = LineText(1).Split(Chr(34))
                        Return ValueToReturn(1)
                    End If
                End If
            Next
        Catch
            Return "Value Not Found"
        End Try

    End Function
This article has been dead for over six months. Start a new discussion instead.