Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

mouse clicking

Hi,
I'm a student and i am doing a project on Visual Basic 6 which connect to a slider. I have 4 buttons-Home,Left,Right and Exit. if i click on Home button the slider(actuator)will move to the original place which is position 0. when i click on the Left button, the slider will move to position 200.when i click left button again, the slider will move from position 200 to 220, but the slider did not move to position 220, so how can i made the slider move to the position when i press the 2nd times
this is my program....... pls help.........

Private Sub cmdexit_Click()
End
     
End Sub

Private Sub cmdhome_Click()

outslider$ = "!99HOM0130@@" & Chr$(13) & Chr$(10)
If MSComm1.PortOpen Then
       MSComm1.Output = outslider
       End If
       Text1.Text = outslider$
cmdhome.Enabled = True
cmdleft.Enabled = True
cmdright.Enabled = True
cmdexit.Enabled = True
End Sub

Private Sub cmdleft_Click()
outslider$ = "!99PMV010   00300001@@" & Chr$(13) & Chr$(10)

If MSComm1.PortOpen Then
       MSComm1.Output = outslider$
        End If
    Text1.Text = outslider$
End Sub



Private Sub Form_Load()
cmdhome.Enabled = True
cmdleft.Enabled = False
cmdright.Enabled = False
cmdexit.Enabled = True

  MSComm1.CommPort = 1                 'Set COM1
  MSComm1.Settings = "9600,N,8,1"      ' Settings: 9600 baud, no parity, 8 data bits, 1 stop bit
  MSComm1.PortOpen = True              ' Open the port with the settings above
 
End Sub

Private Sub Form_Unload(Cancel As Integer)
 MSComm1.PortOpen = False             ' Close the port (let other programs use it)
End Sub
0
wendilim
Asked:
wendilim
1 Solution
 
AmericanDogmaCommented:
for the text box use.

Private Sub txtBoxName_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    txtBoxName.Text = Val(txtBoxName.Text + 1)
End Sub


Where txtBoxName is the name of the textbox.  Also be sure to set the text property to whatever your desired starting integer is.
0
 
PickleCommented:
Use a global variable, I called it position, to keep track of where the slider is.  Set position to 0 when someone clicks the home button and set it to 200 if someone clicks the left button and position is 0.  If someone clicks the left button and position is not 0 then they must have clicked it once before, so add 20 to position.  Then you can use the value of positon to calculate your outslider string.


Dim position As Integer

Private Sub cmdexit_Click()
End
   
End Sub

Private Sub cmdhome_Click()
     position = 0  'Set our position variable to 0(Home)
     
     outslider$ = "!99HOM0130@@" & Chr$(13) & Chr$(10)
     If MSComm1.PortOpen Then
           MSComm1.Output = outslider
     End If

     Text1.Text = outslider$

     cmdhome.Enabled = True
     cmdleft.Enabled = True
     cmdright.Enabled = True
     cmdexit.Enabled = True
End Sub

Private Sub cmdleft_Click()
     If position = 0 Then  'If Position is 0 we must be home
          position = 200 'Goto position 200
     Else  'If position is not 0 we already have a position
          position = position + 20  'Add 20 to the current position
     End If
     
     outslider$ = "!99PMV010   00300001@@" & Chr$(13) & Chr$(10)

     If MSComm1.PortOpen Then
           MSComm1.Output = outslider$
     End If
     
     Text1.Text = outslider$
End Sub

Private Sub Form_Load()
     position = 0

     cmdhome.Enabled = True
     cmdleft.Enabled = False
     cmdright.Enabled = False
     cmdexit.Enabled = True

     MSComm1.CommPort = 1                 'Set COM1
     MSComm1.Settings = "9600,N,8,1"      ' Settings: 9600 baud, no parity, 8 data bits, 1 stop bit
     MSComm1.PortOpen = True              ' Open the port with the settings above
End Sub

Private Sub Form_Unload(Cancel As Integer)
     MSComm1.PortOpen = False             ' Close the port (let other programs use it)
End Sub
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now