Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Programming Help in VB 6!! Need 1 tip or 2  (Read 15698 times)

0 Members and 1 Guest are viewing this topic.

drago87

    Topic Starter


    Rookie
    Programming Help in VB 6!! Need 1 tip or 2
    « on: December 16, 2007, 02:55:16 PM »
    Need to write a file that.

    1. After started wait fore 10 sek
    2. Clicks the 'u' button
    3. Waits 0,5 sek
    4. Set a loop for about 9999 times then another loop fore 30
    5. Clicks the '1' button
    6. Waits 4 sek
    7. Clicks the '2' button
    8. Then run the next loop
    9. After 30 loops clicks the 'p' button
    10. then restart from steep 5 after 10 sek

    this is what i hawed made but it is sent working at all.

    @echo on
    delay(10000)
    KB_CLK(u)
    delay(500)
    loop(9999)
    loop(30)
    KB_CLK(1)
    delay(4000)
    KB_CLK(2)
    delay(4000)
    nextloop()
    KB_CLK(p)
    delay(10000)
    nextloop()
    PAUSE

    If you don't want to make the code you can just give me some pointers. I'm still new to this.

    I'm writing it in an text doc that i'm converting to a *.bat file.

    I could always start whit another prog but i don't now witch.

    Hawe chose tho make it in Visual Basic.
    « Last Edit: December 20, 2007, 04:04:36 PM by drago87 »

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Programming Help in VB!! Need 1 tip or 2
    « Reply #1 on: December 17, 2007, 01:31:33 PM »
    With all the loops and delays, all I see is a total of 4 key entries. Please explain what you are trying to accomplish and what application are you using to create the text doc.

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    drago87

      Topic Starter


      Rookie
      Re: Programming Help in VB!! Need 1 tip or 2
      « Reply #2 on: December 17, 2007, 01:38:25 PM »
      I hawed done this so fare.


      KeyAscii 170 is x but i want use ascii for F11
      KeyAscii 172 is z but i want use ascii for F10
      PS1C is a text box that will set what key it will press
      PS2C is a text box that will set what key it will press
      AS1C is a text box that will set what key it will press
      AS2C is a text box that will set what key it will press
      AS1T is a text box that will set the delay between the key presses
      AS2T is a text box that will set the delay between the key presses
      kb_cl is meant to be the clicking command (but i doupe it work)


      ------------------------------------
      KeyAscii As Integer
      Private Sub Form_Load()

      If KeyAscii = 170 Then
          press 'u'
          delay 500
          If PS1C <> empty Then
              kb_cl = PS1C
          End If
          If PS2C <> empty Then
              kb_cl = PS2C
              End If
      Loop Until KeyAscii = 172
      Loop Until 30
          If AS1C <> empty Then
              kb_cl = AS1C
              delay = AS1T
          End If
          If AS2C <> empty Then
              kb_cl = AS2C
              delay = AS1T
          End If
      next loop
      kb_cl 'p'
      delay 10000
      next loop

      End Sub

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Programming Help in VB!! Need 1 tip or 2
      « Reply #3 on: December 17, 2007, 02:28:53 PM »
      Still not really sure where this is going.

      Never did it this way before, but you might be able to use the sendkeys function to get a value into a text box. I guess I would ensure the textbox has focus first. The sendkeys functon has a wait parameter so you can build in your delays there.

      Usually it's easier to set the text property of the textbox to a value: psc1.text = value. There is also a sleep function in VB but I seem to remember it in the API:

      Code: [Select]
      Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

      Use as: sleep nnnnn where nnnnn is measured in milliseconds (1 sec = 1000 milliseconds)

      As far as I know a loop statement must be matched with a do or do while statement.

      Are you trying to automate a process. If we had the whole picture, there might be other ways of doing it.

       8)

      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      drago87

        Topic Starter


        Rookie
        Re: Programming Help in VB!! Need 1 tip or 2
        « Reply #4 on: December 17, 2007, 02:52:01 PM »
        Dont know how to insert a pic from my hard drive but i vill see if i can draw a pic
        betveen the 2 |         |  is the text box whid the name off the box


        ---------------------------------------------------------

                                      Start F11
                                      Stop F10

                                Skill Slott                Time (mS)

        Passive Skill 1 |   PS1C     |
        Passive Skill 2 |   PS2C     |

        Aktive Skill 1   |    AS1C    |           |     AS1T   |
        Aktive Skill 2   |    AS2C    |           |     AS2T   |



        ---------------------------------------------------------

        The PS1C and PS2C is going to start after i hawe pressed the F11 key and 0,5 sek after the prog hawe pressed the 'u' key
        example:    PS1C = 1 and PS2C = 2 the prog will press the 1 key then wait fore 0,5 sek then presses the 2 key.

        The AS1C and AS2C is the same but the AS1T and AS2T sets a time
        example AS1C is 3 and AS2C is 4 the AS1T is 5000 and AS2T is 3000
        The prog presses the 3 key waits fore 5 sek then press 4 waits 3 sek then press 3 agen.
        After 30st 3 presses and 30 4 presses the prog presses the 'p' key waits fore 10 sek then begins to press 3 and 4 agen fore 30 times.

        think that is all.

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Programming Help in VB!! Need 1 tip or 2
        « Reply #5 on: December 18, 2007, 07:16:53 AM »
        Quote
        Dont know how to insert a pic from my hard drive

        Try using an image control on your form. The snippet shows how it works:

        Code: [Select]
        Image1.Picture = LoadPicture("c:\image00A.jpg")

        I've lost track of the status of this post. Be sure to get back to us if you have any more questions.

         8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        drago87

          Topic Starter


          Rookie
          Re: Programming Help in VB!! Need 1 tip or 2
          « Reply #6 on: December 18, 2007, 09:01:17 AM »
          What is the code so that the prog uses the 1 2 3 4 u p andso i can start/stop whid  the F11 F10 buttons??

          i ment on the forum  ::)

          This is what i hawe done now

          If KeyAscii = 170 Then 'start running the prog when press the x button (want it to be the F11 button)
              Asc passiv1 = PS1C
              SendKeys u ' press the u key
              'sleep 500 ' wait for 0,5 sek 'this line generates the error Sub or Funktion not defined
              If PS1C <> Empty Then 'If the txt box PS1C is not empty then contineu
                  SendKeys PS1C 'press the button that is assigned to PS1C ex 1
                  sleep 500 ' wait for 0,5 sek 'this line generates the error Sub or Funktion not defined
              End If
              If PS2C <> Empty Then 'If the txt box PS2C is not empty then contineu
                  SendKeys PS2C 'press the button that is assigned to PS2C ex 2
                  sleep 500 ' wait 0,5 sek 'this line generates the error Sub or Funktion not defined
                  End If
          Do Until KeyAscii = 172 'stop running the prog when press the z button (want it to be the F10 button)
              Do While lop < 30 'run this part 30 times
                  If AS1C = Empty Then
                      SendKeys AS1C 'press the button that is assigned to PS1C ex 3
                      sleep = AS1T 'wait for the number in mS assigned in AS1T ex 5000 (5 sek) 'this line generates the error Sub or Funktion not defined
                  End If
                  If AS2C = Empty Then
                      SendKeys AS2C 'press the button that is assigned to PS1C ex 4
                      sleep = AS2T 'wait for the number in mS assigned in AS1T ex 3000 (3 sek) 'this line generates the error Sub or Funktion not defined
                  End If
                  Set lop = lop + 1
              Loop
          SendKeys p ' press the p key
          sleep 10000 'wait 10 sek 'this line generates Sub or Funktion not defined
          Set lop = 1 ' resett the lop ' this line generats a error "objekt required
          Loop
          « Last Edit: December 18, 2007, 10:00:45 AM by drago87 »

          drago87

            Topic Starter


            Rookie
            Re: Programming Help in VB!! Need 1 tip or 2
            « Reply #7 on: December 18, 2007, 02:23:19 PM »
            Hawe done some changes

             This is what i loock like
            betveen the 2 / / is a text box whid the name off the box


            ---------------------------------------------------------

                                          Start F11
                                          Stop F10

                                    Skill Slott Time (mS)

            Passive Skill 1 / PS1C /
            Passive Skill 2 / PS2C /

            Aktive Skill 1 / AS1C / / AS1T /
            Aktive Skill 2 / AS2C / / AS2T /


            Times to repet / repete /



            ---------------------------------------------------------

            The PS1C and PS2C is going to start after i hawe pressed the F11 key and 0,5 sek after the prog hawe pressed the 'u' key
            example: PS1C = 1 and PS2C = 2 the prog will press the 1 key then wait fore 0,5 sek then presses the 2 key.

            The AS1C and AS2C is the same but the AS1T and AS2T sets a time
            example AS1C is 3 and AS2C is 4 the AS1T is 5000 and AS2T is 3000
            The prog presses the 3 key waits fore 5 sek then press 4 waits 3 sek then press 3 agen.
            After 30st 3 presses and 30 4 presses the prog presses the 'p' key waits fore 10 sek then begins to press 3 and 4 agen fore 30 times.

            that if i hawe inputet 30 in the "Times to repet" txt box.

            think that is all.


            this is waht i hawe done. (hawent got it to wurk att all)

            After a ' it is a coment on what i want the line to do.

            Dim lop As Integer
            Dim PS1 As Integer
            Dim PS2 As Integer
            Dim AS1 As Integer
            Dim AS2 As Integer
            Dim AS1a As Integer
            Dim AS2a As Integer
            Dim SendKeys As String

            Dim repetetimes As Integer

            Private Sub Form_Load()

            Me.KeyPreview = True

            End Sub


            Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

            Debug.Print KeyCode, Shift
            Select Case KeyCode

            Case vbKeyF11

                lop = 1
                PS1 = PS1C.Text
                PS2 = PS2C.Text
                AS1 = AS1C.Text
                AS2 = AS2C.Text
                AS1a = AS1T.Text
                AS2a = AS2T.Text
                repetetimes = repet.Text
               
               
                object.SendKeys "u" ' press the u key
                object.sleep 500 ' wait for 0,5 sek
               
                If PS1C <> "Input" Then 'If the txt box PS1C is not empty then contineu
                   ' SendKeys 1 'press the button that is assigned to PS1C ex 1
                    object.sleep 500 ' wait for 0,5 sek
                End If
               
                If PS2C <> "Input" Then 'If the txt box PS2C is not empty then contineu
                    object.SendKeys PS2 'press the button that is assigned to PS2C ex 2
                    object.sleep 500 ' wait 0,5 sek
                End If
            'Do Until Case vbKeyF10 'stop running the prog when press the F10 button
            start:
             
                Do While lop < repetetimes 'run this part the times specified in the "Times to repet" txt box
                   
                    If AS1C <> "Input" Then
                        object.SendKeys AS1 'press the button that is assigned to PS1C ex 3
                        object.sleep = AS1a 'wait for the number in mS assigned in AS1T ex 5000 (5 sek)
                    End If
                   
                    If AS2C <> "Input" Then
                        object.SendKeys AS2 'press the button that is assigned to PS1C ex 4
                        object.sleep = AS2a 'wait for the number in mS assigned in AS1T ex 3000 (3 sek)
                   
                    End If
                   
                    lop = lop + 1
               
                Loop

            object.SendKeys "p" ' press the p key
            object.sleep 10000 'wait 10 sek
            lop = 1 ' resett the lop
            Case vbKeyF10 = DoEvents
            GoTo start
            'Loop

            End Sub


            I want to be able to press the F11 key in eny prog to start the prosess.


            This is wahat it loocks like
            « Last Edit: December 19, 2007, 11:49:00 AM by drago87 »

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: Programming Help in VB!! Need 1 tip or 2
            « Reply #8 on: December 18, 2007, 04:28:02 PM »
            Glad to see you moved your code out of the load event and into the keypress event. Check out the DoEvents command. This will allow the program to breakout of the loop and check for pending interrupts (F10 in your case). It's sort of like allowing the program to come up for air.  :D
            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            drago87

              Topic Starter


              Rookie
              Re: Programming Help in VB!! Need 1 tip or 2
              « Reply #9 on: December 18, 2007, 10:13:28 PM »
              Ok. But i still hawent got it to respond to the F11 button or the x.
              Do you now a site wher they hawe exeples of codes??
              I want to make it respond to the F11 before moving on. like making

              press F11 a messagebox aprere then press F10 to make it diapere. then i can use that code and alter it to make it wurk im my case.

              Sidewinder



                Guru

                Thanked: 139
              • Experience: Familiar
              • OS: Windows 10
              Re: Programming Help in VB!! Need 1 tip or 2
              « Reply #10 on: December 19, 2007, 04:49:55 AM »
              I was always told, when I find myself in a hole to stop digging. Ever the optimist, I'm looking for the light at the end of the tunnel.

              Try using the _KeyUp or _KeyDown events. This example may prove helpful.

               8)
              The true sign of intelligence is not knowledge but imagination.

              -- Albert Einstein

              drago87

                Topic Starter


                Rookie
                Re: Programming Help in VB!! Need 1 tip or 2
                « Reply #11 on: December 19, 2007, 09:12:33 AM »
                The code you linked to will be off much use. Now yust to implement it in mine.

                I'l Skream if i hawe some more problems.

                Edit...

                Uppdated the last post vhid the new code.

                How can i make the PS1 Integer hawe the content of PS1C??
                « Last Edit: December 19, 2007, 11:49:40 AM by drago87 »

                Sidewinder



                  Guru

                  Thanked: 139
                • Experience: Familiar
                • OS: Windows 10
                Re: Programming Help in VB!! Need 1 tip or 2
                « Reply #12 on: December 19, 2007, 12:48:42 PM »
                From your code, I can only guess that PS1C never had a value of "Input" so you used SendKeys to put it's value to 1. Try using the CInt function:

                PS1 = CInt(PS1C.Text)

                 8)

                By the way, whatever happened to the pictures?


                The true sign of intelligence is not knowledge but imagination.

                -- Albert Einstein

                drago87

                  Topic Starter


                  Rookie
                  Re: Programming Help in VB!! Need 1 tip or 2
                  « Reply #13 on: December 19, 2007, 01:16:43 PM »
                  What pic do you mean??
                  The "Hand" written pic or the scr shot??

                  now the only thing i got a prob (that i now of) is the object.SendKeys
                  and i dont know if the stopp command wurks jet.

                  Sidewinder



                    Guru

                    Thanked: 139
                  • Experience: Familiar
                  • OS: Windows 10
                  Re: Programming Help in VB!! Need 1 tip or 2
                  « Reply #14 on: December 19, 2007, 04:05:15 PM »
                  Couple of points:

                  1. object.SendKeys...you do not need an object reference;

                  Code: [Select]
                  Sendkeys "{enter}"

                  2. Case vbKeyF10 = DoEvents...DoEvents is a function, not a value

                  Code: [Select]
                  Case vbKeyF10
                      DoEvents()
                      .
                      .
                      .

                  3. There is no stop statement. Are you referring to ending the program or exiting a loop?

                  Are you using the VB IDE to develop this project? If so, you can use the F1 key liberally for most of the help you need.
                  The true sign of intelligence is not knowledge but imagination.

                  -- Albert Einstein