Converting String input to array and passing to function

Error: number of indices is less than the number of dimensions in arra

Page 1 of 1

5 Replies - 3977 Views - Last Post: 14 October 2007 - 08:14 AM Rate Topic: -----

#1 grinsalot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 08-April 06

Converting String input to array and passing to function

Post icon  Posted 13 October 2007 - 11:14 AM

Hi,

I'm having trouble with the above error message. I'm converting string input from a textbox to a char array. I then pass the array to a function. The error occurs in the function call itself. I don't understand why though. I've converted the string to a char array - haven't I?

The program worked fine until I added the option strict on statement to prevent late binding. Now I have a lot of problems.
Thank you in advance for your help.

Dim romanInput As String
			romanInput = inputTextBox.Text.Trim.
			Dim array() As Char = romanInput.ToCharArray
 
 romanToArabicConversion = convertToArabicThousands(array(), j)
 
  Public Function convertToArabicThousands(ByVal array() As Array, ByRef j As Integer) As Integer
		arabicThousandsResult = 0
 
		j = 0
		
 
		With Me
			If j < array.Length Then
				Select Case array(j)
					Case Is  "M"
 
						If array.Length - j >= 4 And arabicThousandsResult <= 4000 Then
							If array(j) Is "M" And array(j + 1) Is "M" And array(j + 2) Is "M" And array(j + 3) Is "M" Then
								arabicThousandsResult = arabicThousandsResult + 4000
								j = j + 4
							End If
						End If
			 End Select
			End If
		End With
		Return arabicThousandsResult
	End Function 


Is This A Good Question/Topic? 0
  • +

Replies To: Converting String input to array and passing to function

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Converting String input to array and passing to function

Posted 13 October 2007 - 11:47 AM

In this line romanToArabicConversion = convertToArabicThousands(array(), j) where do you set the value of j.

Also, change this line romanToArabicConversion = convertToArabicThousands(array(), j) to romanToArabicConversion = convertToArabicThousands(array, j)
Was This Post Helpful? 0
  • +
  • -

#3 grinsalot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 08-April 06

Re: Converting String input to array and passing to function

Posted 13 October 2007 - 12:16 PM

View PostPsychoCoder, on 13 Oct, 2007 - 11:47 AM, said:

In this line romanToArabicConversion = convertToArabicThousands(array(), j) where do you set the value of j.

Also, change this line romanToArabicConversion = convertToArabicThousands(array(), j) to romanToArabicConversion = convertToArabicThousands(array, j)


Hi PsychoCoder,

Thank you for your post. I have declared the variable j at the top of my program, outside of any functions. Dim j as integer = 0.

Also, when I change array() to array, I receive the error message: Option Strict On disallows late binding.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Converting String input to array and passing to function

Posted 13 October 2007 - 01:34 PM

Try this

Dim j As Integer = 0
Dim romanInput As String = inputTextBox.Text.Trim.
Dim str() As Char = romanInput.ToCharArray(0, romanInput.Length)
Dim cnt As Integer = str.Length
romanToArabicConversion = convertToArabicThousands(CType(CType(str, Array), Array()), j)




You are expecting an Array() in your function, but are trying to pass it a char array, which doesn't inherit from Array(), so you need to convert it to an Array, then convert that to an Array(). This caused no errors in my IDE with Option Strict On
Was This Post Helpful? 0
  • +
  • -

#5 grinsalot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 08-April 06

Re: Converting String input to array and passing to function

Posted 14 October 2007 - 06:48 AM

View PostPsychoCoder, on 13 Oct, 2007 - 01:34 PM, said:

Try this

Dim j As Integer = 0
Dim romanInput As String = inputTextBox.Text.Trim.
Dim str() As Char = romanInput.ToCharArray(0, romanInput.Length)
Dim cnt As Integer = str.Length
romanToArabicConversion = convertToArabicThousands(CType(CType(str, Array), Array()), j)




You are expecting an Array() in your function, but are trying to pass it a char array, which doesn't inherit from Array(), so you need to convert it to an Array, then convert that to an Array(). This caused no errors in my IDE with Option Strict On



Thank you for all of your help, PsychoCoder. I learned a lot!

-grinsalot
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Converting String input to array and passing to function

Posted 14 October 2007 - 08:14 AM

No problem grinsalot, thats what we're here for :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1