Jump to content
Xtreme .Net Talk

For Next results arent coming out right what am I missing


Recommended Posts

Posted

Here is my code

 

what I am trying to do is manipulate strings with an array

 

like this

 

chpArr() contains a smaple of the following text

 

1-10

2-29

3-24

4-21

5-21

This represents the Book of 1 John

where chapter 1 has 10 verses and 2 - 29 verses and so on

 

with my code I am wanting to get the verses

 

my problem with what I was trying is that with the single digit chapters it worked great but with 10 and above NOPE

 

I know its because of how I was trying to trim and such

 

Help appreciated

 

Heres the code

Dim vrs1 As String
       verseCombo.Items.Clear()
       If verseCombo.Items.Count <= -1 Then
           MsgBox("You must first choose a Book and chapter first!!!")
           Return
       Else

           For i As Integer = 1 To UBound(chpArr) + 1 ' chpArr has count of chapters so in the case of the above example 1 John there would be only 5
' with the five it worked fine but add one of the larger books it doesnt
               If chapCombo.Text = i Then
                   vrs1 = chpArr(i - 1).Trim("-")
                   vrs1 = vrs1.Substring(1) 

                   For iv As Integer = 1 To vrs1
                       verseCombo.Items.Add(iv)
                   Next


               End If
           Next
       End If

 

vbLarKO

Visual Basic 2008 Express Edition!
  • Administrators
Posted

One possible problem is the line

vrs1 = vrs1.Substring(1) 

that will only work with single numbers, you will need to take into account the length of the string version of the chapter number.

Try something like

vrs1=vrs1.Substring(i.ToString().Length)

haven't tested it but it should be close to what you need.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

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...