Waiting Loop ?

Waiting Loop ?

Anonymous
Not applicable
259 Views
1 Reply
Message 1 of 2

Waiting Loop ?

Anonymous
Not applicable
HI

Long story short with 2008 we are no-longer using our in house erp program ans are moving into the "real" world so i have to fix up the code we use to send data to the new erp/mrp system.
Basically i have to send a text file from inventor to a "spooller" location which the erp system monitors if it detects a file in the location it processes the information in it and appends some information to it and saves it back to a folder on the local hard drive where i need Inventror to open it and read the new information back into the part / assembly files iProps. At the moment all the code is working except for the waiting loop where Inventor needs to wait and check if the file has been placed in the local folder. In testing this has taken anywhere betweem 1.9 seconds and almost 1 minute.
I need a way of having Inventor loop around checking for this file and then when it appears triggering the next section of code to strip the text file down etc. I want to do this without setting a wait for 60 seconds for the odd time that it does take this long. so ant help would be appreciated.

Daren

M90 84.26 XPSP2 4 GB

Dim oSAPDataFile As String
oSAPDataFile = Format(Time, "HH-MM-SS")

' Open file for output.
Open "C:\SAP Test Files\out\" & oSAPDataFile & ".txt" For Output As #1

'Set variables to pass to SAP
Dim oSAPDName As String
Dim oSAPDNameLen As String
oSAPDNameLen = Len(FileName.Text)
oSAPDName = Left(FileName.Text, oSAPDNameLen - 4)

' Write comma-delimited data.
Write #1, oSAPDName, SAPMaterialType.Text, SAPUOM.Text, SAPWeight.Text

Close #1

Dim oSAPPNIN As String
'this is where i need to loop inventor until it finds the file
Open "c:\SAP Test Files\in\" & oSAPDataFile &".txt" For Input As #1
'loop again
Line Input #1, oSAPPNIN

SAPPartNumber.Text = oSAPPNIN
Close #1

End Sub
0 Likes
260 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Well

After many days of trial and error(s) i figured something out. Possibly not the best coding but i does work.
But i am still open to a better way of soing it if anyone has any ideas.

Daren

M90 84.26 XPSP2 4 GB

Private Sub GoSAP_Click()

Dim oSAPDataFile As String
oSAPDataFile = Format(Time, "HH-MM-SS")

'Open file for output.
Open "C:\SAP Test Files\out\" & oSAPDataFile & ".txt" For Output As #1

'Set variables to pass to SAP
Dim oSAPDName As String
Dim oSAPDNameLen As String
oSAPDNameLen = Len(FileName.Text)
oSAPDName = Left(FileName.Text, oSAPDNameLen - 4)

'Write comma-delimited data to spooler location
Write #1, oSAPDName, SAPMaterialType.Text, SAPUOM.Text, SAPWeight.Text
Close #1

Dim inSAP As String
'Wait here until SAP passes part Number back
Do Until inSAP <> ""
inSAP = Dir("C:\SAP Test Files\in\" & oSAPDataFile & ".txt")
Loop

'Pause to allow permission state change
Dim PauseTime, Start
PauseTime = 1 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
Loop

'Open file with Part Number and pass back to dialog box
Dim oSAPPNIN As String
Open "C:\SAP Test Files\in\" & oSAPDataFile & ".txt" For Input As #1
Line Input #1, oSAPPNIN
SAPPartNumber.Text = oSAPPNIN
Close #1

'Delete Part Number file from spooler location
Kill ("C:\SAP Test Files\in\" & oSAPDataFile & ".txt")

End Sub
0 Likes