Click here to Skip to main content
Sign Up to vote bad
good
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:02

Comments
CHill60 - 30 Jan '13 - 10:21
Include your definition of Ix and on which line does the exception get thrown

3 solutions

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 - 30 Jan '13 - 10:45
So simple !!! Thank you CHill60 ...
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  
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 OriginalGriff 273
1 Sergey Alexandrovich Kryukov 179
2 Maciej Los 136
3 Richard MacCutchan 125
4 Tadit Dash 100
0 Sergey Alexandrovich Kryukov 10,264
1 OriginalGriff 7,917
2 CPallini 4,181
3 Rohan Leuva 3,522
4 Maciej Los 3,125


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