Alpha Video Training
Results 1 to 3 of 3

Thread: Keeping numeric field numeric upon importing

  1. #1
    David Farr

    Default Keeping numeric field numeric upon importing

    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"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 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"

    'Add the import destination table to the database....

    '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
    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.


  2. #2
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Boston, MA

    Default RE: Keeping numeric field numeric upon importing

    1. add the function shown below to your database
    2. import the money values as character value.
    3. add fields to your table to hold the numeric values of the money fields.
    4. run an Update operation to update the numeric fields.

    say that the char money field is called "money_c" and the numeric money field is "money_n", the update expression for money_n is: money_to_number(money_c)

    function money_to_number as n (string as c)

    dim decimal_sep as c
    dim thousand_sep as c
    dim currency_prefix as c
    decimal_sep = a5.System_Mode_Get("number.decimal")
    thousand_sep = a5.System_Mode_Get("number.thousand")
    currency_prefix = a5.System_Mode_Get("currency.prefix")

    dim multiplier as n
    multiplier = 1

    string = stritran(string,thousand_sep,"")
    string = stritran(string,currency_prefix,"")
    if atc("(",string) > 0 then
    multiplier = -1
    string = stritran(string,"(","")
    string = stritran(string,")","")
    end if

    money_to_number = multiplier * val(string)

    end function

  3. #3
    David Farr

    Default RE: Keeping numeric field numeric upon importing

    Perfect! Thank you Mr. Rabins for the function and for the instructions on how to use it. It works great!


Similar Threads

  1. Change field to Numeric
    By dparkins in forum Alpha Five Version 5
    Replies: 10
    Last Post: 07-13-2005, 01:35 PM
  2. Numeric Field
    By expollantas in forum Alpha Five Version 5
    Replies: 11
    Last Post: 10-18-2003, 10:08 AM
  3. numeric field bug
    By Daniel Weiss in forum Alpha Five Version 5
    Replies: 7
    Last Post: 07-08-2003, 08:25 AM
  4. Blank numeric field
    By in forum Alpha Five Version 5
    Replies: 2
    Last Post: 12-27-2002, 12:06 PM
  5. Numeric 0 vs. numeric blank
    By John Gamble in forum Alpha Five Version 4
    Replies: 26
    Last Post: 01-30-2001, 05:53 PM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts