dcsimg
Results 1 to 8 of 8

Thread: Assigning Default Text Value

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    3

    Unhappy Assigning Default Text Value

    I'm not new to coding in visual basic, but It's my first time with VB 2019

    I wanted to make an auto clicker app using a Windows form with VB.Net. So I entered the following code after I designed my prototype

    Code:
    Public Class Form1
        Private Declare Sub mouse_event Lib "user32" (ByVal dwflags As Long, ByVal dx As Long, ByVal cbuttons As Long, ByVal dy As Long, ByVal dwExtraInfo As Long)
    
        Dim UserInterval As Integer = Nothing
        Private Const mouseclickdown = 3
        Private Const mouseclickup = 2
        Dim Test As Integer
    
        Public Property getInterval As Integer
            Get
                Return UserInterval
            End Get
            Set(UserInterval As Integer)
                Timer1.Interval = UserInterval
            End Set
        End Property
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Strt_Click(sender As Object, e As EventArgs) Handles strt.Click
            Timer1.Start()
        End Sub
    
        Private Sub Stp_Click(sender As Object, e As EventArgs) Handles stp.Click
            Timer1.Stop()
            Timer1.Enabled = False
            Timer1.Enabled = True
        End Sub
    
        Private Sub Tst_Click(sender As Object, e As EventArgs) Handles tst.Click
            Test = Test + 1
            cntr.Text = Test
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Timer1.Interval = UserInterval
            mouse_event(mouseclickdown, 0, 0, 0, 0)
            mouse_event(mouseclickup, 0, 0, 0, 0)
        End Sub
    
        Private Sub Ntrvl_TextChanged(sender As Object, e As EventArgs) Handles ntrvl.TextChanged
            UserInterval = ntrvl.Text
            If Timer1.Enabled = False Then
                ntrvl.Text = 1000
            Else
                ntrvl.Text = UserInterval
            End If
        End Sub
    End Class
    Now I do not seem to understand where is the fault. I want to enter an integer value within the text box manually after running that is accepted as an interval for the timer. Yet, when the app is run, it doesn't allow me to enter any value. Once I select the Text box and press any value, the text box value changes to 1000???!

    Attached is how the app should look like.
    Can someone pinpoint the mistakes?

    Thanks a trillion in advance!

    Name:  0.png
Views: 160
Size:  2.8 KB

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,333

    Re: Assigning Default Text Value

    Well, you have code in the TextChanged event handler.
    If the user types a character into the Textbox, the text has changed so you get a TextChanged event.
    In your event handler, you have code that checks to see if the Timer is enabled, and if it isn't it sets the textbox Text to "1000".

    So, I have to assume that the timer is not enabled, so any character typed into the textbox will cause the textbox to be reset to "1000", because you told it to do that.

    Why not use a NumericUpDown control instead, and set its Min/Max to the acceptable limits and preset it to 1000.
    The user can then leave it at 1000, or change it to be within the limits that you allow.
    Last edited by passel; Aug 15th, 2019 at 11:27 AM.

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,214

    Re: Assigning Default Text Value

    Put a Break on this
    UserInterval = ntrvl.Text
    in
    ntrvl.TextChanged

    and you will see why
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    3

    Re: Assigning Default Text Value

    Quote Originally Posted by dbasnett View Post
    Put a Break on this
    UserInterval = ntrvl.Text
    in
    ntrvl.TextChanged

    and you will see why
    What do you mean exactly??

    Can I use like a switch-case function with a default clause?? I've just used it in VHDL
    Last edited by Qaswarah; Aug 16th, 2019 at 07:41 AM.

  5. #5
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    144

    Re: Assigning Default Text Value

    I think dbasnett, might be hinting you on the fact that your trying to puss a string in to an integer variable.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    3

    Talking Re: Assigning Default Text Value

    Thank you very much for all your hints.

    It's very functional now, thanks to your "hints"

    So here's the code if anyone would like to use it

    Code:
    Public Class Form1
        Private Declare Sub mouse_event Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32)
    
        Dim UserInterval As Integer = Nothing
        Private Const mouseclickdown = 3
        Private Const mouseclickup = 2
        Dim Test As Integer
    
        Public Property getInterval As Integer
            Get
                Return UserInterval
            End Get
            Set(UserInterval As Integer)
                Timer1.Interval = UserInterval
            End Set
        End Property
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Strt_Click(sender As Object, e As EventArgs) Handles strt.Click
            Timer1.Start()
        End Sub
    
        Private Sub Stp_Click(sender As Object, e As EventArgs) Handles stp.Click
            Timer1.Stop()
            Timer1.Enabled = False
            Timer1.Enabled = True
        End Sub
    
        Private Sub Tst_Click(sender As Object, e As EventArgs) Handles tst.Click
            Test = Test + 1
            cntr.Text = Test
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Timer1.Interval = UserInterval + 1
            Windows.Forms.Cursor.Position = New System.Drawing.Point(Windows.Forms.Cursor.Position)
            mouse_event(&H2, 0, 0, 0, 1)
            mouse_event(&H4, 0, 0, 0, 1)
        End Sub
    
        Private Sub Ntrvl_TextChanged(sender As Object, e As EventArgs) Handles ntrvl.TextChanged
            UserInterval = ntrvl.Text
        End Sub
    End Class

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,333

    Re: Assigning Default Text Value

    Quote Originally Posted by Qaswarah View Post
    What do you mean exactly??

    Can I use like a switch-case function with a default clause?? I've just used it in VHDL
    Quote Originally Posted by Goggy View Post
    I think dbasnett, might be hinting you on the fact that your trying to puss a string in to an integer variable.
    No, I think dbasnett was saying if you use the debugger to step through the code you can clearly see what the problem was and not have to even ask the question.
    It is amazing how many "programmers" start using any version of VB, and are not aware that you can easily set a breakpoint and progress through the code one line at a time and see what it does, and what values it is acting on, and that you can change the values or code and continue stepping through the code as you fix logical problems found in your code.

    You don't have to stare at the code and wonder why it isn't working. You can step through the execution of the code and see why it isn't working.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,985

    Re: Assigning Default Text Value

    I'd like to ask about this:

    Code:
     Timer1.Stop()
     Timer1.Enabled = False
     Timer1.Enabled = True
    Timer1.Stop and setting Enabled to False do exactly the same thing, so those are harmless, but redundant. However, the very next line starts the timer again. Therefore, your stop button doesn't appear to do anything other than reset the timer to the beginning of the interval and keep it running. How is that stop?
    My usual boring signature: Nothing

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width