Results 1 to 31 of 31

Thread: Reading a TextBox.Text ?

  1. #1
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Reading a TextBox.Text ?

    Hi, so i have this code so far:

    if TextBox1.Text.Contains("movemouse") then
    msgbox("moved mouse!")


    Buuutt how could i do something like this:


    if it contains movemouse and then with an input stuff like: movemouse(x,y)

    so it will actually read your input where the X is and where the Y is. so you can say something like:
    cursor.position = new point(x,y);

  2. #2
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,948

    Re: Reading a TextBox.Text ?

    mouse movements are not shown in the text of a text box so unless you are talking about having the user type in this data it is not going to be there

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    Quote Originally Posted by DataMiser View Post
    mouse movements are not shown in the text of a text box so unless you are talking about having the user type in this data it is not going to be there
    I think that's exactly what the idea is!

    if it contains movemouse and then with an input stuff like: movemouse(x,y)
    You'd actually be better off with, for example, .... mousemove 10 20

    Then it's simply ...

    vb.net Code:
    1. Dim parse As String = TextBox1.Text.Substring(10) 'removes mousemove
    2.         Dim xy() As String = Split(parse, " ") 'separates the two numbers
    3.         Try
    4.             Cursor.Position = New Point(CInt(xy(0)), CInt(xy(1)))
    5.  
    6.         Catch ex As Exception
    7.             MsgBox("I'm sorry Dave, I can't do that!") 'GIGO failsafe
    8.         End Try

  4. #4
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    That code works really good but lets say i type another 9 letter word and its not "MoveMouse". Example: Tittylick 500 500. it will still do as movemouse to 500, 500. Sooo how do i make it specificly to only MoveMouse then X then Y. Exmaple: MoveMouse X Y?

  5. #5
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    Oh igot it! What if i try to do something like this (idk code for it but ill explain what i mean)

    1.Find/Search for word "MoveMouse"
    2. if next char is a " " then
    3. input next as a X value to move
    4. then if there a " " then
    5. input next as a Y value to move.
    if catch an error say
    Msgbox("error on movemouse!");



    EDIT:

    something like this: But idk code

    If RichTextBox1.Find("MoveMouse") Then
    'See if next char is a space " "
    'Then put this char as X value to move mouse
    'Then see if there is a another " "
    'then put this char as Y value
    End If
    Last edited by therehere3; Aug 18th, 2012 at 12:40 PM.

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    My code carries on from your 'If TextBox1.Text.Contains("movemouse") Then'. You can change that to

    If TextBox1.Text.StartsWith("movemouse ") Then

    and include the space. If the space between the numbers is missed out or there is only one number or anything other than spaces and numbers is entered, that error will be caught so you don't need anything else other than an End If to finish it off.
    Last edited by dunfiddlin; Aug 18th, 2012 at 12:55 PM.

  7. #7
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    Noooo know what i am trying to say is how do i make it if it FINDS the actaully word "MoveMouse" because right now if i put in my big textbox1.text this:
    bllahh bllah
    blah


    blahh

    MoveMouse 500 500
    it will not move the mouse to 500 500 becuase your are making a "Fixed" number of characters you have which is "10". I want it NOT to be a fixed value and just actaully find the word "MoveMouse" then do as i said above:
    'See if next char is a space " "
    'Then put this char as X value to move mouse
    'Then see if there is a another " "
    'then put this char as Y value

  8. #8
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    Maybe i shud tell you my whole idea of this program im making.. like how you make visual basic codes:
    it does line after line after line of code in that order
    sooo if i was to put:
    msgbox("ihii")
    msgbox("noo")
    msgbox("yup")

    it wud first say "ihii" then "noo" then "yup"

    I am trying to make my own actual thing like visaul basic coding stuff. Idk but it might be very complicated:/

  9. #9
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,390

    Re: Reading a TextBox.Text ?

    Yeah, it will be very complicated. One thing you might consider is making it simpler for yourself. You have probably noticed that VB is divided up into lines. Up until VB2010, each line of code had to end at the end of the line of text unless you explicitly indicated that the line of code extended onto the next line of text with the _ continuation character. I would suggest requiring that each line stood alone, as it does in your example. For instance, I would suggest that you would be fine to say:

    msgbox("ihii")
    msgbox("noo")

    but it would be invalid to write:

    msgbox("ihii"") msgbox("noo")

    and something like this would be right out:

    msgbox("
    ihii")

    If you make that one simple rule, that each line must be complete and independent, then you can divide the textbox into lines, which would be an array of strings. You can then examine each string independently of all the others, and the code that dunfiddlin suggested would work. You would have to parse each line independently, but you would be checking whether each line started with MouseMove, msgbox, and whatever else you want. The fact that the MouseMove line was the nth line in the textbox wouldn't matter because each line would be considered independent of all the others.
    My usual boring signature: Nothing

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    Ok. Then you'll need to find a way to read the textbox line by line and direct the code to a the relevant function or sub. So my code would become,

    vb.net Code:
    1. Sub MoveMouse(ByVal Command As String)
    2.         Dim parse As String = Command.Substring(10) 'removes mousemove
    3.         Dim xy() As String = Split(parse, " ") 'separates the two numbers
    4.         Try
    5.             Cursor.Position = New Point(CInt(xy(0)), CInt(xy(1)))
    6.  
    7.         Catch ex As Exception
    8.             MsgBox("I'm sorry Dave, I can't do that!") 'GIGO failsafe
    9.         End Try
    10. End Sub

    And elsewhere in your code you'd have the equivalent of

    vb.net Code:
    1. If TextBox1.Lines(i).StartsWith("movemouse ") Then MoveMouse(TextBox1.Lines(i))

  11. #11
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,390

    Re: Reading a TextBox.Text ?

    Yeah, it will be very complicated. One thing you might consider is making it simpler for yourself. You have probably noticed that VB is divided up into lines. Up until VB2010, each line of code had to end at the end of the line of text unless you explicitly indicated that the line of code extended onto the next line of text with the _ continuation character. I would suggest requiring that each line stood alone, as it does in your example. For instance, I would suggest that you would be fine to say:

    msgbox("ihii")
    msgbox("noo")

    but it would be invalid to write:

    msgbox("ihii"") msgbox("noo")

    and something like this would be right out:

    msgbox("
    ihii")

    If you make that one simple rule, that each line must be complete and independent, then you can divide the textbox into lines, which would be an array of strings. You can then examine each string independently of all the others, and the code that dunfiddlin suggested would work. You would have to parse each line independently, but you would be checking whether each line started with MouseMove, msgbox, and whatever else you want. The fact that the MouseMove line was the nth line in the textbox wouldn't matter because each line would be considered independent of all the others.
    My usual boring signature: Nothing

  12. #12
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,390

    Re: Reading a TextBox.Text ?

    I figured that dunfiddlin would get a reply in there before this posted, especially since the forum decided to pause on me, as it is wont to do these days. My reply was intended to be prior to his, but it still mostly works, except that he also suggested examining line by line.
    My usual boring signature: Nothing

  13. #13
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    Ehh for dunfiddlin wut wud i use as my i interger?

  14. #14
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    Well the most obvious thing to do would be to loop through the lines when you run the 'program' from the textbox

    vb.net Code:
    1. For i = 0 to TextBox1.Lines.Length-1
    2. 'read each line in turn
    3. 'determine what sub to run
    4. If TextBox1.Lines(i).StartsWith("movemouse ") Then MoveMouse(TextBox1.Lines(i))
    5. 'more sub/function choices
    6. Next

  15. #15
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,390

    Re: Reading a TextBox.Text ?

    How the heck did my post get duplicated both before AND after dunfiddlin's post???? I'm pretty sure it wasn't there more than once when I first posted it.

    Gad, this upgrade hasn't been a great thing.
    My usual boring signature: Nothing

  16. #16
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    ok tyvm, sooo i have tried the same thing but with a "Log" command instead of the movemouse command.

    The log commands it suppsoed to be like this:
    Log hello world!


    and on another textbox i have on the bottom of the program is where the logs will go, so it shud just say "hello world!" not "Log hello world!" sooo this is what i have so far:

    Code:
        Sub Log(ByVal Command As String)
            Dim parse As String = RichTextBox1.Text.Substring(4) 'removes log
            Try
                LogBox.Text = LogBox.Text + parse
    
            Catch ex As Exception
                MsgBox("Error on Log!")
            End Try
        End Sub
    
    
       (in my run button):
    
            For i = 0 To RichTextBox1.Lines.Length - 1
                If RichTextBox1.Lines(i).StartsWith("MoveMouse ") Then
                    MoveMouse(RichTextBox1.Lines(i))
                End If
                If RichTextBox1.Lines(i).StartsWith("Log ") Then
                    Log(RichTextBox1.Lines(i))
                End If
            Next

    Sooo i want when i do this: "Log hiii" it wont show up as "Log hiii" it will show up as "hiii" and also it does this too (but i dnt want it too):

    if i type in my big richtextbox1 this:
    Code:
    sdas
    sd
    s
    das
    
    Log hello!
    
    sdf
    
    
    ss
    
    ss
    s
    it will actually say on my textbox: "Log hello!sdfsssss"

    it also ttakes all the other lines after it when i type Log, but i dnt want that, sooo can u help plz?;/

  17. #17
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    vb.net Code:
    1. Sub Log(ByVal Command As String) 'you work with Command in the sub which contains the line you passed to it
    2.         'Dim parse As String = RichTextBox1.Text.Substring(4) 'removes log .... no it doesn't, you're using the whole of the text here
    3. Dim Parse As string = Command.Substring(4) 'removes log
    4.         Try
    5.             LogBox.AppendText(parse & vbcrlf) 'add text and force new line for next entry
    6.  
    7.         Catch ex As Exception
    8.             MsgBox("Error on Log!")
    9.         End Try
    10.     End Sub

  18. #18
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    Ok sooo what i need know is, how do i make it read the line after line with a wait period on it?

    For example if i was do type in my richtextbox1:

    MoveMouse 50 50
    MoveMouse 900 900
    MoveMouse 123 35


    it will end up going to the coords: 123, 35. How could i make another command such as this:


    MoveMouse 50 50
    Wait 1000
    MoveMouse 900 900
    Wait 1000
    MoveMouse 123 35



    so it will move mouse to 50,50 then wait 1sec then move to 900,900 then wait 1sec then move to 123,35.

    Can u help me out on that? Ikno it will be alot complicated, i tried
    Last edited by therehere3; Aug 19th, 2012 at 07:30 PM.

  19. #19
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    Not complicated at all once you know about Now!

    vb.net Code:
    1. Sub Wait(Command As String)
    2.  
    3.        Application.DoEvents 'this just ensures that there is nothing queued up before entering the wait
    4.  
    5.         Try
    6.             Dim millisecs As ULong = CULng(Command.Substring(5)) 'as we only need to deal with positive integers, use ULong
    7.             Dim start As ULong = Now.Ticks 'Now gives the exact current computer time in various formats. Ticks is the most basic unit
    8.             Dim timeup As Boolean = False
    9.             millisecs = millisecs * 10000 '10000 ticks per millisecond
    10.             Do Until timeup = True
    11.                 If Now.Ticks - start >= millisecs Then timeup = True
    12.             Loop
    13.  
    14.         Catch
    15.                 'error message
    16.         End Try
    17.     End Sub

  20. #20
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    YOU ARE SOOO AMAZING!! I cant tell you how much i thank you right now! I might even donate sum moneyz to u!

    The only problem with that Wait command now is it will ALWAYS 100% goto the Catch error. I made it say "msgBox("Error on Wait!")"
    And it will always say that when a Wait command is put in my richtextbox1.


    Soo this is what i had:

    MoveMouse 30 30
    Wait 1000
    MoveMouse 200 200


    it moves mouse to 30,30 waits 1sec, then moves to 200,200 and gives me a message box of "Error on Wait!"

  21. #21
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    trolololol XD i accidently kept my old "Wait" command in there too, thats why:P

    Ok sooo one sec, ill probably ask for more help in alil like usual haha :P

  22. #22
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    Got it! Two things now:P Srry if bothering u :'(



    1. Find a RBG Color and make the mouse move to it.

    2. Select a Range of where to have the coordinates.

    I might need to explain alittle bit more on number 2:
    Sooo, my very top-left of my screen is coordinate 0,0 and the bottom-right is my max X,Y coordinates my screen has. Soooo if I was to have a code such as to move to a specific spot in a webbrowser (324,672) and if i was to move the webbrowser just a little ALL coordinates will be off Soooo i was wondering how i can make a "Select Client" thingy, such as this video i made shows you more detail:


  23. #23
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    buump. plz help

  24. #24
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    On 2. take a look athttp://msdn.microsoft.com/en-us/libr...ttoclient.aspx

    1. on the other hand doesn't make a lot of sense. On an 800 x 600 screen (and who uses a screen that size these days?) there are nearly half a million pixels. If I was to go looking for a red one, say, not only would it take up all the CPU room available trolling through all those values, but which pixel would I actually choose. The first one I came to, the one nearest the middle of the screen, the one next to two blues and a green, the largest prime x co-ordinate? It is one thing to detect the colour at a specified point. It is quite another to specify a point by colour!

  25. #25
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    im not exactly sure on how to use the method "PointToClient". can u give me an example usage please?

  26. #26
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    Actually looking at this again I should have said PointToScreen rather than PointToClient.

    vb.net Code:
    1. Cursor.Position = WebBrowser1.PointToScreen(p)
    2. 'takes a specified point within the webbrowser and converts to screen co-ordinates
    3. 'so that wherever the webbrowser is moved the cursor is always at the same point within it
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  27. #27
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    Havnt tested or tried it yet, but what is that "p" variable inside that PointToScreen function? do i need to declare that "p" somewhere? or just call that?

  28. #28
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    p is a drawing point. You can either declare it separately if you're going to use it more than once or simply create it on the fly.

    vb.net Code:
    1. 'either
    2. Dim p As Point = New Point(310, 250)
    3. Cursor.Position = WebBrowser1.PointToScreen(p)
    4.  
    5. 'or
    6. Cursor.Position = WebBrowser1.PointToScreen(New Point(310,250))
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  29. #29
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    I dont believe this is what i kinda was looking for:/

    So if i was to move my mouse anywhere on the screen it would have the coords of: 0,0 on my top-left and on my top-right would be whatever my max screen monitor is (1305,1670) <-example.

    Soo, what if i wanted to make it move the mouse with my MoveMouse function to a certain spot inside a program maybe called "notepad" then i have it perfectly set up to move to that certain spot, but once i move my "notepad" prorgam, my coordinates are aaallll screwed up and will not work anymore Sooo i wanted to make something like a button or something to make it get coords of a certain program area. Soo if i wanted to get the coords of the "notepad" program, then i can move that "notepad" program anywhere on my screen but the still have the top-left of that "notepad" pgrogram be 0,0 and the top-right of that program be the max of the "notepad" program's window size.

  30. #30
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: Reading a TextBox.Text ?

    Right. Well, I bow to your expertise then. Obviously you know so much more than I do and will have this working in no ti ..... oh!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  31. #31
    Addicted Member
    Join Date
    Jul 11
    Posts
    157

    Re: Reading a TextBox.Text ?

    Woe woe.. dont take me wrong? I am not trying to attack you in any way? I clearly can see that you are wwaayyy better than me at this visual basic coding stuff. withyou, my program i have right now would be what it is today. So i am defently not saying i am better or i can fix it. I was just asking of what i said above, is that "pointToScreen" function could work as what i said on my last post? I did not mean to be rude or mean or say im better. Sorry if it sounded like that

Posting Permissions

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