| | |
error creating substring
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2005
Posts: 2
Reputation:
Solved Threads: 0
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
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
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
•
•
Join Date: Jun 2008
Posts: 23
Reputation:
Solved Threads: 0
take a look at vb.net substring in detail.
http://vb.net-informations.com/strin..._Substring.htm
bruce.
http://vb.net-informations.com/strin..._Substring.htm
bruce.
![]() |
Similar Threads
- Error in creating ODBC connection."Reason: Not assosiated with a trusted SQL Server" (ASP)
- Error creating new ASP.Net project (ASP.NET)
- Error listing files... (C++)
- Error Creating Folder message during installation (OS X)
Other Threads in the VB.NET Forum
- Previous Thread: help with array please
- Next Thread: i nee the hangaroo vb.net code
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account array basic beginner bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel fade file-dialog filter forms ftp generatetags google hardcopy html images input insert intel internet mobile monitor ms net networking objects open output panel passingparameters pdf picturebox picturebox1 port position print printing problem save searchbox searchvb.net select serial settings shutdown soap sqlserver survey table tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet view visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year






