Attempted READ of key larger than file maximum key size - universe

I'm running a program to help document what is contained in our 30+year old database. During the course of this process, I am getting the following error message:
Attempted READ of record ID larger than file/table maximum record ID size of 255 characters.
My program is working like this:
LOOP WHILE I <= NUM.FILES
RECORD = ""
FILENAME = FILE.LIST<I>
ERROR = ""
DEBUG.RECORD = ""
HAVE.LOOKED = 0
OPEN 'DICT ':FILENAME TO D.FILE THEN
OPEN FILENAME TO T.FILE THEN
STATEMENT = "SSELECT ONLY DICT ":FILENAME:' BY FIELD.NO WITH FIELD.NO >= 0 AND WITH FIELD.NO <= 900 AND WITH FIELD # ".]"'
DEBUG = ""
PRINT FILENAME
EXECUTE STATEMENT RETURNING DEBUG
LOOP WHILE READNEXT FIELDNAME DO
READ FIELD.RECORD FROM D.FILE, FIELDNAME THEN
IF LEN(FIELDNAME) > BIGGEST.KEY.LEN THEN
BIGGEST.KEY = FIELDNAME
BIGGEST.KEY.LEN = LEN(FIELDNAME)
BIGGEST.KEY.FILE = "DICT ": FILENAME
PRINT FILENAME:" ":LEN(FIELDNAME):" ":FIELDNAME
END
USE.COUNT = ""
USE.LIST = ""
USE.COUNT.STATEMENT = "SELECT ":FILENAME:" WITH ":FIELDNAME:' # ""'
DEBUGS = ""
EXECUTE USE.COUNT.STATEMENT RTNLIST USE.LIST RETURNING DEBUGS
ROW = ""
ROW<1,1> = FIELD.RECORD<2> ; *Attribute Number
ROW<1,2> = FIELDNAME ; *Field Name
ROW<1,3> = FIELD.RECORD<1> ; *Field Type
ROW<1,4> = FIELD.RECORD<10> ; *Field Size
ROW<1,5> = FIELD.RECORD<12> ; *Is Multivalued: "" = no, "Y" = Multivalued, "###" = specific multivalue
ROW<1,6> = FIELD.RECORD<13> ; *Is Subvalued: "" = no, "Y" = Subvalued, "###" = specific subvalue
ROW<1,7> = FIELD.RECORD<7> ; *Automatic data output conversion
ROW<1,8> = FIELD.RECORD<8> ; *Correlative field definition
ROW<1,9> = FIELD.RECORD<11> ; *Field description
ROW<1,10> = #SELECTED ; *Number of records that don't have this field blank
RECORD<-1> = ROW
IF ROW<1,10> < 1 THEN
READ UNUSED.FIELDS FROM CHUCK.WORK, "FILE.DEBUG.UNUSED.FIELDS" ELSE
UNUSED.FIELDS = ""
END
UNUSED.FIELDS<-1> = FILENAME:VM:ROW
WRITE UNUSED.FIELDS ON CHUCK.WORK, "FILE.DEBUG.UNUSED.FIELDS"
END
IF FIELD.RECORD<2> = 0 AND #SELECTED > 0 AND HAVE.LOOKED = 0 THEN
LOOP WHILE READNEXT KEY FROM USE.LIST DO
IF LEN(KEY) > BIGGEST.KEY.LEN THEN
BIGGEST.KEY = KEY
BIGGEST.KEY.LEN = LEN(KEY)
BIGGEST.KEY.FILE = FILENAME
PRINT FILENAME:" ":LEN(KEY):" ":KEY
END
REPEAT
HAVE.LOOKED = 1
END
END
REPEAT
END ELSE
ERROR<-1> = "Failed to open file '":FILENAME:"'"
END
END ELSE
ERROR<-1> = "Failed to open file DICT '":FILENAME:"'"
END
WRITE RECORD ON CHUCK.WORK, "FILE.":FILENAME
WRITE DEBUG.RECORD ON CHUCK.WORK, "FILE.DEBUG.":FILENAME
READ CHUCK.LOG FROM CHUCK.WORK, "CHUCK.LOG" ELSE
CHUCK.LOG = ""
END
CHUCK.LOG<-1> = "FILE '":FILENAME:"' had ":DCOUNT(RECORD,AM):" fields"
IF ERROR THEN
CHUCK.LOG<-1> = ERROR
ERRORS<-1> = ERROR
END
WRITE CHUCK.LOG ON CHUCK.WORK,"CHUCK.LOG"
CLEARSELECT
I = I + 1
REPEAT
When I look at the database directly, I can't find any record IDs or keys with more than 35 characters in the file which is causing problems, and nothing longer than 70 characters in the entire database. Can anyone help identify why these records are getting flagged in this process but aren't discoverable directly?
Below is a program I wrote to specifically find the problematic records, but it can't find the culprit
OPEN "CHUCK.WORK" TO CHUCK.WORK ELSE
PRINT "UNABLE TO OPEN CHUCK.WORK"
RETURN
END
READ FILENAME FROM CHUCK.WORK, "LISTME" ELSE
PRINT "UNABLE TO READ LISTME"
RETURN
END
NUM.FILES = DCOUNT(FILENAME,AM)
FOR I = 1 TO NUM.FILES
OPEN FILENAME<I> TO T.FILE ELSE
PRINT "UNABLE TO OPEN ":FILENAME<I>
RETURN
END
EXECUTE 'SELECT ':FILENAME<I>
LOOP WHILE READNEXT KEY DO
IF LEN(KEY) > 20 THEN
PRINT FILENAME<I>:" ":LEN(KEY):" ":KEY
END
REPEAT
NEXT I
UPDATE
One of my coworkers identified the source of the problem, even though we haven't identified how to fix the problem:
one of our files has a multivalued field which is a key used in a correlative. For some reason, Universe is trying to read the entire attribute instead of the individual multivalue as the key, which causes the long record IDs. Anyone able to see whether I am doing something wrong in my code or if there is some setting in the database that we need to look at?

