Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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)
        MsgBox(myWordData)
    End If
Next
 
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
    Loop
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 4:02am
Comments
CHill60 at 30-Jan-13 10:21am
   
Include your definition of Ix and on which line does the exception get thrown
Rate this: bad
good
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
  Permalink  
Comments
Gary Heath at 30-Jan-13 10:45am
   
So simple !!! Thank you CHill60 ...
Rate this: bad
good
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.
  Permalink  
v8
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 545
1 OriginalGriff 498
2 sanket saxena 330
3 Abhinav S 280
4 thatraja 275
0 Sergey Alexandrovich Kryukov 8,372
1 OriginalGriff 4,830
2 Peter Leow 3,784
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid