I am writing a code in VB6 to save and retrieve an image in .dbf file, but i don't know what field type to take in dbf file. Can anyone suggest what field should i take in dbf file and what code should i write in VB6 ??
Thanks in advance..
I have done it in Memo Fields long ago. The code is in foxpro. See:
CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4)) &&Create a table with FileName character field
*And Store as memo field
1.
Append blank &&to add a blank record
APPEND MEMO store from "D:\Shah.Jpg" overwrite
*This will copy the contents of the file. If Overwrite is ignored, and the memo has some contents,
*The contents of the file will be appended to it, which should be avoided.
REPLACE filename WITH "Shah.Jpg"
*Add as many files as you wish to other records.
Copy memo Store to "SomePhoto.jpg" && will copy to the default folder
*Or
Copy memo store to "c:\MyPhotos\Shah.JPG" &&You must save or know the extension of the file
2.
append blank
filedata=FILETOSTR("D:\Shah.JPG")
REPLACE store WITH filedata
STRTOFILE(store,"SomeFileName.JPG")
*OR
STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")
It should solve your problem.
I have done it in Memo Fields long ago. The code is in foxpro. See:
CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4))
*Create a table with FileName character field
*And Store as memo field
Method 1:
Append blank &&to add a blank record
APPEND MEMO store from "D:\Shah.Jpg" overwrite
*This will copy the contents of the file. If Overwrite is ignored, and the memo has some contents, *The contents of the file will be appended to it, which should be avoided.
REPLACE filename WITH "Shah.Jpg"
*Add as many files as you wish to other records.
Copy memo Store to "SomePhoto.jpg"
will copy to the default folder or
Copy memo store to "c:\MyPhotos\Shah.JPG"
*You must save or know the extension of the file
Method 2.
Append blank
filedata=FILETOSTR("D:\Shah.JPG")
REPLACE store WITH filedata
STRTOFILE(store,"SomeFileName.JPG")
*OR
STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")
***It should solve your problem.
This is how I did it In Fox pro 9 it involves saving and retrieving image from MYSQL server.
1. First create table by the name:pictures with two fields image_id (int 10) and image(longBlob).
Now I wrote two function SaveImage RetriveImage"
CLOSE DATABASES
DO SaveImage WITH "C:\Users\Admin\Desktop\New folder (6)\rafay.jpg"
DO RetriveImage WITH "C:\KalimKhan2.jpg"
Function SaveImage
Parameters ImageName
&& Get image info
Create Cursor im (pic Blob)
Appen Blank
Overwrite`enter code here`
Append Memo pic From (ImageName) Overwrite
SQLDisconnect(0)
nconnect = SQLConnect('TEST_BOX','root')
If nconnect < 0
Wait Window 'Connection Failed!' Timeout 1
Return
Else
Wait Window 'Connected. ' Nowait
Endif
nresult = SQLExec(nconnect, [INSERT INTO pictures (image) VALUES (?pic) ] )
If nresult != 1
Aerror(laErr)
List Memory Like laErr To File c:\Error
error1 = .T.
=Aerror(x)
Wait Window " Query failed."
Endif
Return "good"
Function RetriveImage
Parameters ImageName
SQLDisconnect(0)
nconnect = SQLConnect('TEST_BOX','root')
If nconnect < 0
Wait Window 'Connection Failed!' Timeout 1
Return
Else
Wait Window 'Connected. ' Nowait
Endif
CursorSetProp("MapBinary",.T.,0)
nresult = SQLExec(nconnect, [Select * from pictures where image_id = 1 ],"ImageTemp" )
If nresult != 1
Aerror(laErr)
List Memory Like laErr To File c:\Error
error1 = .T.
=Aerror(x)
Wait Window " Query failed."
Endif
nBytes = Strtofile (ImageTemp.Image, (ImageName))
Related
I have a fixed length file like:
0001ABC,DEF1234
The file definition is:
id[1:4]
name[5:11]
phone[12:15]
I need to load this data into a table. I tried to use CSV module and defined the fixed lengths of each field. It is working fine except for the name field.
For the NAME field, only the value till ABC is getting loaded. The reason is:
As I am using CSV module, it is treating 0001ABC, as a value and only parsing till that.
I tried to use escapechar = ',' while reading the file, but it removes the ',' from the data. I also tried quoting=csv.QUOTE_ALL but that didnt work either.
with open("xyz.csv") as csvfile:
readCSV = csv.reader(csvfile)
writeCSV = open("sample_csv", 'w');
output = csv.writer(writeCSV, dialect='excel', lineterminator="\n")
for row in readCSV:
print(row) # to debug #
data= str(row[0])
print(data) # to debug #
id = data[0:4]
name = data[5:11]
phone = data[12:15]
output.writerow([id,name,phone])
writeCSV.close()
Output of the print commands:
row: ['0001ABC','DEF1234']
data: 0001ABC
Ideally, I expect to see the entire set 0001ABC,DEF1234 in the variable: data.
I can then use the parsing as mentioned in the code to break it into different fields.
Can you please let me know where I am going wrong?
Is there a way within a praatscript to query the path and filename of an object.
I want to save a textgrid to the same file I opened (overwite it)
I was think of something like:
selectObject: n
type_name$ = selected$ ()
file_name$ = some_way_to_query_this..., n
type$ = extractWord$ (type_name$, "")
if type$ == "TextGrid"
runScript: "save.praat", file_name$
endif
No. Objects in Praat do not store information about their location on disk because most objects will never exist on disk at all. Objects are not files.
If you are reading an object from a file, and then want to store the object to the same location, then you should store that information elsewhere yourself.
This isn't an answer to your question but to the situation. Depending on how you open the textgrid, you could throw the filename into a string variable and then save to the same name.
file$ = "C:\Users\Me\Desktop\praat\example.TextGrid"
Read from file: file$
Set tier name: 1, "this"
Set tier name: 2, "that"
Save as text file: file$
This answer is quite late but it could be still useful to someone...
The file name, if it exists, can be shown with the Info command.
After selecting an object:
object_info$ = Info
file_name$ = extractLine$(object_info$, "Associated file: ")
writeInfo: file_name$
I need to read the filename of a csv file to extract some information about what to do with the data inside the file. How do I read the filename?
e.g. I will get a file called 200_SomeTestName.csv. The file will contain details of the test to be created. I'm required to create a test called SomeTestName for the student who has an id of 200.
You can list all the CSV files in the dropbox folder and check if they match the pattern. Then extract the information you need and create the test:
Dir.glob('yourdropboxfolder/*.csv').each do |filename|
name = File.basename(filename, '.csv')
if (match = /(\d+)_(.*).csv/.match(name))
student_id = match[1]
test_name = match[2]
create_test_for(student_id, test_name, File.read(filename))
end
end
Not sure if you need to extract the values from the filename or if this information is also in the file.
I have an INPUT_IMAGE_CHECK_ALL function that takes image. In INPUT_IMAGE_CHECK_ALL there are 7 functions that image is passed to.
How do I feed images from folder 1 by 1 to the INPUT_IMAGE_CHECK_ALL function?
image = imread('6-Capmissing/capmissing-image078.jpg');
INPUT_IMAGE_CHECK_ALL(image);
INPUT_IMAGE_CHECK_ALL code:
function [ ] = INPUT_IMAGE_CHECK_ALL( image )
CHECK_FOR_CAP(image);
CHECK_FOR_NOLABEL(image);
CHECK_FOR_NOLABELPRINT(image);
CHECK_FOR_OVERFILLED(image);
CHECK_FOR_LABELNOTSTRAIGHT(image);
CHECK_FOR_UNDERFILLED(image);
end
Images that I want to feed into INPUT_IMAGE_CHECK_ALL are in folder "All" named image001 to image141.
Since you know how the name of the images you want to read (image001, image002, ... from 1 to 141) the easiest way is to use a loop in which:
build the names using the function sprintf
read the image whith the name you've build
feed your function with the image data
A possible implementation could be
for img_idx=1:141
img_name=sprintf('All/image%3.3d.jpg',img_idx)
disp(['Reading ' img_name])
the_image=imread(img_name);
INPUT_IMAGE_CHECK_ALL(the_image);
end
In the above code:
notice the format used in the call to sprintf: %3.3d: this allows padding with 0 the number in the buildoing of the filename, so that you can have 001, 002, ... 013 and so on
if the folder All in which your images are stored is not in the MatlLab path you have to specify the folder in building the filename
I've used the_image as name of the variable in which to store the data of the image because image (the varaible you are using) is a MatLab function.
the call to the disp function is used only to print on the CommandWindow a message about what the script is dooing (which image is processing); you can remove it
If the folder All only the images you you want to process, another possibility could be to get the list of images using the function dir to get the filenames of the
The function dir returns a struct in which the information about the files are stored.
In this case you have to loop over the list returned by dir
% Get the filenames of all the images in the folder "All"
img_list=dir('All/image*.jpg')
% Loops over the list of images
for img_idx=1:length(img_list)
img_name=['All/' img_list(img_idx).name]
disp(['Reading ' img_name])
the_image=imread(img_name)
INPUT_IMAGE_CHECK_ALL(the_image);
end
Hope this helps,
Qapla'
I have to validate an API output with a values stored in Sybase DB.
When I use "select Data" activity to fetch the value from Sybase table, the value is returned in XML format as below:
<Row>
<ColumnName1> Value </ColumnName1>
<ColumnName2> Value </ColumnName2>
<ColumnName3> Value </ColumnName3>
</Row>
However I need only the Value so I can save it in excel to compare in my next step. Comparison is being done on value basis not with xml. I need to convert the response from select data (which is in XML format shown above) .
The subsequent checkpoint in API output fails as I need to provide individual values as input to the service.
I will need a solution that can either split array and give me individual values at run time Or I should be able to save values in Excel which I can save and import at run time.
You can use the COM object for Microsoft's XML Parser. Something like this should do it,
set objXml = CreateObject("Microsoft.XMLDOM")
objXml.Load("C:\yourxmlpath.xml")
' Get your node (you can traverse it like a path)
set allMathchingRows = objXml.selectNodes("/Row")
For intRow = 0 To allMathchingRows.Length - 1
For each Node in allMathchingRows(intRow).ChildNodes
strAllRowData = strAllRowData + "," + Node.text
Next
' Remove the ' appended to the start of string
strAllRowData = Right(strAllRowData, Len(strAllRowData) - 1)
Next
you may want to refine it more if you want your data separate for each rows