When you see this error it has nothing to do with the size of keys in file, it is simply that the #ID you are trying to READ is longer than 255 chars. When I have seen it usually show me what line in the source code it happened on. If you put this right before you that line you should be able to track it down.
IF LEN(THIS.ID) GT 255 THEN
DEBUG
END
Edit. Apparently the error in this case is does not reference a line number. I was not sure if this was omitted for clarity or was some difference in the UniVerse flavor, but I now believe its absence is a hint that the error message is coming from the shell and not that the interpreter.
OPEN '','VOC' TO FILE.VOC ELSE STOP "CANNOT OPEN FILE VOC"
STMT = "SELECT VAL WITH ":STR("A",256):" EQ 0"
EXECUTE STMT RTNLIST USE.LIST RETURNING DEBUGS
CRT "**************************************"
READ TEST FROM FILE.VOC,STR("A",256) ELSE NULL
END
Which on my system outputs this.
>RUN TEST.SC TEST.LONG.ID
Attempted READ of record ID larger than file/table maximum
record ID size of 255 characters.
RetrieVe: syntax error. Unexpected sentence without filename. Token was "".
Scanned command was SELECT 'VAL' WITH 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' EQ '0'
**************************************
Program "TEST.LONG.ID": Line 5, Attempted READ of record ID larger than file/t
able maximum
record ID size of 255 characters.
>
The first looks like your error message and would point to one of the dynamic SELECT statements you are building. #ID is synonymous with with record key and to carry the analogy a little further, it appears that you are trying to unlock your bike with one of those comically large "Keys to the City".

Related

User defined input in a macro

