PDA

View Full Version : VB6 Code Help



charudatt
- 30th November 2005, 06:52
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.

Luciano
- 30th November 2005, 10:19
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




'=============================
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

'=============================

keithdoxey
- 30th November 2005, 10:25
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

charudatt
- 30th November 2005, 19:43
Thanks fellas,

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

regards

mazmoiz
- 16th December 2005, 21:48
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

rhino
- 20th December 2005, 20:39
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