Loop problem at runtime

  • Thread starter Thread starter jcrouse
  • Start date Start date
* "Cor Ligthert said:
As a matter of fact ,reading XML is quite simple, I use it all the time.

Sure, but what's going on behind the scenes is more compilcated.
 
It doesent really matter, the point is that reading an XML file is far more
structured and useful.

--

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

Time flies when you don't know what you're doing
 
* "Cor Ligthert said:
Sure, but what's going on behind the scenes is more compilcated.
Maybe you can ask Terry if you can buy that old commodore 64 from him,
although I thought that what he has, is the English equivalent, however that
should not give any problem for you anymore. I have you now for a half year
not seen you telling that your mistake was because of your bad English

:-)

Cor
 
I see , well done !

--

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

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

jcrouse said:
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
 
* "One Handed Man \( OHM - Terry Burns \) said:
It doesent really matter, the point is that reading an XML file is far more
structured and useful.

No!

XML is /not/ useful in all situations because it's not human-readable.
It's designed for easy processing my /machines/ and not for
edititng/reading by humans. So, INI files are far more comfortable,
they support nested data structures too, and they can be parsed easily.
 
(e-mail address removed) (Herfried K. Wagner [MVP]) wrote in
I doubt that it's easier to read. It's much more complicated to parse.

If it's in an app.config format, you can use the:

System.Configuration.ConfigurationSettings.AppSettings.Item("VariableName")

Writing to the app.config is a bit tougher as it's read only... but it's
still it's pretty straight forward : )
 
Hi Herfried,
No!

XML is /not/ useful in all situations because it's not human-readable.
It's designed for easy processing my /machines/ and not for
edititng/reading by humans. So, INI files are far more comfortable,
they support nested data structures too, and they can be parsed easily.
Because that you can read it (a computer in a humanbox) does not mean that
it is for all humans readable.

However the INI file is no W3C format while the XML format is human readable
with every browser.

And serious I have always hatted that INI format so that will never be my
favorite.

(And the first sentence just for fun)

:-)

Cor
 
jcrouse said:
CHECK YOUR CASE SENSATIVITY!.

If case sensitivity is not important in your program, Ucase/Lcase any
comparisons before hand so you'll have uniform cases.
 
Lucas,
It might be easier, and more importantly more correct, to use StrComp
instead of Ucase or Lcase to do case sensitive or case insensitive
comparisons.

In addition to StrComp and the "=" operator, there is String.Compare &
String.CompareOrdinal with overloads. String.Compare simply has more options
the StrComp otherwise its personal preference on which to use.

I would use the String.Compare for example:

Imports System.Globalization

' This is effectively what "string1.ToUpper() = string2.ToUpper()" does:
If String.Compare(string1, string2, True, CultureInfo.CurrentCulture) =
0 Then

' This will do case insensitive, culture invariant comparisons:
If String.Compare(string1, string2, True, CultureInfo.InvariantCulture)
= 0 Then


For details on comparing strings see:

http://msdn.microsoft.com/library/d...e/html/cpconsortingdataforspecificculture.asp

http://msdn.microsoft.com/library/d.../cpconculture-insensitivestringoperations.asp

http://msdn.microsoft.com/library/d.../html/cpconcustomcasemappingssortingrules.asp

http://msdn.microsoft.com/library/d...ormingculture-insensitivestringoperations.asp

Plus any sub topics of the above...

Hope this helps
Jay
 
* Lucas Tam said:
If case sensitivity is not important in your program, Ucase/Lcase any
comparisons before hand so you'll have uniform cases.

.... alternatively, you can use 'Strings.StrComp("Hello", "HELLO",
CompareMethod.Text)' to compare using "text" semantics, or you can
specify 'Option Compare Text' for the project or each source file.
 
Yes!

XML is is usefull in most situations, it IS human readable and IS easy to
navigate, there is a whole group of classes dedicated to doing just that.




--

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

Time flies when you don't know what you're doing
 
No, BBC model B ( not commodore 64 )




--

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

Time flies when you don't know what you're doing
 
* "One Handed Man \( OHM - Terry Burns \) said:
XML is is usefull in most situations, it IS human readable and IS easy to
navigate, there is a whole group of classes dedicated to doing just that.

It seems that you have decided not to be a human any more...

;-)
 
Is that the best you can come up with ?

--

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

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