CallByName Error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: CallByName Error

  1. #1
    Join Date
    Dec 2013
    Posts
    2

    CallByName Error

    The following code is an example of what returns me "Index was outside the bounds of the array."

    Imports System
    Imports System.Reflection
    Imports Microsoft.VisualBasic.CallType

    Public Class Form2
    Dim cityAmount As Integer
    Dim city1 As String
    Dim city2 As String
    Dim city3 As String
    Dim city4 As String
    Dim city5 As String

    Sub Example()

    For cityCount As Integer = 1 To cityAmount

    System.IO.File.Create(Application.StartupPath & "\Save\city" & cityCount & ".txt").Dispose()
    Dim Lines() As String = System.IO.File.ReadAllLines(Application.StartupPath & "\Save\city" & cityCount & ".txt")

    Lines(0) = CallByName(Me, "city" & cityCount, [Get])

    Next
    End Sub
    End Class


    Everything already has a value unlike they do in this example code.
    The code gets to " Lines(0) = CallByName(Me, "city" & cityCount, [Get])" when it throws me the error.
    The code still does not work when I change the ProcName to "city" & cityCount.ToString
    What i'm trying to do is get the name of the city (which is already declared and equals a certain string) based off of what number the city count is on. For example, if city1 = "Toronto" and the city count is at 1, I want the first line in the city().txt to equal Toronto.

  2. #2
    Join Date
    Dec 2013
    Posts
    2

    Re: CallByName Error

    Figured it out- it was mad because the text file was blank thus there were no lines to edit

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,335

    Re: CallByName Error

    A Visual Basic question in a Visual c++ forum?

    A you're figured it out can you mark the thread as resolved please.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: CallByName Error

    [ Moved thread ]
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: CallByName Error

    What is it that you are trying to do? Explain what the app is supposed to be doing
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center