Click here to Skip to main content
13,290,261 members (54,647 online)
Rate this:
Please Sign up or sign in to vote.
See more:
As per the Subject, that is what I want to do.

I am experimenting here, so I know the code is not perfect & may not even work at all, but I am working on it bit by bit and at the moment I just need to get the Index value into the Function

I have a Loop as follows ...

For Ix = 0 To myArrayLen - 1
    If myXml1.Value.Chars(Ix) = "Y" Then
        myWordData = GetNewsletterHeader(Ix)
    End If

and a Function as follows ...

Function GetNewsletterHeader(ByRef Ix As Int16) As String
    Dim myXml2 As XmlTextReader = New XmlTextReader(myDataFolder + "NewsLetter Items.xml")
    myItem = "Item" + Ix
    Do While (myXml2.Read())
        If myXml2.IsStartElement() Then
            If myXml2.Name = myItem Then
                GetNewsletterHeader = myXml2.Value.ToString
            End If
        End If
End Function

It currently throws an exception "Conversion from string "Item" to type 'Double' is not valid.", presumably because the Ix is a pointer rather than a real value.
Posted 30-Jan-13 5:02am
CHill60 30-Jan-13 10:21am
Include your definition of Ix and on which line does the exception get thrown
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

1. Remove the ByRef and replace with ByVal.
Function GetNewsletterHeader(ByVal Ix As Int16) As String

2. Ensure that Ix is declared as Int16 in the scope of the For..Next loop

3. In the Function GetNewsLetterHeader, add the following line
Dim myItem as string

4. Change the assignment to myItem to
myItem = "Item" & Ix.ToString

5. Add the following line as the very first line of the Visual Studio document file that contains this code
Option Strict

6. Let us know which line gets the error and what the Visual Studio Debugger displays for the values of the variables that are involved in the error.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Ok, the exception is particularly nicely worded and you wouldn't get the problem with C# but the problem is with
myItem = "Item" + Ix

You should be using
myItem = "Item" + Ix.ToString
Gary Heath 30-Jan-13 10:45am
So simple !!! Thank you CHill60 ...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You don't show your declaration of myItem, but I assume it is something like:
Dim myItem as Double
Since the compiler error is talking about converting a string constant "Item" to a double, and why it can't do it. Since Ix is an Int16, myItem must be a double.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100