×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

StreamReader doesn't read

StreamReader doesn't read

StreamReader doesn't read

(OP)
Colleagues,

here's the code:

CODE --> VB

' 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" sad )...

gcStrINI remains blank!

What am I doing wrong?
Please advise!
TIA!

Regards,

Ilya

RE: StreamReader doesn't read

Hi Ilya,

my guess is the problem lies here:

Quote:

' 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 --> VB.Net

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.

RE: StreamReader doesn't read

(OP)
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

RE: StreamReader doesn't read

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:
https://www.tek-tips.com/viewthread.cfm?qid=370520

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.

RE: StreamReader doesn't read

(OP)
Yeah, the same idea.
This _SCREEN object was actually a Form, which is a class.
Thank you, colleague!

Regards,

Ilya

RE: StreamReader doesn't read

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

Yes, you could do much the same thing in VB6

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close