error creating substring

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2005
Posts: 2
Reputation: Agent57C is an unknown quantity at this point 
Solved Threads: 0
Agent57C Agent57C is offline Offline
Newbie Poster

error creating substring

 
1
  #1
May 3rd, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: error creating substring

 
1
  #2
May 3rd, 2005
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
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 2
Reputation: Agent57C is an unknown quantity at this point 
Solved Threads: 0
Agent57C Agent57C is offline Offline
Newbie Poster

Re: error creating substring

 
0
  #3
May 3rd, 2005
Thanks I have it fixed now. My count should have been 0 to length -2 so it did not go out of the string.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: bruce2424 is an unknown quantity at this point 
Solved Threads: 0
bruce2424 bruce2424 is offline Offline
Newbie Poster

Re: error creating substring

 
0
  #4
Nov 23rd, 2008
take a look at vb.net substring in detail.

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

bruce.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC