1
votes

I have an error in my VB.NET program. I have tried various casts, etc., but it just will not resolve the issue - so reluctantly I post it here to see if anyone else has a similar problem.

Error message

Error 1 Option Strict On disallows implicit conversions from 'Object' to 'String'.

Code

Private DS As New DataSet ' Languages
Function TransTxt(ByVal Frm As String, ByVal Item As String) As String

    Dim language As String
    Select Case My.Settings.Language
        Case 0 : language = "en" ' English
        Case 1 : language = "fr" ' French
        Case 2 : language = "it" ' Italian
        Case 3 : language = "sp" ' spanish
        Case 4 : language = "pt" ' portuguese
        Case 5 : language = "de" ' german
        Case 6 : language = "du" ' dutch
        Case Else : language = "en" ' English
    End Select


    Try 'ONE of these rows is the error
        Dim DR() As DataRow = DS.Tables(Frm).Select("Tag = '" & Item & "'")
        Return DR(0).Item(language) 
        Catch ex As Exception 
          Return "- error -" & Item
    End Try 
End Sub
1
A general hint for debugging: Remove the Try-Catch. Then Visual Studio will break in the line that really causes the error. In addition, you shouldn't return error messages as the return value of functions --- that's what Exceptions are for. Just let the (unexpected) Exception bubble up your function tree and only handle it at the very top level. - Heinzi
@Heinzi - this is a compile error. - Hans Passant
@Hans: Uh.. of course, right, sorry about that. I guess the comment "ONE of these rows is the error" at the beginning of the try block and the fact that the OP didn't say in which line the error occurred made me read the question sloppily. - Heinzi

1 Answers

4
votes

Return DR(0).Item(language) is my guess.

Either CAST to a STRING type or use Return DR(0).Item(language).ToString() at the end.