Boolean Flag issues

dwizzle13

New member
Joined
Dec 5, 2006
Messages
1
Programming Experience
Beginner
Hi, I need to create a program to tell the position of the letters n and r in a word w/out using indexof, so I need to use word.substring, but for finding if the letter is in the word, I was thinking of using a variable, flag, as boolean to determine if a msgbox saying are you sure you want to continue would pop up, and I have not been able to get that part correct.

With my looking for both r and n process to say t or f for the flag, it thinks I'm converting n to boolean, but n is string. Is this how to do it, thx. Please help.

VB.NET:
[COLOR=#007f00]'look at flag
[/COLOR]        [COLOR=#00007f]Do[/COLOR] [COLOR=#00007f]While[/COLOR] word.Substring(L, 1) <> "r"
            L = L + 1
            [COLOR=#00007f]If[/COLOR] word.Substring(L, 1) <> "r" [COLOR=#00007f]And[/COLOR] "n" [COLOR=#00007f]Then[/COLOR]
                flag = [COLOR=#00007f]True[/COLOR]
            [COLOR=#00007f]End[/COLOR] [COLOR=#00007f]If[/COLOR]
        [COLOR=#00007f]Loop[/COLOR]

        [COLOR=#00007f]If[/COLOR] flag = [COLOR=#00007f]False[/COLOR] [COLOR=#00007f]Then[/COLOR]
            z = [COLOR=#00007f]MsgBox[/COLOR]("the word has no r or n.  Quit? y/n", MsgBoxStyle.YesNo, "Quit?")
            [COLOR=#00007f]If[/COLOR] z = 6 [COLOR=#00007f]Then[/COLOR]
                [COLOR=#00007f]Me[/COLOR].[COLOR=#00007f]Close[/COLOR]()
            [COLOR=#00007f]End[/COLOR] [COLOR=#00007f]If[/COLOR]
        [COLOR=#00007f]End[/COLOR] If
 

lingsn

Well-known member
Joined
Nov 16, 2006
Messages
287
Programming Experience
Beginner
VB.NET:
[/COLOR]
[COLOR=#00007f]L = 0[/COLOR]
[COLOR=#00007f]Do[/COLOR] [COLOR=#00007f]While[/COLOR] L < word.length
   L = L + 1
[COLOR=#00007f]   If[/COLOR] word.Substring(L, 1) = "r" [COLOR=#00007f]or[/COLOR] word.Substring(L, 1) = "n" [COLOR=#00007f]Then[/COLOR]
      flag = [COLOR=#00007f]True[/COLOR]
[COLOR=#00007f]      exit do[/COLOR]
[COLOR=#00007f]   End[/COLOR] [COLOR=#00007f]If[/COLOR]
[COLOR=#00007f]Loop[/COLOR]
[COLOR=#00007f]
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
VB.NET:
Dim FoundLetter As Boolean = False
L = 0
Do While L <= word.Length AndAlso FoundLetter = False
  If word.Substring(L, 1) = "r" OrElse word.Substring(L, 1) = "n" Then FoundLetter = True
  L += 1
Loop
If FoundLetter = False Then
  If Messagebox.Show("The word does not contain an 'r' or an 'n'" & ControlChars.NewLine & "Quit?", "Letter Not Found", MessageboxButtons.YesNo) = DialogResult.Yes Then Me.Close()
End If
 
Top Bottom