|
-
Aug 8th, 2012, 04:09 PM
#5
Thread Starter
Hyperactive Member
Re: Comms Problem
Hi Thanks For all your replays
@doogle
Basicly what my program does is creates folders and and then creates a virtual drive from infomation from the comms "engine numbers", I have the comms open all the time waiting for 13 numbers to be sent then it creates a folder with the 13 numbers, another software then saves images to the virutal drive then another engines comes in to station and then another 13 unquie number is sent then creates folders and so on for each engine.
Could you please check though this script below I have inserted with your script Thanks
I dont understand the strBuffer = Mid$(strBuffer, 14)
what is the 14 value, and what does boolean and bocomplete do.
Private Sub Form_Load()
Dim textfile As String
Open "C:\users\administrator\dirnames.txt" For Input As #1
Do While Not EOF(1)
Input #1, textfile
FolderCreator.Combo1.AddItem (textfile)
Loop
Close #1
' Show Date on main screen.
'Label3.Caption = DateValue(Now)
' Fire Rx Event Every Two Bytes
MSComm1.RThreshold = 1 ' Is this correct
' When Inputting Data, Input 2 Bytes at a time
MSComm1.InputLen = 13 ' Is this correct
' 9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = "9600,N,8,1"
' Disable DTR
MSComm1.DTREnable = False
' Open COM1
MSComm1.CommPort = 1
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0 ' Do I need this
End Sub
Private Sub MSComm1_OnComm()
'
' Assumes RTHreshold Property is set to a value > 0
' (Recommended value is 1)
'
Static strBuffer As String
Dim strData As String
Dim strRX As String
Dim boComplete As Boolean
Select Case MSComm1.CommEvent
Case comEvReceive
strData = MSComm1.Input
strBuffer = strBuffer & strData
Do
If Len(strBuffer) >= 13 Then
strRX = Mid$(strBuffer, 1, 13)
'
' rest of your code goes here - strRX contains the 13 characters sent
' After you've done all your processing add the following code
' START OF MY SCRIPT
Label8.Caption = strData
'MSComm1.Output = strData
Dim wshThisShell As WshShell
Dim lngRet As Long
Dim strShellCommand As String
Dim strBatchPath As String
'label8.caption = ""
Set wshThisShell = New WshShell
strBatchPath = "c:\deletevert.bat"
'the path for the batch file you're using
strShellCommand = Chr$(34) & strBatchPath & Chr$(34)
'the ridiculous number of quotation marks is necessary
'when there is a space in one or more of the folder names
lngRet = wshThisShell.Run(strShellCommand, vbNormalFocus, vbTrue)
'set 3rd argument above to vbFalse for asynchronous
'execution of the batch file.
'label8.caption = ""
'label9.caption = ""
If Dir$("e:\" & strData, vbDirectory) = "" Then
Label9.Caption = "Directory does not exist."
MkDir "e:\" & strData
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(0)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(1)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(2)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(3)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(4)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(5)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(6)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(7)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(8)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(9)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(10)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(11)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(12)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(13)
MkDir "e:\" & strData & "\" & FolderCreator.Combo1.List(14)
Shell ("net use Z: " & "\\ENDOFLINE\STORAGE\" & strData & " /persistent:yes")
Shell ("net use Z: " & "\\ENDOFLINE\STORAGE\" & strData & " /persistent:yes")
MSComm1.Output = strData
Else
ViewRejects.ViewList.AddItem strData & " REJECTED ON " & Now
Label5.Caption = ViewRejects.ViewList.ListCount
Label9.Caption = "Directory exists."
Shell ("net use Z: " & "\\ENDOFLINE\STORAGE\" & strData & " /persistent:yes")
Shell ("net use Z: " & "\\ENDOFLINE\STORAGE\" & strData & " /persistent:yes")
MSComm1.Output = strData
Open "e:\REJECTS.txt" For Append As #1
' For I = 0 To Lis't1.ListCount - 1
Print #1, strData & " REJECTED ON " & Now
' Next
Close #1
Open "e:\" & strData & "\REJECTS.txt" For Append As #2
' For I = 0 To Lis't1.ListCount - 1
Print #2, strData & " REJECTED ON " & Now
' Next
Close #2
End If
End If
' THE REST OF YOUR SCRIPT got compile error below
If Len(strBuffer) = 13 Then
strBuffer = ""
boComplete = True
Else
strBuffer = Mid$(strBuffer, 14)
End If
Else ' I get Compile Error Else Without IF
boComplete = True
End If
Loop Until boComplete = True
End Select
End Sub
Thanks for your help
Regards
Steve
Last edited by sbarber007; Aug 8th, 2012 at 05:08 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|