Variables don't hold values...

Ok,

I have a routine that reads some data from a text file,

If f <> Nil then
fp = TextInputStream.Open(f)
Do
HPrice9=fp.Readline
HPrice8=fp.Readline
HPrice7=fp.Readline
HPrice6=fp.Readline
HPrice5=fp.Readline
HPrice4=fp.Readline
HPrice3=fp.Readline
HPrice2=fp.Readline
HPrice1=fp.Readline
HPrice0=fp.Readline
LPrice9=fp.Readline

Loop Until fp.EOF
fp.close

End If

Now, after the loop I have this code:

Price0 = Val(Prices(0))
MsgBox(str(Prices(0)))
MsgBox(str(Price0))
If Val(SharesOut0) = 0 Then SharesOut0 = CommonSharesOut
MsgBox(SharesOut0)
If Val(BookValue0) = 0 Then BookValue0 = Str((Val(Assets) - Val(Liabilities)) / Val(CommonSharesOut))
MsgBox(BookValue0)
If Val(CFPS0) = 0 Then CFPS0 = CFPS1
MsgBox(CFPS0)
LPrice8=fp.Readline

Why is that this code returns either 0 or NA values, but if I put the code within the loop, I get actual numerical values for the equations??? This is all within the same method, do the variables lose value after exiting a do loop?

Depends on where your dim statements are located. If they are within the loop then the scope of the variables are within the loop. If you want the variables to be available outside the loop then you need to dim them before the loop.

I put the dim statements before the loop, at the top of the method… so they should hold their values after exiting the loop, but before exiting the method?

I don’t understand why mine seem to reset before they get to the code that does the equations…

[quote=22412:@Gary Vassalotti]I put the dim statements before the loop, at the top of the method… so they should hold their values after exiting the loop, but before exiting the method?

I don’t understand why mine seem to reset before they get to the code that does the equations…[/quote]
Can you post the whole section of code ?
I’m not sure there’s enough there to tell

It does look like you’re accessing the textInputStream object after you close it (the last line: [quote]LPrice8=fp.Readline[/quote]) which seems odd.