Loop problem at runtime

J

jcrouse

Here is my code:

Dim sr1 As StreamReader = New StreamReader(Application.StartupPath &
"\Controls.ini")

strGameExists = "no"

intCheck = 0

Do

strLine = sr1.ReadLine()

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

strGameExists = "yes"

End If

Loop Until intCheck > 0 Or strLine Is Nothing

sr1.Close()

If strGameExists = "yes" Then

do something

else

do something else

End if


The code works great in the debugger. It finds the string, sets
strGameExists to "yes" and executes my code. However, at runtime it always
executes my do something else code. Am I missing something here?

Thank you,
John
 
L

Lucas Tam

jcrouse said:
Dim sr1 As StreamReader = New StreamReader(Application.StartupPath &
"\Controls.ini")

BTW, out of curiousity... any reason why you're using a .ini file instead
of an app.config file?

An app.config is in XML so it's much easier to read from.
 
O

One Handed Man \( OHM - Terry Burns \)

That doesent answer the OP's questions Lucas.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
O

One Handed Man \( OHM - Terry Burns \)

If strGameExists = "yes" Then '<<<<<<< Debug value here for strGameExists
is ?????

do something

else

do something else

End if


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
C

Cor Ligthert

Terry,
That doesent answer the OP's questions Lucas.

However in my opinion not forbidden to ask, this is a newsgroup meant to
learn from each other. Everybody can has a reason why he use an INI file
instead of an XML file so how more reasons you know how better it is to make
own decisions in that.

Just my thought about a newsgroup.

Cor
 
O

One Handed Man \( OHM - Terry Burns \)

Sure, I was just pointing out that some help along with the question would
have been nice !

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
O

One Handed Man \( OHM - Terry Burns \)

Actually, a better reply would have been ( And this includes mine ) along
the lines.

1.) Here is how to look at your problem/slove it.

2.) Did you know, there are several other ways to store information about
x,y,z, here they are. . .


Some text
Link

Some text
Link

Some text
Link

If you need more help, please post back to the NG


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
C

Cor Ligthert

Terry
1.) Here is how to look at your problem/slove it.

2.) Did you know, there are several other ways to store information about
x,y,z, here they are. . .
As we try to do it, however when someone has no solution however is curious
why?

Maybe he is curious for himself because everybody has told that an XML file
is better and now there is somebody who stays with the INI file so he wants
to know why, just for is own purpose.

However basicly we agree, (in what I had no doubt)

Cor
 
H

Herfried K. Wagner [MVP]

* Lucas Tam said:
BTW, out of curiousity... any reason why you're using a .ini file instead
of an app.config file?

An app.config is in XML so it's much easier to read from.

I doubt that it's easier to read. It's much more complicated to parse.
 
H

Herfried K. Wagner [MVP]

* "One Handed Man \( OHM - Terry Burns \) said:
Actually, a better reply would have been ( And this includes mine ) along
the lines.

It simply doesn't matter. Every post that adds something to the
discussion is valuable, irrespective of its completeness.
 
H

Herfried K. Wagner [MVP]

* "jcrouse said:
Dim sr1 As StreamReader = New StreamReader(Application.StartupPath &
"\Controls.ini")

Use 'System.OP.Path.Combine' to combine path and file name.
strGameExists = "no"

intCheck = 0

Do

strLine = sr1.ReadLine()

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

strGameExists = "yes"

End If

Loop Until intCheck > 0 Or strLine Is Nothing

Use 'OrElse' instead of 'Or'.

Are you sure the same file is read when running in IDE and when running
the executable file? Add a breakpoint to the line that assigns the read
string to 'strLine' and check its value there. To add a breakpoint,
clock the bar on the right side of the text-editor until a darkred
bullet appears:

| | For i = 1 To 10
|o| Foo = True
| | Next i
 
J

jcrouse

While in VB, the debug value there for strGameExists is "yes" and it
executes the proper code in the decision logic. However, after compiling it
won't go into the "yes" part of the loop, only the Else, (no) branch.

Thanks,
John

One Handed Man ( OHM - Terry Burns ) said:
If strGameExists = "yes" Then '<<<<<<< Debug value here for strGameExists
is ?????

do something

else

do something else

End if


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

jcrouse said:
Here is my code:

Dim sr1 As StreamReader = New StreamReader(Application.StartupPath &
"\Controls.ini")

strGameExists = "no"

intCheck = 0

Do

strLine = sr1.ReadLine()

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

strGameExists = "yes"

End If

Loop Until intCheck > 0 Or strLine Is Nothing

sr1.Close()

If strGameExists = "yes" Then

do something

else

do something else

End if


The code works great in the debugger. It finds the string, sets
strGameExists to "yes" and executes my code. However, at runtime it always
executes my do something else code. Am I missing something here?

Thank you,
John
 
O

One Handed Man \( OHM - Terry Burns \)

As a matter of fact ,reading XML is quite simple, I use it all the time.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
O

One Handed Man \( OHM - Terry Burns \)

OK, well you can use trace.writeline(your text) to tell you whats happening
during execution on realease code. In the realease code, is the ini file in
the executable directory ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

jcrouse said:
While in VB, the debug value there for strGameExists is "yes" and it
executes the proper code in the decision logic. However, after compiling it
won't go into the "yes" part of the loop, only the Else, (no) branch.

Thanks,
John

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
If strGameExists = "yes" Then '<<<<<<< Debug value here for strGameExists
is ?????

do something

else

do something else

End if


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

jcrouse said:
Here is my code:

Dim sr1 As StreamReader = New StreamReader(Application.StartupPath &
"\Controls.ini")

strGameExists = "no"

intCheck = 0

Do

strLine = sr1.ReadLine()

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

