Answered by:
Getting error: Overload resolution failed because no accessible 'Substring' accepts this number of arguments.

Question
-
User-1995349159 posted
Dear Forum
I am trying to make it so users can select more than one checkbox and search a table for all the selected options.
Any idea where I am going wrong on this?Thank you for your help. I totally appreciate it.
Jeff
Here is the error I am getting:Compiler Error Message: BC30516: Overload resolution failed because no accessible 'Substring' accepts this number of arguments.
Source Error:Line 77: Line 78: If chkboxes.length = 1 Then Line 79: inStatement= inStatement.Substring Line 80: end if Line 81: Instatement = instatement &')'
Here is my main code:
Dim chkboxes (5) As Integer
If bedroom1.checked = true
chkboxes (0)=1
end ifIf bedroom2.checked=true
chkboxes (1)=2
end ifDim inStatement As String
inStatement = "("For i As Integer = 1 To 100
If chkboxes(i)<>0 Then
'If chkboxes (i) Is Not Nothing Then
inStatement = inStatement & chkboxes (i)
end if
NextIf chkboxes.length = 1 Then
inStatement= inStatement.Substring
end if
instatement = instatement &')'
Next;Substring (0. instatement length -1)
The part of the code that queries the database:
dim SqlCmd as new StringBuilder() SqlCmd.Append("SELECT * FROM plans WHERE Planname LIKE '" & Plannametext & "' AND Sqrft >= '" & Sqrftminint & "' AND Sqrft <= '" & Sqrftmaxint & "' AND Wide <= '" & Wideint & "' AND Deep <= '" & Deepint & "' AND Bedrooms in ('2','4')' AND Floors = '" & Floorsint & "' AND Garages >= '" & Garagesminint & "' AND Garages <= '" & Garagesmaxint & "' AND Alleyfront = '" & Alleyfrontint & "' AND Baths >= '" & Bathstext & "' ")Thursday, October 16, 2014 2:31 PM
Answers
-
User-1360095595 posted
String.SubString() expects at least one parameter: http://msdn.microsoft.com/en-us/library/system.string.substring(v=vs.110).aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 17, 2014 3:27 AM -
User1918509225 posted
Hi jeffwood,
The issue that you didn't set a parameter to the Substring method.
You need to use it like below:
string a="xxxxxxx"; string s=a.SubString(2);
Here is a working demo for you:
http://msdn.microsoft.com/en-us/library/hxthx5h6(v=vs.110).aspx
Best Regards,
Kevin Shen.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 17, 2014 3:54 AM
All replies
-
User-1360095595 posted
String.SubString() expects at least one parameter: http://msdn.microsoft.com/en-us/library/system.string.substring(v=vs.110).aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 17, 2014 3:27 AM -
User1918509225 posted
Hi jeffwood,
The issue that you didn't set a parameter to the Substring method.
You need to use it like below:
string a="xxxxxxx"; string s=a.SubString(2);
Here is a working demo for you:
http://msdn.microsoft.com/en-us/library/hxthx5h6(v=vs.110).aspx
Best Regards,
Kevin Shen.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 17, 2014 3:54 AM -
User-1995349159 posted
Thanks for your help.
Here is the adjusted code that we came up with that makes it work:
Dim chkboxes (5) As Integer
If bedroom1.checked = true chkboxes (0)=1 end if
If bedroom2.checked=true chkboxes (1)=2 end if
If bedroom3.checked = true chkboxes (2)=3 end if
If bedroom4.checked=true chkboxes (3)=4 end if
If bedroom5.checked=true chkboxes (4)=5 end if
Dim inStatement As String inStatement = "("
For i as integer =0 to chkboxes.length -1
If chkboxes(i)<>0 Then
inStatement = inStatement & chkboxes (i) & "," end if Next
If chkboxes.length = 1 Then inStatement= inStatement.Substring(0) end if
inStatement = inStatement.Substring (0, instatement.Length -1)
inStatement = inStatement & ")"
Saturday, November 1, 2014 6:57 PM