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
    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
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: CallByName Error

    [ Moved thread ]
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
  •  





Click Here to Expand Forum to Full Width

Featured