I am trying to create a macro on Fiji (ImageJ). I cannot find how to introduce a user input. I want to sum a stack with z project. Each sum is the result of 10 stacks. But the start is not the same. It varies between 1 and 11. So it would be fine when the user choose a startpoint. when the file is saved, the filename should contain the start and endpoint. So I know some weeks later which stacks I used. Thanks for some hints!
imageTitle=getTitle();
path = "D:/test/";
first = Dialog.getChoice();
// first = 8;
last = first+9;
selectWindow(imageTitle);
run("Z Project...", "start=first stop=last projection=[Sum Slices]");
run("Red");
saveAs("Tiff", path+"SUM_"+imageTitle+"("+first+last+")";
I get the error message:
"No dialog created with Dialog.create() in line 3:
first = Dialog.getChoice> () ;
When I didnt choose the start I get the error message:
" ')' expected in line 9:
saveAs ( "Tiff" , path + "SUM_" + imageTitle + "(" + first + last + ")" <;>

Storing incorrect passwords on .txt file - Python 2.7

I am creating a python program which stores it in a list, then records in a text file called wrongpasswords.txt.
The program should ask the user for input by saying 'Please enter your password: '. The correct password will always be 'rusty' but the user can of course enter any String. And also, how do I add to my program that the number of characters the user inputs wrong is also stored for each incorrect password?
Please do mind me as I am a beginner in programming and python.
Please see my code below:
enteredPass = raw_input("Enter your password: ")
incorrectPass= file("wrongpasswords.txt","w")
counter = 0
for i in range(0, counter+1):
if enteredPass != "rusty":
counter = counter +1
incorrectPassO = open("wrongpasswords.txt","w")
incorrectPassO.write("Incorrect password" +str(counter)+": " + enteredPass + "\n")
incorrectPassO.close()
enteredPass = raw_input("Enter your password: ")
else:
incorrectPassO = open("wrongpasswords.txt","w")
incorrectPassO.write("Correct password entered on the " + str(counter)+"th entry")
incorrectPassO.close()
If I understood correctly you're trying to create a simple login program that counts the wrong login attempts? This should work:
counter = 0
correct_answer_entered = False
while not correct_answer_entered:
enteredPass = raw_input("Enter your password: ")
counter = counter + 1
if enteredPass != "rusty":
incorrectPassO = open("wrongpasswords.txt","a")
incorrectPassO.write("Incorrect password" +str(counter)+": " + enteredPass + "\n")
incorrectPassO.close()
else:
incorrectPassO = open("wrongpasswords.txt","a")
incorrectPassO.write("Correct password entered on the " + str(counter)+"th entry")
incorrectPassO.close()
correct_answer_entered = True
The points I fixed in your code that you should notice:
I replaced the "w" with an "a" where you open the file, since "w" makes it write over what's already wroten in the file, while "a" appends after what's there.
I replaced the for loop with a while, what you did was a range from 0 to 1, so the loop would exit after the first round, I added a boolean value (correct_answer_entered), to indicate if the correct password was entered, and keeps going if it wasn't.
I moved the "counter = counter + 1" outside of the if statement, since the number of attempts is not related to wither the password is correct or not, the way you did it if the password was correct at the first attempt it'd say 0th attempt instead of 1th.
overrall your code is pretty nice and it's good to see new people getting into programming ^.^

Using VBA regex on Array

I am writing a macro and the macro works fine, but I am trying to add some error handling to it so others are using it and an error occurs they are able to figure out what happened. The last problem I am having is I am using the Application.GetOpenFilename to open multiple files with multiselect = True. I am using a regex to match the file name and if the wrong file name is chosen then it displays an error message. If multiselect = False then I get no errors, but when it is equal to True I get a Type Mismatch error. I can only assume this is because when mutliselect = True the file is an array which the regex cannot handle. Is there a solution to this or can anyone point me to a better solution to handle the error. I have attached the VBA script as well.
Sub DataImport_Loop()
Dim nom As String
Dim wb As Excel.Workbook
Dim i, j, k, m, n, file As Variant
Dim strPattern As String: strPattern = "Strain End Point [0-9] - FEA Loop - Loading - (Timed)" 'File Pattern
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
'Turns Screen Updating and Alert Displays off
Application.ScreenUpdating = False
Application.DisplayAlerts = False
nom = ActiveWorkbook.Name
'takes user straight into necessary folder
If CurDir() <> CurDir("J:") Then
ChDrive "J:"
ChDir "J:FEA Material Data"
End If
'Number of specimens tested
For i = 1 To 5
'Allows user to select multiple files to open
file = Application.GetOpenFilename( _
FileFilter:="Text Files (*.csv), *.csv", _
MultiSelect:=True)
'If no file selected, stop data import and display error message
If Not IsArray(file) Then
MsgBox ("You only imported " & (i - 1) & " Specimens.")
Exit Sub
'Sets patteren to check if correct file
With regex
.Pattern = strPattern
End With
'Checks set pattern, displays error message if not correct file
If regex.Test(file) = False Then
MsgBox ("Select Loading Only")
Exit Sub
End If
Else
Counter = 1
While Counter <= UBound(file)
j = (2 * i) - 1
Workbooks.Open file(Counter)
Set wb = Workbooks("Strain End Point " & Counter & " - FEA Loop - Loading - (Timed).csv")
'End of column, needs + 3 to account for first 3 unused cells
k = Range("F4", Range("F4").End(xlDown)).Count + 3
'Loops through data, deletes negative values
For m = 4 To k
If Range("F" & m).value < 0 Or Range("F" & m).Offset(0, 1) < 0 Then
Range("F" & m).Delete
Range("F" & m).Offset(0, 1).Delete
'If cell is deleted, rechecks new value
m = m - 1
End If
Next m
Range("F4:G" & k).Copy
Workbooks(nom).Sheets(Counter + 1).Cells(4, j).PasteSpecial
wb.Close
'Opens next file
Counter = Counter + 1
Wend
End If
Next i
'Turns Screen Updating and Alert Displays back on
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
When MultiSelect is true, file will always be a variant array, even if only a single file is selected. Therefore you must iterate through each element of the array in order to check it against your mask.
With regard to your mask, I would suggest using the Like operator as it seems simpler and will probably run faster. Note the # replacing the regex pattern [0-9]) eg:
'Checks set pattern, displays error message if not correct file
Const strPattern as String = "Strain End Point # - FEA Loop - Loading - (Timed)" 'File Pattern
For I = LBound(file) To UBound(file)
If Not file(I) Like strPattern Then
MsgBox ("Select Loading Only")
Exit Sub
End If
Next I

Text File not Created in ' if ' Statement

I am working on a little program with is able to write and load .txt files.
I am facing an issue, where the .txt file is not created when my save () function is in a "if" loop. I did used the computer's search function just in case that it was created somewhere else. Nope, nothing on the .txt file came out.
For you information, I am coding in Microsoft Visual Studio 2013 (Community), and using Windows 8.
Here are the codes:
def save (dic, filename):
out_file = open (filename, "wt")
key_list = []
for i in dic.keys():
key_list.append (i)
key_list.sort ()
for i in range(len(key_list)):
key = key_list [i]
out_file.write (key + "," + dic [key] + "\n")
out_file.close ()
filename = "dictionary.txt"
count = input ("Save (0) or Load (1): ")
if count == 0:
dic = {}
dic["1"] = "11"
dic ["2"] = "22"
dic ["3"] = "33"
dic ["4"] = "44"
dic ["5"] = "55"
save (dic, filename)
The input function returns a string. Since count is a string, count == 0 is always false. This is because the string '0' and the number 0 are not equal.
You have two options here. You can either convert the count to an integer with count = int(input('...')) and not touch your condition, or you can compare count with the string representation of 0 (count == '0').

VBS Broken If Statement/Logic

My logic/code is pretty simple count rows from a SQL table, store this value to a Registry Key. If the value read from the SQL query is greater than the value of the RegKey, update the value of the RegKey with the query result, and likewise, save the value to a log file. If, the value of the SQL query is equal to the RegKey value, then do not store the result to the RegKey, but write 0 to the log file.
I run this code, and it seems it does not like my IF statements/operators. Testing this, it only seems to work if I set the operation "tempSQLCount(0,0) < strRegKeyVal " or "tempSQLCount(0,0) <> strRegKeyVal". In my scenario, the SQLCounter will never be less than, only greater than, or equal.
strRegKeyVal = readfromRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\SQLCounter1", "ha")
'Dim intRegKeyVal = CInt(strRegKeyVal)
If tempSQLCount(0,0) > strRegKeyVal Then
'update row counter value to regKey
strValueName = "SQLCounter1"
objRegistry.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,tempSQLCount(0,0)
Set objFSO=CreateObject("Scripting.FileSystemObject")
'write to log
outFile="C:\Logs\some.log"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write tempSQLCount(0,0) & vbCrLf
objFile.Close
End If
If tempSQLCount(0,0) = strRegKeyVal Then
'update row counter value to regKey
Set objFSO=CreateObject("Scripting.FileSystemObject")
'write to log
outFile="C:\Logs\some.log"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write 0 & vbCrLf
objFile.Close
End If
Get your logic straight and convert your numbers to the correct type. (This is mostly what the commenters suggested, but comments are hard to read for code improvements):
dim strRegKeyVal, sqlCountToReport, sqlCount
' both values are converted to Int
strRegKeyVal = cInt(readfromRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\SQLCounter1", "ha"))
sqlCount = cInt(tempSQLCount(0,0))
' Conditional registry write part
If sqlCount > strRegKeyVal Then
'update row counter value to regKey
strValueName = "SQLCounter1"
objRegistry.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName, sqlCount
sqlCountToReport = sqlCount
else
sqlCountToReport = 0
End If
' Write to log part
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Logs\some.log", True)
objFile.Write sqlCountToReport & vbCrLf
objFile.Close
Your script consist of two parts: the registry update part and the log write part. Splitting it in two tasks is easier to debug.
The flow is a little bit different; this also covers the case if cInt(tempSQLCount(0,0)) < strRegKeyVal, but that was a case that shouldn't happen anyways.