Need with Help Invalid outside source error - vb6

I am trying to process information with a dead mans program. Every time I try to run it I get Compile error Invalid outside procedure. I've never messed with VB6 before. I've been searching for a solution but I only get help saying it needs to be in sub or something but the threads are closed and I haven't been able to get their solutions to work for me. http://pastebin.com/vR7A7iN5
I think the problem is in this specific section of the code but I am unsure how to place it into a sub or get it to work otherwise.
End Type
Dim recout As statrec
Open "\STAT\PP\QM1409\MGA013A\" For Random As #1 Len = 150
num.recs = LOF(1) / 150
Print num.recs
For Count = 1 To num.recs
Get #1, Count, recout
If recout.mga = "013" Then

It is a big reach to assume this is the only incompatibility, but start by wrapping the code you're talking about now inside a method as Plutonix mentioned. That IS definitely an error. However I would not be surprised if there are more problems.
Example:
Public Sub GetStatRecs()
Dim recout As statrec
Open "\STAT\PP\QM1409\MGA013A\" For Random As #1 Len = 150
num.recs = LOF(1) / 150
Print num.recs
For Count = 1 To num.recs
Get #1, Count, recout
....
Next Count
....
End Sub

Related

Python Speech Recognition Program Tends To Hang In A Certain Place

This program is not complete but is a work in progress.
import speech_recognition as sr
import subprocess as sp
import time, os
r = sr.Recognizer()
print("Voice Recognition Software\n\n******************************************************************************\n")
while True:
r.energy_threshold = 8000
t = None
with sr.Microphone() as source:
success = False
print (">")
audio = r.listen(source)
try:
print("Processing...")
t = r.recognize_google(audio)
print (": " + t)
except sr.UnknownValueError:
print("Unknown input")
continue
except sr.RequestError as e:
print("An error occured at GAPI\nA common cause is lack of internet connection")
continue
if "open" in t:
t = t.replace("open","")
t = t.replace(" ","")
t = t + ".exe"
print (t)
for a,d,f in os.walk("C:\\"):
for files in f:
if files == t.lower() or files == t.capitalize() or files == t.upper():
pat = os.path.join(a,files)
print (pat)
sp.call([pat])
success = True
if success == True:
continue
The problem I'm facing is that after > or Processing the program sometimes stops responding. No error messages or anything, in the shell it just prints > or Processing and stays there.
This happens randomly, the program can function continuously for a long time but at any given moment for whatever reason it freezes. Usually after a minute or 2 it moves onto the next part and starts responding again but that isn't always the case.
I've attempted to create a sort of fail-safe so if it takes too long to respond the program closes and opens again but I was unsuccessful with that so now I'm trying to figure out the root cause of the problem.
Can someone with experience with this sort of thing help me understand why this is happening?
Edit:
I was able to solve the problem. Turns out there is a timeout parameter here r.listen(source).
I was able to solve the problem. Turns out there is a timeout parameter here r.listen(source).

VBScript Error 52 Bad file name or number

