•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 374,029 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,883 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Views: 2852 | Replies: 3
![]() |
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
I have a problem with "left"syntax
when i operate it in console application, it works
but when i operate it in windows application, the left syntax is error...
this is my code, can someone check my code please
' get and validate order no
Dim strOrderNo As String = _ ValidateOrderNumber(txtOrderNumber.Text)
If strOrderNo = "" Then
MessageBox.Show("Error: Invalid Order Number")
With txtOrderNumber
.SelectAll()
.Focus()
End With
Return
End If
Private Function ValidateOrderNumber(ByRef strOrderNo As String) _ As String
strOrderNo = strOrderNo.ToUpper
If Left(strOrderNo, 2) <> "SO" Then
' returns an empty string to denote error
Return ""
End If
' return valid order no
Return strOrderNo
End Function
the description say that 'Public Property Left() As Integer' has no parameters and its return type cannot be indexed.
can someone help me please..............
thanks
when i operate it in console application, it works
but when i operate it in windows application, the left syntax is error...
this is my code, can someone check my code please
' get and validate order no
Dim strOrderNo As String = _ ValidateOrderNumber(txtOrderNumber.Text)
If strOrderNo = "" Then
MessageBox.Show("Error: Invalid Order Number")
With txtOrderNumber
.SelectAll()
.Focus()
End With
Return
End If
Private Function ValidateOrderNumber(ByRef strOrderNo As String) _ As String
strOrderNo = strOrderNo.ToUpper
If Left(strOrderNo, 2) <> "SO" Then
' returns an empty string to denote error
Return ""
End If
' return valid order no
Return strOrderNo
End Function
the description say that 'Public Property Left() As Integer' has no parameters and its return type cannot be indexed.
can someone help me please..............
thanks
•
•
Join Date: Dec 2002
Location: West Virginia
Posts: 350
Reputation:
Rep Power: 6
Solved Threads: 32
Left is no longer used in vb net. Instead of
use
The first number is the starting position and the second is the number of characters to get.
This also replaces the mid and right string operations. If the second number is omitted then all the characters from the starting place are returned.
If Left(strOrderNo, 2) <> "SO" Then
If strOrderNo.Substring(0, 2) <> "SO" Then
This also replaces the mid and right string operations. If the second number is omitted then all the characters from the starting place are returned.
Last edited by waynespangler : Apr 28th, 2007 at 9:24 am.
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
i still got the error on my program. the error is in red color font, it say that "Index and length must refer to a location within the string."
what it does mean? and can you check my coding. i want to validate the order number. the order number must be started with "SO" and then followed with 3 or 5 number. is the coding correct?
Thanks
Dim strOrderNo As String = ValidateOrderNumber(txtOrderNumber.Text)
If strOrderNo = "invalid" Then
MessageBox.Show("Error: Invalid Order Number")
With txtOrderNumber
.SelectAll()
.Focus()
End With
Return
End If
Private Function ValidateOrderNumber(ByRef strOrderNo As String) As String
strOrderNo = strOrderNo.ToUpper
If Not (Len(strOrderNo) >= 5 And Len(strOrderNo) <= 7) Then
Return "invalid"
End If
If Not (strOrderNo.Substring(0, 2)) = "SO" Then
Return "invalid"
End If
If Not (IsNumeric(strOrderNo.Substring(2, 5)) Or _
IsNumeric(strOrderNo.Substring(2, 7))) Then
Return "invalid"
End If
Return strOrderNo
End Function
what it does mean? and can you check my coding. i want to validate the order number. the order number must be started with "SO" and then followed with 3 or 5 number. is the coding correct?
Thanks
Dim strOrderNo As String = ValidateOrderNumber(txtOrderNumber.Text)
If strOrderNo = "invalid" Then
MessageBox.Show("Error: Invalid Order Number")
With txtOrderNumber
.SelectAll()
.Focus()
End With
Return
End If
Private Function ValidateOrderNumber(ByRef strOrderNo As String) As String
strOrderNo = strOrderNo.ToUpper
If Not (Len(strOrderNo) >= 5 And Len(strOrderNo) <= 7) Then
Return "invalid"
End If
If Not (strOrderNo.Substring(0, 2)) = "SO" Then
Return "invalid"
End If
If Not (IsNumeric(strOrderNo.Substring(2, 5)) Or _
IsNumeric(strOrderNo.Substring(2, 7))) Then
Return "invalid"
End If
Return strOrderNo
End Function
•
•
Join Date: Dec 2002
Location: West Virginia
Posts: 350
Reputation:
Rep Power: 6
Solved Threads: 32
Your problerm is if you have a string length of 5 and you are starting at the third position(2) and then going 5 more positions then you are past the end of your line. Same thing with length of 7.
Like vb6 if you did not give mid$ a second number it would take all the numbers from that starting position, substring does the same thing. So you do not need to check if it is 5 or 7 characters long.
One other thing in this code:
if 4 numbers are entered it will accept them. I don't know if it is a typeing error or not but you said "followed with 3 or 5 number." If so then change it to the following"
Hope this helps.
'If Not (IsNumeric(strOrderNo.Substring(2, 5)) Or _
'IsNumeric(strOrderNo.Substring(2, 7))) ThenIf Not IsNumeric(strOrderNo.Substring(2)) Then
One other thing in this code:
If Not (Len(strOrderNo) >= 5 And Len(strOrderNo) <= 7) Then
If Len(strOrderNo) <> 5 Or Len(strOrderNo) <> 7 Then
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
- IE Syntax Error and Can“t browse some sites (Viruses, Spyware and other Nasties)
- Syntax Analyser and General Java Help (Java)
- DECLARATION SYNTAX ERROR (for bc 31 user) (C++)
- C++ Syntax (C++)
Other Threads in the VB.NET Forum
- Previous Thread: Connecting to a SQL server on another XP computer
- Next Thread: add radiobutton list or checkboxes list


Linear Mode