Results 1 to 21 of 21

Thread: How can i get this vb6 code in vb.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190

    How can i get this vb6 code in vb.net

    vb.net Code:
    1. Private Sub txtGew_KeyPress(ByVal KeyAscii As Integer)
    2.  
    3.     If KeyAscii = 46 Then
    4.         KeyAscii = 44
    5.     End If
    6. End Sub
    Last edited by Siddharth Rout; Nov 5th, 2013 at 02:04 AM. Reason: Added Code Tags

  2. #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?

  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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

  5. #5
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: How can i get this vb6 code in vb.net

    Hi,

    Give this a try:-

    vb.net 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

    Hope that helps.

    Cheers,

    Ian

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190

    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

  7. #7
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    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

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190

    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

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190

    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

  12. #12
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    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

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190

    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

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How can i get this vb6 code in vb.net

    Quote Originally Posted by Heribertt View Post
    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.

  15. #15
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    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:
    1. Private bolPeriodPressed As Boolean
    2.  
    3. Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    4.   If e.KeyCode = Keys.OemPeriod Then
    5.     bolPeriodPressed = True
    6.   End If
    7. End Sub
    8.  
    9. Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    10.   If bolPeriodPressed Then
    11.     TextBox1.AppendText(",")
    12.     e.Handled = True
    13.     bolPeriodPressed = False
    14.   End If
    15. End Sub

    I hope that gives you a better starting point.

    Cheers,

    Ian

  16. #16
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  18. #18
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190

    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

  20. #20
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190

    [RESOLVED] How can i get this vb6 code in vb.net

    thanks to all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width