I have a VBScript which is used in Avaya CMS to generate a CSV every 3 seconds. This CSV is then read on each change by a node server.
Every now and then it will throw an error (Error 52) and it then requires someone to manually click OK on the prompt and then it continues.
I didn't write the initial script, but I have been trying to fix it so it doesn't throw this error.
As far as I understand, the issue is being caused when the script tries to write to the file when the node server is trying to read the file.
So far I have tried to fix this by making the file read only, then, in the script it makes it writeable, writes to it and makes it read only again.
I thought this had fixed the issue, but I have received Error 52 pop up again and now I am unsure.
Does anyone know if there is a way to get VB/Avaya to ignore the error? I was thinking something like putting On Error Resume Next before the line that writes the file?
I know ignoring errors is not good practice, but in this case, if it does ignore it, it just means the file wont be updated on this loop, but 3 seconds later it will loop again so it should be fine.
Script:
On Error Resume Next
cvsSrv.Reports.ACD = 1
Set Info = cvsSrv.Reports.Reports("Real-Time\Designer\Skill Status")
If Info Is Nothing Then
Else
b = cvsSrv.Reports.CreateReport(Info,Rep)
If b Then
Rep.RefreshInterval = 3
Rep.SetProperty "Split/Skill","5"
Set WshShell = CreateObject("WScript.Shell")
theHTMLLocation = "C:\wamp\www\wallboards\agent_status.csv"
theSleepFile = "C:\wamp\www\wallboards\sleep.vbs"
theTemplateLocation = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set gfile = fso.GetFile("C:\wamp\www\wallboards\agent_status.csv")
Do While Rep.Window.Caption <> ""
gfile.Attributes = 0
d = Rep.ExportData("C:\wamp\www\wallboards\agent_status.csv", 44, 0, False, True, True)
gfile.Attributes = 1
WshShell.Run "wscript.exe """ & theSleepFile & """", , True
Loop
If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing
End If
End If
Set Info = Nothing
P.S - I left out some Parameters at that start of the file which I don't think are relevant, if someone thinks they are I will add them.

Spss (mrScriptBasic) error handling obtain code where error occured

Hello I am currently using IBM Spss, and I was wondering if there is a way when the code throws an exception to be able to obtain the line of code where the exception occurred? I am able to obtain the line number is there a way to access the stack of the lines that were executed and pull this information from there? Any ideas would be great Thank you in advance!
For Example:
Dim x, y, z
On Error Goto ErrorHandler
x = 30
y = 0
z = x / y 'would like to grab this code since this is where the error occurred
Exit
ErrorHandler:
debug.Log(Err.Description + _
" error occurred on line number " + _
CText(Err.LineNumber))
No, there is no way to map the line number to the actual code unless you keep your own index, allowing for macro expansion etc.
What you can do, though, is to submit the code in blocks and catch the exception for that block, which narrows down the location. In the limit, if each line is its own block, you will know exactly where the error occurred.

dbDenyWrite still in force after recordset closed

I have some code that gets a value from another table, then updates the value in the table. This code is in a loop that performs for each item in recordset based on another table. The code works the first time through but the next time it errors on the first line saying access is denied because the table is being held by another use or the user interface. The code uses DAO.
Anyone have a clue as to why the dbDenyWrite is still in force after closing the recordset and destroying its reference?
Here is a code snippet:
Set rsRR = DataDB.OpenRecordset("Railroads", dbOpenTable, dbDenyWrite)
rsRR.Index = "Railroads_RRIx"
rsRR.Seek "=", RTrs!RR
If rsRR.NoMatch Then
' Write ERROR MESSAGE
rsRR.Close
Set rsRR = Nothing
GoSub CleanUp
ReverseRouteDataCollect = 0
Exit Function
End If
If Not dWork Is Nothing Then Set dWork = Nothing
Set dWork = New Scripting.Dictionary
FieldsSave dWork, rsRR
i = FieldsCopy(drr, dWork, "TemplatesRailroad")
If dWork(rsRR.Name & "$LastWaybillNo") = "999999" Then
rsRR.Edit
rsRR!LastWaybillNo = 2001
rsRR.Update
Else
rsRR.Edit
rsRR!LastWaybillNo = dWork(rsRR.Name & "$LastWaybillNo") + 1
rsRR.Update
End If
rsRR.Close
Set rsRR = Nothing
.. why the dbDenyWrite is still in force after closing the recordset
and destroying its reference?
Because you only do this in case of a NoMatch.
So either change the dbDenyWrite to allow for edits, or (slower) reset the recordset before starting editing it:
Set rsRR = DataDB.OpenRecordset("Railroads", dbOpenTable)

Using parfor and labSend/labRecieve

I want to run two matlab scripts in parallel for a project and communicate between them. The purpose of this is to have one script do image analysis and sending the results to the other which will use it for more calculations (time consuming, but not related to the task of finding stuff in the images). Since both tasks are time consuming, and should preferably be done in real time, I believe that parallelization is necessary.
To get a feel for how this should be done I created a test script to find out how to communicate between the two scripts.
The first script takes a user input using the built in function input, and then using labSend sends it to the other, which recieves it, and prints it.
function [blarg] = inputStuff(blarg)
mpiInit(); %added because of error message, but do not work...
for i=1:2
labBarrier; % added because of error message
inp = input('Enter a number to write');
labSend(inp);
if (inp == 0)
break;
else
i = 1;
end
end
end
function [ blarg ] = testWrite( blarg )
mpiInit(); % added because of error message, but does not help
par = 0;
if ( blarg == 0)
par = 1;
end
for i = 1:10
if (par == 1)
labBarrier
delta = labReceive();
i = 1;
else
delta = input('Enter number to write');
end
if (delta == 0)
break;
end
s = strcat('This lab no', num2str(labindex), '. Delta is = ')
delta
end
end
%%This is the file test_parfor.m
funlist = {#inputStuff, #testWrite};
matlabpool(2);
mpiInit(); % added because of error message, but does not help
parfor i=1:2
funlist{i}(0);
end
matlabpool close;
Then, when the code is run, the following error message appears:
Starting matlabpool using the 'local' profile ... connected to 2 labs.
Error using parallel_function (line 589)
The MPI implementation has not yet been loaded. Please
call mpiInit.
Error stack:
testWrite.m at 11
Error in test_parfor (line 8)
parfor i=1:2
Calling the method mpiInit does not help... (Called as shown in the code above.)
And nowhere in the examples that mathworks have in the documentation, or on their website, show this error or what to do with it.
Any help is appreciated!
You would typically use constructs such as labSend, labRecieve and labBarrier within an spmd block, rather than a parfor block.
parfor is intended for implementing embarrassingly parallel algorithms, in other words algorithms that consist of multiple independent tasks that can be run in parallel, and do not require communication between tasks.
I'm stretching my knowledge here (perhaps someone more expert can correct me), but as I understand things, it does not set up an MPI ring for communication between workers, which is probably the explanation for the (rather uninformative) error message you're getting.
An spmd block enables communication between workers using labSend, labRecieve and labBarrier. There are quite a few examples of using them all in the documentation.
Sam is right that the MPI functionality is not enabled during parfor, only during spmd. You need to do something more like this:
spmd
funlist{labindex}(0);
end
(Sam is also quite right that the error message you saw is pretty unhelpful)

Resources