strGameExists = "yes"

End If

Loop Until intCheck > 0 Or strLine Is Nothing

sr1.Close()

If strGameExists = "yes" Then

do something

else

do something else

End if


The code works great in the debugger. It finds the string, sets
strGameExists to "yes" and executes my code. However, at runtime it always
executes my do something else code. Am I missing something here?

Thank you,
John
 
J

jcrouse

Yes, it is.

One Handed Man ( OHM - Terry Burns ) said:
OK, well you can use trace.writeline(your text) to tell you whats happening
during execution on realease code. In the realease code, is the ini file in
the executable directory ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

jcrouse said:
While in VB, the debug value there for strGameExists is "yes" and it
executes the proper code in the decision logic. However, after compiling it
won't go into the "yes" part of the loop, only the Else, (no) branch.

Thanks,
John

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
If strGameExists = "yes" Then '<<<<<<< Debug value here for strGameExists
is ?????

do something

else

do something else

End if


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"jcrouse" <me> wrote in message
Here is my code:

Dim sr1 As StreamReader = New StreamReader(Application.StartupPath &
"\Controls.ini")

strGameExists = "no"

intCheck = 0

Do

strLine = sr1.ReadLine()

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

strGameExists = "yes"

End If

Loop Until intCheck > 0 Or strLine Is Nothing

sr1.Close()

If strGameExists = "yes" Then

do something

else

do something else

End if


The code works great in the debugger. It finds the string, sets
strGameExists to "yes" and executes my code. However, at runtime it always
executes my do something else code. Am I missing something here?

Thank you,
John
 
C

Cor Ligthert

"Herfried K. Wagner
I doubt that it's easier to read. It's much more complicated to parse.
As a matter of fact ,reading XML is quite simple, I use it all the time.

Cor
 
G

Greg Burns

This is really no better or worse than your code, just the method I prefer
when looping through a text file.

HTH,
Greg

(untested)

' equivalent, take your pick...
Dim sr1 As StreamReader =
File.OpenText(System.IO.Path.Combine(Application.StartupPath,
"Controls.ini"))
'Dim sr1 As StreamReader = New
StreamReader(System.IO.Path.Combine(Application.StartupPath,
"Controls.ini"))

Dim bGameExists As Boolean = False
Dim strLine As String
Dim strParentName As String = "somevalue"

strLine = sr1.ReadLine()

Do While Not strLine Is Nothing

Dim intCheck As Integer = 0

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

bGameExists = True
Exit Do

End If

strLine = sr1.ReadLine()

Loop

sr1.Close()

If bGameExists = True Then

'do something

Else

'do something else

End If
 
O

One Handed Man \( OHM - Terry Burns \)

That depends where you put it

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

One Handed Man ( OHM - Terry Burns ) said:
OK, well you can use trace.writeline(your text) to tell you whats happening
during execution on realease code. In the realease code, is the ini file in
the executable directory ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

jcrouse said:
While in VB, the debug value there for strGameExists is "yes" and it
executes the proper code in the decision logic. However, after compiling it
won't go into the "yes" part of the loop, only the Else, (no) branch.

Thanks,
John

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
If strGameExists = "yes" Then '<<<<<<< Debug value here for strGameExists
is ?????

do something

else

do something else

End if


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"jcrouse" <me> wrote in message
Here is my code:

Dim sr1 As StreamReader = New StreamReader(Application.StartupPath &
"\Controls.ini")

strGameExists = "no"

intCheck = 0

Do

strLine = sr1.ReadLine()

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

strGameExists = "yes"

End If

Loop Until intCheck > 0 Or strLine Is Nothing

sr1.Close()

If strGameExists = "yes" Then

do something

else

do something else

End if


The code works great in the debugger. It finds the string, sets
strGameExists to "yes" and executes my code. However, at runtime it always
executes my do something else code. Am I missing something here?

Thank you,
John
 
O

One Handed Man \( OHM - Terry Burns \)

DUP

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
J

jcrouse

Thanks for the code Greg. I implemented it. As far as my problem goes I
figured it out and it's a little embarrassing but maybe someone else can
learn, CHECK YOUR CASE SENSATIVITY!.

Duh,
John

Greg Burns said:
This is really no better or worse than your code, just the method I prefer
when looping through a text file.

HTH,
Greg

(untested)

' equivalent, take your pick...
Dim sr1 As StreamReader =
File.OpenText(System.IO.Path.Combine(Application.StartupPath,
"Controls.ini"))
'Dim sr1 As StreamReader = New
StreamReader(System.IO.Path.Combine(Application.StartupPath,
"Controls.ini"))

Dim bGameExists As Boolean = False
Dim strLine As String
Dim strParentName As String = "somevalue"

strLine = sr1.ReadLine()

Do While Not strLine Is Nothing

Dim intCheck As Integer = 0

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

bGameExists = True
Exit Do

End If

strLine = sr1.ReadLine()

Loop

sr1.Close()

If bGameExists = True Then

'do something

Else

'do something else

End If


jcrouse said:
Here is my code:

Dim sr1 As StreamReader = New StreamReader(Application.StartupPath &
"\Controls.ini")

strGameExists = "no"

intCheck = 0

Do

strLine = sr1.ReadLine()

intCheck = InStr(strLine, "[" & strParentName & "]")

If intCheck > 0 Then

strGameExists = "yes"

End If

Loop Until intCheck > 0 Or strLine Is Nothing

sr1.Close()

If strGameExists = "yes" Then

do something

else

do something else

End if


The code works great in the debugger. It finds the string, sets
strGameExists to "yes" and executes my code. However, at runtime it always
executes my do something else code. Am I missing something here?

Thank you,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top