-
May 15th, 2019, 11:08 AM
#1
Thread Starter
Member
[RESOLVED] Function not returning values ...
This is a function I've used over and over again and it always works … except this time. Here's the code from the the Main sub calling the function:
Code:
'Write face areas
Using writer = My.Computer.FileSystem.OpenTextFileWriter("C:\users\denny\source\repos\newest atomizer 5-15-19\face areas.txt", False)
'writer.WriteLine(String.Format("jz ir r z"))
For jz = 0 To nz
For ir = 0 To nr
NbrIndex(ir, jz, nr, n, s_index, n_index, w_index, e_index, se_index, ne_index, sw_index, nw_index)
writer.WriteLine(String.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8}", jz, ir, n,
aface_west(n).ToString("E4"), aface_south(n).ToString("E4"), aface_east(n).ToString("E4"),
aface_north(n).ToString("E4"), aface_low(n).ToString("E4"), aface_high(n).ToString("E4")))
Next
Next
End Using
And here's the function itself:
Public Function NbrIndex(ir As Integer, jz As Integer, nr As Integer, n As Integer, s_index As Integer, n_index As Integer, w_index As Integer,
e_index As Integer, se_index As Integer, ne_index As Integer, sw_index As Integer, nw_index As Integer)
Dim ip1, im1, jp1, jm1 As Integer
ip1 = ir + 1
im1 = ir - 1
jp1 = jz + 1
jm1 = jz - 1
n = ir + jz * nr
Console.WriteLine("nr =", nr)
Console.WriteLine("jz =", jz)
Console.WriteLine("ir =", ir)
Console.WriteLine("n = ", n)
Console.WriteLine("Press enter to close...")
Console.ReadLine()
Return 0
s_index = ir + jm1 * nr
n_index = ir + jp1 * nr
w_index = im1 + jz * nr
e_index = ip1 + jz * nr
'southeast index
se_index = ip1 + jm1 * nr
'northeast index
ne_index = ip1 + jp1 * nr
'southwest index
sw_index = im1 + jm1 * nr
'northwest index
nw_index = im1 + jp1 * nr
End Function
Here's the console output from the run:
Code:
nr =
jz =
ir =
n =
Press enter to close...
The file is opened and written to but because n (the main array index) is always zero so is everything else. Any clue as to what's happening here?
-
May 15th, 2019, 11:21 AM
#2
Re: Function not returning values ...
If you are expecting/wanting this line:
inside of your NbrIndex function to carry the value of "n" back to your calling code, then you need to adjust your NbrIndex function's parameter definition for n to be passed ByRef.
Code:
Public Function NbrIndex(ir As Integer, jz As Integer, nr As Integer, ByRef n As Integer, ...
Edit: The same is true (need to be passed ByRef) for any other variable(s) where you want the adjusted value of the passed variables to flow back to the caller.
Last edited by OptionBase1; May 15th, 2019 at 11:25 AM.
-
May 15th, 2019, 11:27 AM
#3
Thread Starter
Member
Re: Function not returning values ...
Thank you … I will try that right away.
-
May 15th, 2019, 11:34 AM
#4
Thread Starter
Member
Re: Function not returning values ...
Can you tell me why the console isn't displaying the variables I asked for?
-
May 15th, 2019, 11:39 AM
#5
Re: Function not returning values ...
Code:
Console.WriteLine("nr =" & nr)
Edit: Or this:
Code:
Console.WriteLine("nr = {0}", nr)
https://docs.microsoft.com/en-us/dot...tframework-4.8
Last edited by OptionBase1; May 15th, 2019 at 11:54 AM.
-
May 15th, 2019, 11:53 AM
#6
Thread Starter
Member
Re: Function not returning values ...
If I eliminate the " " it writes a value. How would I include the identifying string?
-
May 15th, 2019, 11:58 AM
#7
Re: Function not returning values ...
I think it wants a string, and you're giving it a number.
Try nr.ToString() instead of nr.
Also, string interpolation should work:
Console.WriteLine($"nr = {nr}")
Last edited by passel; May 15th, 2019 at 12:06 PM.
-
May 15th, 2019, 02:00 PM
#8
Thread Starter
Member
Re: Function not returning values ...
Got it working! Thanks folks!
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
|