-
December 16th, 2013, 10:30 PM
#1
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.
-
December 16th, 2013, 10:49 PM
#2
Re: CallByName Error
Figured it out- it was mad because the text file was blank thus there were no lines to edit
-
December 17th, 2013, 11:30 AM
#3
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)
-
December 20th, 2013, 03:43 AM
#4
-
December 21st, 2013, 06:25 PM
#5
Re: CallByName Error
What is it that you are trying to do? Explain what the app is supposed to be doing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|