?
Solved

mouse clicking

Posted on 2003-03-09
2
Medium Priority
?
189 Views
Last Modified: 2010-04-17
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
Comment
Question by:wendilim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:AmericanDogma
ID: 8100851
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
 
LVL 1

Accepted Solution

by:
Pickle earned 80 total points
ID: 8104555
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Progress
Starting up a Project
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question