Hello all. The basis behind the application I am designing is that a file is imported into my database every morning and a series of steps are performed, generating reports and letters that print automatically. Everything is automated so that the user hits "Start" and knows nothing about how or why it happens, it just does....
The major hurdle has been the attempt to seamlessly import the file from the user's database. After many hours playing with different ways of importing, I thought that the following code was getting the job done: (I will not pretend to know what type of import this is, I just know that it basically worked....)
dim inputs as p
inputs=table.open("user inputs")
import_destination_table = filename_decode("import.dbf")
'this line reads where the user saved the file that is to 'be imported
import_filename = filename_decode(inputs.filename)
if file.exists(import_filename) = .f. then
ui_msg_box("Error","File to import not found: '"+import_filename+"'.",ui_stop_symbol)
end
end if
import.type = 0
import.names = "use"
import.file = import_filename
import.db = import_destination_table
import.skip_lines = 0
import.skip_bytes = 0
import.field_sep = " "
import.record_sep = ""
import.text_qualifier = ""
import.record_len = 294
import.rem_blanks = .F.
import.escape_newlines = .F.
import.fields = 25
import.field1 = "account_number,n,0,19,0"
import.field2 = "name,c,1,50,0"
import.field3 = "name_2,c,2,50,0"
import.field4 = "address1,c,3,50,0"
import.field5 = "address2,c,4,50,0"
import.field6 = "address3,c,5,50,0"
import.field7 = "city,c,6,50,0"
import.field8 = "state,c,7,50,0"
import.field9 = "zip,c,8,16,0"
import.field10 = "zip2,c,9,16,0"
import.field11 = "home_phone,c,10,20,0"
import.field12 = "branch,n,11,19,0"
import.field13 = "acct_type,n,12,19,0"
import.field14 = "officer,c,13,20,0"
import.field15 = "dda_balance,n,14,19,2"
import.field16 = "ytd_average,n,15,19,2"
import.field17 = "days_od,n,16,19,0"
import.field18 = "of_deposits,n,17,19,0"
import.field19 = "o_d_limit,n,18,19,0"
import.field20 = "ytd_nsfs,n,19,19,0"
import.field21 = "times_o_d_ytd,n,20,19,0"
import.field22 = "date_last_deposit,d,21,8,0"
import.field23 = "date_opened,d,22,8,0"
import.field24 = "date_entered_od,d,23,8,0"
import.field25 = "holds,n,24,19,2"
import()
'Add the import destination table to the database....
file_add_to_db(table.filename_get(import_destination_table))
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
'*******************************************************
The problem is that for fields with dollar amounts and/or negative numbers (dda_balance, ytd_average, od_limit), the file to be imported contains parentheses "()" for negative amounts and dollar signs "$" for everything in these three fields, oh yeah, and commas too. Therefore, these characters cause the values to become zero, as my table has these fields designated as numeric. I do many calculations with these numbers and really need them to remain numeric.
So, I noticed that importing the data from Excel using the ODBC Import Genie allows the data to remain numeric, i.e. the genie recognizes that the data is numeric, and negative. This is great, but my users will use Runtime, which will not support the ODBC Import Genie.
So, I am back to where I was.
Here are my options as I see them, this is where I would really appreciate some ideas and experience!
1) Redefine my table's fields as character and import the data as such. Then somehow find a way to strip the dollar signs, commas, and replace the parentheses with a minus sign "-". Then dump the data into a new field that is numeric. (I have no idea if this can be done and how difficult it will be...)
2) See if my users can save the import data as a different type of file that will enable Alpha to recognize these problem fields as numeric.
3) See if my users can save the import data without the characters (dollar signs and parentheses).
Well, if you've read this far I truely appreciate it! I am stupped and am greatful for any suggestions.
Dave
The major hurdle has been the attempt to seamlessly import the file from the user's database. After many hours playing with different ways of importing, I thought that the following code was getting the job done: (I will not pretend to know what type of import this is, I just know that it basically worked....)
dim inputs as p
inputs=table.open("user inputs")
import_destination_table = filename_decode("import.dbf")
'this line reads where the user saved the file that is to 'be imported
import_filename = filename_decode(inputs.filename)
if file.exists(import_filename) = .f. then
ui_msg_box("Error","File to import not found: '"+import_filename+"'.",ui_stop_symbol)
end
end if
import.type = 0
import.names = "use"
import.file = import_filename
import.db = import_destination_table
import.skip_lines = 0
import.skip_bytes = 0
import.field_sep = " "
import.record_sep = ""
import.text_qualifier = ""
import.record_len = 294
import.rem_blanks = .F.
import.escape_newlines = .F.
import.fields = 25
import.field1 = "account_number,n,0,19,0"
import.field2 = "name,c,1,50,0"
import.field3 = "name_2,c,2,50,0"
import.field4 = "address1,c,3,50,0"
import.field5 = "address2,c,4,50,0"
import.field6 = "address3,c,5,50,0"
import.field7 = "city,c,6,50,0"
import.field8 = "state,c,7,50,0"
import.field9 = "zip,c,8,16,0"
import.field10 = "zip2,c,9,16,0"
import.field11 = "home_phone,c,10,20,0"
import.field12 = "branch,n,11,19,0"
import.field13 = "acct_type,n,12,19,0"
import.field14 = "officer,c,13,20,0"
import.field15 = "dda_balance,n,14,19,2"
import.field16 = "ytd_average,n,15,19,2"
import.field17 = "days_od,n,16,19,0"
import.field18 = "of_deposits,n,17,19,0"
import.field19 = "o_d_limit,n,18,19,0"
import.field20 = "ytd_nsfs,n,19,19,0"
import.field21 = "times_o_d_ytd,n,20,19,0"
import.field22 = "date_last_deposit,d,21,8,0"
import.field23 = "date_opened,d,22,8,0"
import.field24 = "date_entered_od,d,23,8,0"
import.field25 = "holds,n,24,19,2"
import()
'Add the import destination table to the database....
file_add_to_db(table.filename_get(import_destination_table))
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
'*******************************************************
The problem is that for fields with dollar amounts and/or negative numbers (dda_balance, ytd_average, od_limit), the file to be imported contains parentheses "()" for negative amounts and dollar signs "$" for everything in these three fields, oh yeah, and commas too. Therefore, these characters cause the values to become zero, as my table has these fields designated as numeric. I do many calculations with these numbers and really need them to remain numeric.
So, I noticed that importing the data from Excel using the ODBC Import Genie allows the data to remain numeric, i.e. the genie recognizes that the data is numeric, and negative. This is great, but my users will use Runtime, which will not support the ODBC Import Genie.
So, I am back to where I was.
Here are my options as I see them, this is where I would really appreciate some ideas and experience!
1) Redefine my table's fields as character and import the data as such. Then somehow find a way to strip the dollar signs, commas, and replace the parentheses with a minus sign "-". Then dump the data into a new field that is numeric. (I have no idea if this can be done and how difficult it will be...)
2) See if my users can save the import data as a different type of file that will enable Alpha to recognize these problem fields as numeric.
3) See if my users can save the import data without the characters (dollar signs and parentheses).
Well, if you've read this far I truely appreciate it! I am stupped and am greatful for any suggestions.
Dave
Comment