CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2013

    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])

    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

    Re: CallByName Error

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

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.4)

  4. #4
    Join Date
    Feb 2003
    Iasi - Romania

    Re: CallByName Error

    [ Moved thread ]
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: CallByName Error

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

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.