943,589 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 7556
  • VB.NET RSS
May 3rd, 2005
1

error creating substring

Expand Post »
an error is found on line: letters = input.Substring((count), 2)
it says that the index must be within the string
I don't see why it is an error can anyone help?


Function DigramCount(ByVal input As String)
'takes two charcters at a time out of input
'string and determines their frequencies
'and displays them in Digrams listbox

Dim count As Integer 'count is position in string
Dim length As Integer 'length of input string
Dim letter1 As Char '1st character of letters string
Dim letter2 As Char '2nd character of letters string
Dim digram(58, 58) As Integer 'array for charcters 32 to 90
Dim row As Integer 'row index for digram array
Dim column As Integer 'column index for digram array
Dim letters As String 'substring of input string

'adds spaces to end and beginning of input string
input = " " & input & " "

length = input.Length
count = 0

'steps through input string one position at a time
'and finds frequencies of digrams
For count = 0 To (length - 1)
letters = input.Substring((count), 2)
letter1 = CChar(letters.Substring(0, 1))
letter2 = CChar(letters.Substring(1, 1))
arrangeLetters(letter1, letter2)
row = ((AscW(letter1)) - 32)
column = ((AscW(letter2)) - 32)
If ((row >= 0) And (row <= 58)) Then
If ((column >= 0) And (column <= 58)) Then
digram(row, column) = 1 + digram(row, column)
End If
End If
Next count

'takes the digramArray and displays combinations
'and count for any digram that appears at least once
For row = 0 To 58
For column = 0 To 58
If digram(row, column) >= (1) Then
lstDigrams.Items.Add((ChrW(row + 32)) & _
(ChrW(column + 32)) & ": " & digram(row, column))
End If
Next column
Next row

End Function

Function arrangeLetters(ByRef letterA As Char, ByRef letterB As _
Char) As Char
'arranges letters of digram so lowest unicode is
'displayed first ie, frequency of ZA is not
'tabulated apart from AZ

Dim temp As Char 'temp is temporary variable to
'characters

'if first letter of digram's unicode is more than
'the second swap them
If ((AscW(letterA)) > (AscW(letterB))) Then
letterA = temp
letterB = letterA
letterB = temp
End If

End Function
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Agent57C is offline Offline
2 posts
since May 2005
May 3rd, 2005
1

Re: error creating substring

I go idea is to use a msgbox or some other method to see the actual string. Say msgbox input, that will tell you exactly what the string is that you are trying to get the substring of. I'm guessing there isn't 2 or 3 characters in the string, so when you try to get 2, it doesn't exist. I could be wrong, but I don't have .NET installed to try it
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 3rd, 2005
0

Re: error creating substring

Thanks I have it fixed now. My count should have been 0 to length -2 so it did not go out of the string.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Agent57C is offline Offline
2 posts
since May 2005
Nov 23rd, 2008
0

Re: error creating substring

take a look at vb.net substring in detail.

http://vb.net-informations.com/strin..._Substring.htm

bruce.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bruce2424 is offline Offline
23 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: help with array please
Next Thread in VB.NET Forum Timeline: i nee the hangaroo vb.net code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC