Re: VB6 program help- Nina
I would suggest that you use a For Next loop rather than a while loop with a counter. As for the com part you should start by telling us what type of com you are talking about ... Serial,UDP,TCP ?
Re: VB6 program help- Nina
Thanks for responding. I started with the below,
Private sub IRdisc_Click()
'To check for IR disconnects'
Private sub cmdCoun_Click()
Dim Countmsg As integer
For first counter= 1 to 100
Print'command running'
For second counter=1 to 5
print'No disconnect'
Next second counter
Next first counter
Print'Successful'
End sub
I am sure there will be lot of errors. Please advise how i can correct it. Thanks!
Re: VB6 program help- Nina
Also, i will be connecting the system through a dongle to the computer and it uses a USB port.
Re: VB6 program help- Nina
You need to dim all your variables
Variables can not have spaces in them e.g. First counter Second counter
not sure what you are supposed to be checking for the code there does not check for anything it just loops and prints to the form Command Running followed by 5 lines of No Disconnect and repeats those 6 lines 100 times
Re: VB6 program help- Nina
here is piece of code stripped out of my source for you to se how it works
for now add all these codes to fresh project and test so u can check it and tell me if this is something u want
add to fresh project
Code:
text5.text = "100"
text1.text = "1" ' speed
Label2 ' with caption set to 0
Private Sub Command8_Click()
Dim x As Integer
Dim i As Integer
For x = 0 To Text5.Text - 1
' your code here
'example winsock1.close
'winsock1.connect ip,port
Pause Text1
Label2.Caption = Label2.Caption + 1
DoEvents
Next x
Debug.Print x
End Sub
Code:
Sub Pause(interval)
Dim atime
atime = Timer
Do While Timer - atime < Val(interval)
DoEvents
Loop
End Sub
so your code is simile to mine
Code:
Private sub cmdCoun_Click()
Dim Countmsg As integer
For first counter= 1 to 100 ' is my text5.text
Print'command running'
For second counter=1 to 5 ' is my text5.text
print'No disconnect'
Next second counter
Next first counter
Print'Successful'
End sub
so here is your fixed code
Code:
Private Sub Command12_Click()
Dim Countmsg As Integer
Dim x As Integer
Dim i As Integer
'For first counter = 1 to 100 ' is my text5.text
For x = 1 To 100
'put your command here
'example command1_click or any execution code etc it will keep sending till it reaches 100
Label2.Caption = Label2.Caption + 1
Pause 1
DoEvents
Next x
Debug.Print x
End Sub
add this to your source
Code:
Sub Pause(interval)
Dim atime
atime = Timer
Do While Timer - atime < Val(interval)
DoEvents
Loop
End Sub
Re: VB6 program help- Nina
You should not use that busy loop pause method. That is very bad programing practice and can lead to all sorts of unexpected issues.
There is rarely ever a case where you would need to resort to this and even when there is it is usually because your code was not written properly.
I strongly advise against using it and against advising others to use it.
Not to mention that the sub does not define a variable type and then uses Val() to convert it to a number which also is not properly defined in the code.
Re: VB6 program help- Nina
:)thanks for the advise, made many progs users never complained so its good anyways:p
:psince no one posted i thought might aswell help her understand how its done so she gets the idea:p
Re: VB6 program help- Nina
Is this an InfraRed (IR) project ? If so, and if you're connecting via USB I suspect the IR Device looks like a Comm Port in which case you'll need to use the MSComm control.
Do you have any documentation regarding the device ? (e.g. What Communication protocols it supports)
Re: VB6 program help- Nina
Re: VB6 program help- Nina
You have attached the Form rather than the Code. Please .Zip up the Project and attach it here.
1 Attachment(s)
Re: VB6 program help- Nina
Hi Please find the attached project.
Basically, i need to write a code for Number of cycles, delay, timer. The user feeds in the number of cycles and delay he wants. And send a pump command that should run the number of cycles he wanted it to run.
Below is the command that will be executed.
Private Sub cmdSendCommand_Click()
Dim aCommand As String
Dim itsArgs As String
aCommand = txtPumpCommand & "/" & txtPumpCommandValue ' get stuff off of the form
Call SendCommand(aCommand)
End Sub
Please help.
Re: VB6 program help- Nina
Hi guys, Do you think its understandable?
Re: VB6 program help- Nina
Hi
I just took a quick look, I would change the following :
text box Number of Cycles, 'Text5' change to 'TXTCycles'
search all references of Text5 and replace to TXTCycles.
Assumming the send button starts the processing work for the form.
Change the code inside to :
Code:
Private Sub cmdSendCommand_Click()
Dim aCommand As String
Dim itsArgs As String
Dim Cycles As Integer
aCommand = txtPumpCommand & "/" & txtPumpCommandValue ' get stuff off of the form
For Cycles = 1 To Val(TXTCycles.Text)
Call SendCommand(aCommand)
' sleep 1000*val(txtdelaytime.text) ' delay after each sendcommand
Next Cycles
' sleep 1000*val(txtdelaytime.text) ' delay after a full cycle of sendcommands
End Sub
for the delay, i would use sleep command, add this line at top of a form or module :
Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' usage : sleep 1000 - sleep for 1000 ms or 1 second
What we also need is a way to display connection status during loop maybe this will work :
If we could test if the global ConnectStatus = True
then we could use a CheckConnection() function
Code:
Private Function CheckConnection() as Boolean
CheckConnection = ' code to check status - True connection on (ok) , set false is off
' update global connection status variable
ConnectStatus = CheckConnection
End Sub
We can optionally use the function when the missing data is filled in :
Code:
dim ConnectStatus as boolean
Private Sub cmdSendCommand_Click()
Dim aCommand As String
Dim itsArgs As String
Dim Cycles As Integer
aCommand = txtPumpCommand & "/" & txtPumpCommandValue ' get stuff off of the form
For Cycles = 1 To Val(TXTCycles.Text)
' Check we have a connection before we do anything
if CheckConnection = True then
Call SendCommand(aCommand)
' user requested delay
' sleep 1000*val(txtdelaytime.text) ' delay in secs after each sendcommand
else
' update error log
' try reconnect
endif
Next Cycles
' sleep 1000*val(txtdelaytime.text) ' delay in secs after a full cycle of sendcommands
End Sub