VB6 Code Help


Closed Thread
Results 1 to 6 of 6

Thread: VB6 Code Help

  1. #1
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161

    Default VB6 Code Help

    I am trying to build a Robotic Arm to be controlled by a Computer Based Application, just to generate some interest of school children in Robotic.

    The Hardware is pretty simple and involves a PIC (16F628A) and geared DC Motor at the Arm (yes DC motors and not Servo or Stepper).

    The idea is that the Computer sends a stream of commands to the control and the controller engages the motor in the direction of the Command.

    I am facing a problem with the VB code. I cannot figure out how to program a command button (in VB6) to keep sending a stream of string when the comannd button is kept pressed. At present I can only program in a way that it sends a string only once. I have 4 command buttons for 4 direction and I am interested in Momentary action for these Command Buttons.

    Can any one help me with the code.

    Thank you.

  2. #2
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695

    Default

    Hi,

    To try this VB code put the following controls on a form:
    (This is a sample for 1 command button).

    Command1
    Label1
    Timer1

    * * * *

    The code for 4 command buttons:

    Your program has 4 buttons so you will need a global
    variable to tell Timer1_Timer() which button is MouseDown.
    Set the value of your global variable in the 4 subroutines commandX_MouseDown()
    and in Timer1_Timer() with a "Select Case" or with more "IF"
    you can do your conditional execution based on the global variable value.

    Best regards,

    Luciano


    Code:
    '=============================
    Private Sub Form_Load()
    
    Label1.Caption = 1
    Command1.Caption = "Test"
    Timer1.Enabled = False
    
    
    End Sub
    
    '=============================
    
    Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Timer1.Interval = 100   '~ 100 ms. try 10 or 1000
    Timer1.Enabled = True
    
    End Sub
    
    '=============================
    
    Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Timer1.Enabled = False
    
    End Sub
    
    '============================
    
    Private Sub Timer1_Timer()
    
    Label1.Caption = Label1.Caption + 1
    
    End Sub
    
    '=============================

  3. #3
    Join Date
    Feb 2003
    Posts
    432

    Default

    Quote Originally Posted by charudatt
    I am facing a problem with the VB code. I cannot figure out how to program a command button (in VB6) to keep sending a stream of string when the comannd button is kept pressed. At present I can only program in a way that it sends a string only once. I have 4 command buttons for 4 direction and I am interested in Momentary action for these Command Buttons.
    I did something similar for controlling a Video Conferencing camera.

    Instead of using the Click event for the button....

    1. Create a timer for each button and have the timer send a command each time it expires.

    2. Use the MouseDown event to enable the timer

    3. Use the MouseUp event to disable the timer.

    The end result is that for the duration of the button press, your program will send the command every x milliseconds depending on what you set x to be.

    You can get clever and include a counter as well so that you start off with one command every 200mS giving slow control but after "n" steps you decrease the time period so that the movement accellerates either gradually... 200, 190, 180, 170 etc or rapidly 200, 200, 200, 50, 50, 50 etc

    Hope that helps
    Keith

    www.diyha.co.uk
    www.kat5.tv

  4. #4
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161

    Default Thanks !

    Thanks fellas,

    I shall try it out and give my feedback. Good tip of using a Timer.

    regards

  5. #5
    mazmoiz's Avatar
    mazmoiz Guest

    Smile X-Y Movement of the arm using mouse !!!

    Hello !!
    May be this piece of code can help u in sending a stream of strings as u want !! (X-Y Movement) and continous streaming !!!

    Send the values of X and Y text boxes to the COM port.
    U have to modify this code as per ur requirements !!

    here the values of textboxes ranges from 0-100 in both the directions
    You have to set the value between 25 to 225 if using Servo motors !!

    the arm movements will follow the mouse movements in x-y position.

    (Note: here code only shows X-Y movements !!! and it doesnt contain
    COM event programming !! You have to use COM control for
    sending textbox values to the port)

    I hope u'll find this code helpful and useful for your project !!
    Regards

    Mazhar Haque


    PLS have a look at the attached ZIP file !!!
    --------------------------------------------------------------------------

    Private Sub Command1_Click()
    xl.Visible = True
    yl.Visible = True
    Picture2.Visible = False

    End Sub


    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then
    xl.Visible = False
    yl.Visible = False
    Picture2.Visible = True
    End If
    End Sub

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim intx As Integer
    Dim inty As Integer

    xl.Y1 = Y
    xl.Y2 = Y
    intx = Abs(Y - 100)
    xt.Text = intx


    yl.X1 = X
    yl.X2 = X
    inty = Abs(X - 100)
    yt.Text = inty

    End Sub
    Attached Files Attached Files

  6. #6
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216

    Wink Nice Code!

    Nice code mazmoiz,
    Who needs a joystick? I know I can think of some applications this code could be useful.... with a little modification. Koodos
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. VB6 Code Help
    By charudatt in forum Code Examples
    Replies: 5
    Last Post: - 14th July 2006, 20:41

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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