Jump to content
Xtreme .Net Talk

Counting Need help figuring whats wrong with this code


Recommended Posts

Posted

Here is some code I wrote earlier today....

 

It opens a text file loads it into an Array

 

then I am counting number of chapters and number of verses in each chapter then displaying it in an rtb.

 

However, I am getting a repeating of of this for example over and over

 

this specific chapter chapter 1 has 10 verses its displaying like this in my rtb

 

1-10

1-10

1-10

 

repeating the above numerous times LOL

 

I know I am missing something simple ... but for the life of me I am not seeing why this wont work

Dim frPath As String
       Dim ReadString As String
       Dim myText As String
       Dim cntArr() As String
       frPath = "C:\Program Files\Dove Media\DoveSearch\" & fileListBox.SelectedItem
       Dim rFile As StreamReader
       Try
           If File.Exists(frPath) Then
               rFile = File.OpenText(frPath)
               ReadString = rFile.ReadToEnd()
           End If
           'rtbText.Text = ReadString
           myText = ReadString
           cntArr = Split(ReadString, vbCrLf)
       Catch
       Finally
           rFile.Close()
       End Try
       Dim x As Integer = 1
       Dim intChp As Integer
       Dim intVrs As Integer
       Dim counter As Integer
       For Each itm As String In cntArr
           If itm.StartsWith(x) Then
               counter = counter + 1
               intVrs = counter
               displayText.Text = x & "-" & intVrs
           Else
               displayText.Text = displayText.Text & vbCrLf & x & "-" & intVrs
           End If
       Next

vbMarkO

Visual Basic 2008 Express Edition!
Posted

Update;

 

Thought I might add to my above post.....

 

What I am counting to get the verses is the number of ones or twos or threes ect ect ect the chapter numbers as my text looks like this

 

1:1: Text

1:2: Text

1:3: Text

2:1: Text

2:2: Text

2:3: Text

2:4: Text

3:1: Text

3:2: Text

and so on and on

 

By counting the number of ones I have the exact number of verses for chapter one

 

I have updated my code I am getting mixed results but not what I need so

 

I am hoping someone might know how I should count this thing

 

 

vbMarkO

Visual Basic 2008 Express Edition!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...