-
Nov 4th, 2013, 11:31 AM
#1
Thread Starter
Addicted Member
How can i get this vb6 code in vb.net
vb.net Code:
Private Sub txtGew_KeyPress(ByVal KeyAscii As Integer) If KeyAscii = 46 Then KeyAscii = 44 End If End Sub
Last edited by Siddharth Rout; Nov 5th, 2013 at 02:04 AM.
Reason: Added Code Tags
-
Nov 4th, 2013, 11:32 AM
#2
Re: How can i get this vb6 code in vb.net
Uh...I'm not sure what the problem is here. Make it a function and return 44?
-
Nov 4th, 2013, 11:35 AM
#3
Re: How can i get this vb6 code in vb.net
I do not think that would do anything. Looks like ou are changing the value of the integer that is passed to the Sub, but the parameter is passed ByVal, so the moment the Sub ends nothing is persisted. What are you trying to accomplish with that?
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Nov 4th, 2013, 11:50 AM
#4
Re: How can i get this vb6 code in vb.net
You would move the code to the Key_Down event and check the e.KeyCode
Or in Key press you check e.keychar =chr(46)
Edit: of course as pointed out above if using ByVal that function does nothing so to convert it to vb.net all you need to do is delete it
-
Nov 4th, 2013, 11:51 AM
#5
Re: How can i get this vb6 code in vb.net
Hi,
Give this a try:-
vb.net Code:
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = "."c Then
e.KeyChar = ","c
End If
End Sub
Hope that helps.
Cheers,
Ian
-
Nov 5th, 2013, 02:43 AM
#6
Thread Starter
Addicted Member
Re: How can i get this vb6 code in vb.net
thanks fot your replay Ian but
3. e.KeyChar = ","c dont do it
wath can there be wrong
here the code
1.Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
2. If e.KeyChar = "."c Then
3. e.KeyChar = ","c
4. End If
5.End Sub
-
Nov 5th, 2013, 03:35 AM
#7
Re: How can i get this vb6 code in vb.net
Taking a guess here, but perhaps the inclusion of e.Handled = True might also help.
VB.NET MVP 2008 - Present
-
Nov 5th, 2013, 03:36 AM
#8
Re: How can i get this vb6 code in vb.net
I can't tell you how much it bugs me when people ask for our help and then refuse to answer questions when we ask for information in order to provide that help. You were asked in post #3 what you are trying to achieve. How about you tell us that rather then how you're trying to achieve it. If we know the aim then we can provide advice to achieve that aim. You say that that code "don't do it". Don't do what? What does it do? Is there an error message? If so, what is it? If someone asks you a question it's because they want information in order to help you. Provide it.
-
Nov 5th, 2013, 04:16 AM
#9
Thread Starter
Addicted Member
Re: How can i get this vb6 code in vb.net
when i run the app it gifs an error "there were build errors"
the "." is not replace by "," in the textbox
What I want to do is change in chr 46 to chr 44 then "." must be the "." in the textbox
-
Nov 5th, 2013, 04:44 AM
#10
Re: How can i get this vb6 code in vb.net
If there are build errors then of course it doesn't work. The code's not even compiling so how can it run? As I said in my previous post:
Is there an error message? If so, what is it?
If there's a build error then there's an error message. For a second time, what is the error message?
What version of VS are you using? If it's 2002 or 2003 then you're targeting .NET 1.x and the KeyPressEventArgs.KeyChar property is read-only, which would explain the issue. Of course, it's for reasons just like this that you're asked to provide a VS version when you create a thread. That's more relevant information that you have neglected to provide and cost us and yourself wasted time as a result.
-
Nov 5th, 2013, 05:05 AM
#11
Thread Starter
Addicted Member
Re: How can i get this vb6 code in vb.net
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub txt1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If (e.KeyChar = ".") Then
e.Handled = True
e.KeyChar = ","c 'This line is underlined here
End If
End Sub
End Class
the error message is "there were build errors"
What is wrong
my vb.net version = 2003
-
Nov 5th, 2013, 05:29 AM
#12
Re: How can i get this vb6 code in vb.net
Open your Output window and double click on any of the errors which gets listed. It should give you an indication of where the error(s) is / are
VB.NET MVP 2008 - Present
-
Nov 5th, 2013, 05:43 AM
#13
Thread Starter
Addicted Member
Re: How can i get this vb6 code in vb.net
i think i have the problem
my keychar is read only
how can i change this
-
Nov 5th, 2013, 05:59 AM
#14
Re: How can i get this vb6 code in vb.net
Originally Posted by Heribertt
i think i have the problem
my keychar is read only
how can i change this
If only I'd told you that in post #10. Oh, I did. That property was made read/write in .NET 2.0 so, if you want to be able to set it, you need to target at least .NET 2.0, which means upgrading to at least VB 2005. Given that the latest is VB 2013 and .NET 4.5.1, you're probably well past time to upgrade.
-
Nov 5th, 2013, 06:01 AM
#15
Re: How can i get this vb6 code in vb.net
Hi,
What version of VS are you using? If it's 2002 or 2003 then you're targeting .NET 1.x and the KeyPressEventArgs.KeyChar property is read-only, which would explain the issue.
Excellent call jmcilhinney, I would have struggled to answer that one.
i think i have the problem
my keychar is read only
how can i change this
You cannot so you need to disregard the comments that I made in post #5. To do this in VS2003 you are going to have to come up with another way to accomplish this. Here is an example which, I hope, is compatible with VS2003:-
vb.net Code:
Private bolPeriodPressed As Boolean
Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.OemPeriod Then
bolPeriodPressed = True
End If
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If bolPeriodPressed Then
TextBox1.AppendText(",")
e.Handled = True
bolPeriodPressed = False
End If
End Sub
I hope that gives you a better starting point.
Cheers,
Ian
-
Nov 5th, 2013, 06:27 PM
#16
Re: How can i get this vb6 code in vb.net
How about you dont change the key pressed but just change the contents of the textbox?
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Nov 5th, 2013, 07:24 PM
#17
Re: How can i get this vb6 code in vb.net
By the way, you still haven't told us what you're actually trying to achieve. It appears that you want a comma to appear whenever the user enters a dot but that is still just a means to an end. What is the desired end? Why do you want this to happen in the first place? I'm asking - AGAIN - because there may be a better way.
-
Nov 6th, 2013, 09:54 AM
#18
Re: How can i get this vb6 code in vb.net
If we have to guess (It appears we do), looks like changing the locale numeric notation, from european to everyone else or biceversa. ie: 1.200,00 vs 1,200.00
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Nov 7th, 2013, 01:57 AM
#19
Thread Starter
Addicted Member
Re: How can i get this vb6 code in vb.net
Here is the solution for my problem
Private Sub Textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox1.KeyPress
e.Handled = True
If e.KeyChar = "." Then
textbox1.AppendText(",")
Else
textbox1.AppendText(e.KeyChar)
End If
End sub
it works fine
thanks all for your help
-
Nov 7th, 2013, 09:56 AM
#20
Re: How can i get this vb6 code in vb.net
Using your same approach, how about this, it is the same just a bit leaner
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = "."c Then
TextBox1.AppendText(","c)
e.Handled = True
End If
End Sub
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Nov 8th, 2013, 08:22 AM
#21
Thread Starter
Addicted Member
[RESOLVED] How can i get this vb6 code in vb.net
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|