Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StreamReader doesn't read 1

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
566
0
16
US
Colleagues,

here's the code:

Code:
' In the declarations section:
Dim gcStrINI As String = ""

' In the Main()
'...
' Read the INI file's contents
Dim loStreamReader As StreamReader = New StreamReader(lcFullPath2FileINI)
gcStrINI = loStreamReader.ReadToEnd()
'...

The INI file is present, and it's not blank. But (there's always a "But" :-( )...

gcStrINI remains blank!

What am I doing wrong?
Please advise!
TIA!

Regards,

Ilya
 
Hi Ilya,

my guess is the problem lies here:
' In the Main()

Meaning: your gcStrINI="" and your gcStrINI = loStreamReader.ReadToEnd() are not in the same scope and therefore two different variables, albeit with the same name.
Can you post a larger portion of your code?

P.S: When using a StreamReader or other disposable types (e.g. SqlCommand or similar), I usually put them in a "using" block as that makes sure streams are properly closed and the variable disposed of when no longer needed. In your case this would look like this (all within the same scope/method):
Code:
Dim gcStrINI = ""
Dim lcFullPath2FileINI = "path 2 ini"

Using loStreamReader = New StreamReader(lcFullPath2FileINI)
	gcStrINI = loStreamReader.ReadToEnd()
End Using

'check your gcStrINI  contents here

Best
MakeItSo

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Right!
Old habit: memvars declared before Main() proc. become "in scope" for entire life of the program.
Declared them Public there (yeah, yeah! Not the best practice!) and it started to work.
BTW: there is _SCREEN object in VFP to which one can add property or even object and store all one needs there instead of declaring 'em all PUBLIC.
Is there equivalent in the VB? (Recon there was none of the sort in VB6...)

Regards,

Ilya
 
Hi Ilya,

Sounds like you are thinking of a class.
Take a look at the following. It is C# but then again that is also .Net and can easily be converted/translated into VB.Net:
[URL unfurl="true"]https://www.tek-tips.com/viewthread.cfm?qid=370520[/url]

Hope this helps.

MakeItSo

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Yeah, the same idea.
This _SCREEN object was actually a Form, which is a class.
Thank you, colleague!

Regards,

Ilya
 
>Recon there was none of the sort in VB6...

Yes, you could do much the same thing in VB6

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top