Answered by:
Val(right) and Val(left)

Question
-
in vb 6 i am using code :
If ((Val(textbox1.text) <= 1000) And (Val(Left(textbox2.text, 1)) = 9) And (Len(Trim(textbox2.text)) = objdatareader.item("field")) Then
error at (Val(Left(textbox2.text, 1)) = 9) -----> left
how to writing code lin vb net 2005 ?
Friday, July 8, 2011 6:08 AM
Answers
-
You should use substring instead of Left. Here is the code:
If ((Val(TextBox1.Text) <= 1000) And (Val(TextBox2.Text.Substring(0, 1)) = 9) And (Len(Trim(TextBox2.Text)) = objdatareader.item("field"))) Then
Thank you.
(Previously i stated that Left is not available. I tried to meant a better approach. Left is available. So i edited my post.)
If my post answers your question then mark as answer.
- Proposed as answer by John Anthony Oliver Friday, July 8, 2011 6:25 AM
- Edited by Shaoun1000 Saturday, July 9, 2011 8:08 AM Wrong information removed.
- Marked as answer by jimbong Monday, July 11, 2011 3:05 AM
Friday, July 8, 2011 6:17 AM -
Shaoun1000,
sorry to say this, but you are not right. See:
'Visual Basic 2008 - .net 3.5 - Any CPU MsgBox(Microsoft.VisualBasic.Left("test", 1))
but you are also right to suggest the substring() method, because keeping it the Net way ( 0 based array access ) is better.Therefor i just wanted to propose your post as the answer but John had been faster ;-)
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marked as answer by jimbong Friday, July 8, 2011 6:51 AM
Friday, July 8, 2011 6:32 AM
All replies
-
in vb 6 i am using code :
If ((Val(textbox1.text) <= 1000) And (Val(Left(textbox2.text, 1)) = 9) And (Len(Trim(textbox2.text)) = objdatareader.item("field")) Then
error at (Val(Left(textbox2.text, 1)) = 9) -----> left
how to writing code lin vb net 2005 ?
- Merged by Mike Feng Monday, July 11, 2011 11:49 AM duplicate
Friday, July 8, 2011 5:49 AM -
Hi jimbong,
LEFT and RIGHT doesn't work in vb.net like vb6.
Try this:
' Left in VB.NET as a public function Public Function Left(ByVal sText As String, _ ByVal nLen As Integer) As String If nLen > sText.Length Then nLen = sText.Length Return (sText.Substring(0, nLen)) End Function
and have a look:http://msdn.microsoft.com/en-us/library/y050k1wb(vs.71).aspx
Please 'Mark as Answer' if I helped. This helps others who have the same problem!- Proposed as answer by Dennis Hemken Tuesday, July 12, 2011 4:48 AM
Friday, July 8, 2011 6:15 AM -
You should use substring instead of Left. Here is the code:
If ((Val(TextBox1.Text) <= 1000) And (Val(TextBox2.Text.Substring(0, 1)) = 9) And (Len(Trim(TextBox2.Text)) = objdatareader.item("field"))) Then
Thank you.
(Previously i stated that Left is not available. I tried to meant a better approach. Left is available. So i edited my post.)
If my post answers your question then mark as answer.
- Proposed as answer by John Anthony Oliver Friday, July 8, 2011 6:25 AM
- Edited by Shaoun1000 Saturday, July 9, 2011 8:08 AM Wrong information removed.
- Marked as answer by jimbong Monday, July 11, 2011 3:05 AM
Friday, July 8, 2011 6:17 AM -
Shaoun1000,
sorry to say this, but you are not right. See:
'Visual Basic 2008 - .net 3.5 - Any CPU MsgBox(Microsoft.VisualBasic.Left("test", 1))
but you are also right to suggest the substring() method, because keeping it the Net way ( 0 based array access ) is better.Therefor i just wanted to propose your post as the answer but John had been faster ;-)
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marked as answer by jimbong Friday, July 8, 2011 6:51 AM
Friday, July 8, 2011 6:32 AM -
jimbong,
you should use the direction Shaoun1000 had provided to get a better understanding of the .Net way. I know by going this way by myself that at the start it isn`t that easy to use .NET if you are used to use VB6, but .Net has so many advantages.
e.g. you also shouldn`t use Val() instead use e.g. Integer.TryParse(),Integer.Parse() or convert.ToInt32().
Doing your if statement like:
if condition1=true AndAlso condition2=true...
would also be better, because the second condition will be evaluated only if the first one will result in true.
So, please unmark my post as answer and give the credit to Shaoun1000.
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/Friday, July 8, 2011 7:06 AM -
Left will refer to the .Left property of the form instead of the Microsoft.VisualBasic.Left method which you appear to be after.
However, if you just want to check the first character in the TextBox is a 9, you can use TextBox2.Text.Chars(0)="9" as the test.
I suggest that you put Option Strict On at the top of your script so that Visual Studio can catch errors like that for you.
HTH,
Andrew
Friday, July 8, 2011 12:13 PM -
Hi ALL,
For completeness sake only please try the following code and read my code comments.
- Left
- Right
- Top
- Bottom
refer to the distance in pixels a Form or control is within its parent container.
For a Form it is usually the default screen unless you put a Form inside a Form or have an MDI ( Multi-Document-Interface ) based application.
For STRING Left and Right functions they are in the Microsoft.VisualBasic namespace as Heslacher has shown.
Try this code with one Button on your Form please.
Option Strict On Option Explicit On Option Infer Off Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'These two you can GET or SET as the Left and Top 'are SET by the Forms .Location property. Dim formLeft As Integer = Left 'or Me.Left MessageBox.Show("formLeft = " & formLeft.ToString) Dim formTop As Integer = Top 'or Me.Top MessageBox.Show("formTop = " & formTop.ToString) '-------------------------------------------------------------------- 'These two are ReadOnly properties:>> Dim formRight As Integer = Right 'or Me.Right MessageBox.Show("formRight = " & formRight.ToString) Dim formBottom As Integer = Bottom 'or Me.Bottom MessageBox.Show("formBottom = " & formBottom.ToString) '-------------------------------------------------------------------- Dim leftString As String leftString = ":-) Hi there!!".Substring(0, 3) MessageBox.Show(leftString) 'OR leftString = Microsoft.VisualBasic.Left(":-D How are you today?", 3) MessageBox.Show(leftString) '-------------------------------------------------------------------- Dim rightString As String Dim testString As String = "Hi!! :-]" rightString = testString.Substring(testString.Length - 3) MessageBox.Show(rightString) 'OR testString = "Hello!! ;-)" rightString = Microsoft.VisualBasic.Right(testString, 3) MessageBox.Show(rightString) End Sub End Class
Regards,
John
Click this link to see how to insert a picture into a forum post.
Installing VB6 on Windows 7
XNA is coming to VB.Net
App Hub forums
Friday, July 8, 2011 2:03 PM -
Hi jimbong,
Please do not post in more than one forum area, your question(s) will still get noticed.
This question is marked as answered here:>>
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/dc94ef0a-de5b-4434-9ecd-bcec9626447b
Regards,
John
Click this link to see how to insert a picture into a forum post.
Installing VB6 on Windows 7
XNA is coming to VB.Net
App Hub forums
Friday, July 8, 2011 3:33 PM -
Left is not available in .Net. You should use substring.
While I agree that .Substring is a better approach, don't say that "Left" isn't available!
It most certainly is, as it "Right". It still exists and still works. I'll be glad to post examples if need be.
Friday, July 8, 2011 10:36 PM -
Just for the record here:
Dim originalText As String = "The Quick Brown Fox Jumped Over The Lazy Dog" Dim leftText As String = Microsoft.VisualBasic.Left(originalText, 10) Dim rightText As String = Microsoft.VisualBasic.Right(originalText, 10) Dim msgToShow As String = "Left Text: " & leftText & vbCrLf & "Right Text: " & rightText MessageBox.Show(msgToShow)
Friday, July 8, 2011 10:54 PM -
This IS NOT A VB6 forum. Those and you who answer VB6 questions are 1.) Breaking the rules of this forum and encouraging these people to stay.
Renee
Saturday, July 9, 2011 1:22 AM -
Renee,
It is not a VB6 question.
Telling: "I'm born in Amsterdam" does not mean that I'm currently in Amsterdam.
Look at the question from the OP
Success
CorSaturday, July 9, 2011 8:18 AM