Alpha DevCon 2018
Results 1 to 11 of 11

Thread: I need some formatting help

  1. #1
    Member
    Real Name
    Steven Greer
    Join Date
    Jun 2008
    Location
    Manchester,PA
    Posts
    375

    Default I need some formatting help

    I have some files that I upload via ftp and some are *.doc and some *.docx and also *.pdf. I am having trouble with formatting the correct extensions and also working with spaces in file name, if there is file names and it's a *.docx 4 char extension all works but if not I get errors. I have prepared some sample code with special information removed for security purposes.

    The process is that user selects file to upload I use the shell to run and AES encryption to the file and then delete the unencrypted file, and upload to server via ftp then delete the uploaded *.aes encrypted file, write to sql database the filename derived from the description. Like I said works fine if there is a 4 char extension and no spaces in the filename of the selected file.

    Here is the code I am using
    Code:
    'Date Created: 31-Mar-2016 09:59:28 AM
    'Last Updated: 21-Feb-2018 01:59:58 PM
    'Created By  : Steve
    'Updated By  : hubby
    'Prompt for text and store result in a variable called 'ftype'.
    'Get 'Value' property of 'Idclientd' in Form 'clientstart' .
    DIM window_name as C
    window_name = ":"+"credmaster"
    DIM varP_Object as p
    'Get a pointer to the specified window
    varP_Object = obj(window_name)
    'Check if the specified window exists
    if .not. is_object(varP_Object) then 
    	ui_msg_box("Error","The window '"+window_name+"' does not exist.",ui_stop_symbol)
    else
    	DIM SHARED clientid AS n
    	clientid = varP_Object:Idclientd.value
    end if
    dim prmpt_title as c 
    dim prmpt_prompt as c 
    dim prmpt_default as c 
    
    prmpt_title = "Description"
    prmpt_prompt = "File Description"
    prmpt_default = ""
    	
    DIM SHARED ftype AS C
    	
    ftype = ui_get_text(prmpt_title,prmpt_prompt,prmpt_default)
    	'Prompt for a filename and store result in a variable called 'fname'.
    'Prompt for a filename and store result in a variable called 'fname'.
    dim prmpt_title as c 
    dim prmpt_filter as c 
    dim prmpt_default as c 
    dim prmpt_flag as c 
    
    prmpt_title = a5_eval_expression("=\"Choose File\"",local_variables())
    prmpt_filter = "(*.*)"
    prmpt_default = ""
    
    DIM fname AS C
    
    fname = ui_get_file( a5_eval_expression(prmpt_title,local_variables()),prmpt_filter,prmpt_default,"X")
    
    
    
    if ftype ="" 
    	ui_msg_box("error","You Didn't Choose a File Description",UI_STOP_SYMBOL)
    	end 
    	end if
    	if fname="" 
    		ui_msg_box("error","You Didn't Choose a File",UI_STOP_SYMBOL)
    		end 
    		end if
    sys_shell_wait("c:\housing\aescrypt -e -p magic_key_removed "fname,.F.)
    dim extn as c
    extn = right(fname,4)
    xbasic_wait_for_idle(2)
    
    dim st as c
    dim en as c
    st = "\\"
    
    en = " "
    dim shared upname as c
     upname=".aes"
    dim ftsend as c
    ftsend=ftype+"."+extn+upname
    				
    				
    	cmd = <<%a%
    connect|********
    onerror|error|Could not connect
    login|*****|*******
    onerror|error|Could not log in
    mkdir|%a%"/srv/ftp/clientdocs/credit/" + clientid + crlf() + <<%a%
    onerror|quit
    quit 
    %a% 
    ftp_script_run_silent(cmd, .t.)
    				
    							
    				
    ftp_put_file("192.168.69.149", "******", "******", fname+".aes","/srv/ftp/clientdocs/credit/"+clientid+"/"+ftsend,.f.,"Uploading File")
    'Insert a new record into a remote SQL database.
    'DIM a connection variable
    DIM cn as SQL::Connection
    dim flagResult as l 
    flagResult = cn.open("::Name::pat")
    if flagResult = .f. then 
    	ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text)
    	end 
    end if
    
    'Specify that we are using Portable SQL syntax
    cn.PortableSQLEnabled = .t.
    dim shared agent as c
    agent=user_name()
    'Dim a SQL arguments object, create arguments and set their values
    DIM args as sql::arguments
    
    
    if a5_eval_valid_expression("=clientid",local_variables()) then 
    	args.add("idclientd",convert_type(a5_eval_expression("=clientid",local_variables()),"N"))
    end If
    if a5_eval_valid_expression("=ftsend",local_variables()) then 
    	args.add("doc_type",convert_type(a5_eval_expression("=ftsend",local_variables()),"C"))
    end If
    if a5_eval_valid_expression("=agent",local_variables()) then 
    	args.add("doc_who",convert_type(a5_eval_expression("=agent",local_variables()),"C"))
    end If
    
    
    dim sqlInsertStatement as c 
    sqlInsertStatement = <<%txt%
    INSERT INTO cred_docs  (idclientd, doc_type, doc_who) VALUES (:idclientd, :doc_type, :doc_who)
    %txt%
    
    dim flag as l 
    flag = cn.Execute(sqlInsertStatement,args)
    if flag = .f. then 
    	ui_msg_box("Error","Record was not inserted. Error reported was: " + crlf(2) + cn.CallResult.text,UI_STOP_SYMBOL)
    else
    	if cn.AffectedRows() = 1 then 
    		ui_msg_box("Notice","File Has Been  Uploaded..",UI_INFORMATION_SYMBOL)
    	else
    		ui_msg_box("Error","File Has Not Been Uploaded." ,UI_STOP_SYMBOL)
    	end if 
    end if 
    cn.close()  
    xbasic_wait_for_idle(1)
    file.remove(fname)
    file.remove(ftsend)
    delete fname
    delete ftsend

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,108

    Default Re: I need some formatting help

    extn = file.filename_parse(fname,"E")

    will return the extension with the period as in .doc or .docx. Strtran(file.filename_parse(fname,"E"),".","") will remove the period.

    Seems

    sys_shell_wait("c:\housing\aescrypt -e -p magic_key_removed "fname,.F.)

    should be

    sys_shell_wait("c:\housing\aescrypt -e -p magic_key_removed "+fname,.F.)
    There can be only one.

  3. #3
    Member
    Real Name
    Steven Greer
    Join Date
    Jun 2008
    Location
    Manchester,PA
    Posts
    375

    Default Re: I need some formatting help

    I had the +fname in there must have removed it when editing. The thing I'm having the hardest time with is the spaces in the file name when running the sys_shell_wait() command because some people save files such as ex"this file.txt" instead of "this_file.txt" and the command line don't like spaces in the file names

    so the command would look like

    sys_shell_wait("c:\housing\aescrypt -e -p magic_key_removed c:\Desktop\file to test.doc",.F.) and the encryption program won't run because it comes backs can't find c:\Desktop\file i'm going to ponder on this for a little bit because i'm sure there is a way i can work the string and add chr(092) before and after the selected file somehow.
    Last edited by steve745; 02-21-2018 at 03:14 PM.

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,108

    Default Re: I need some formatting help

    Rename the file for them.

    Just after

    fname = ui_get_file( a5_eval_expression(prmpt_title,local_variables()),prmpt_filter,prmpt_default,"X")

    add

    if at(" ",fname) > 0
    file.rename(fname,strtran(fname," ","_"))
    end if

    This will replace spaces with underlines. You really don't have to test for at(" ",fname) > 0. file.rename(fname,strtran(fname," ","_")) won't alter the filename if there are no spaces.
    There can be only one.

  5. #5
    Member
    Real Name
    Steven Greer
    Join Date
    Jun 2008
    Location
    Manchester,PA
    Posts
    375

    Default Re: I need some formatting help

    ok so I put this in the interactive window because I keep getting file not found
    Code:
    dim prmpt_title as c 
    dim prmpt_prompt as c 
    dim prmpt_default as c 
    
    prmpt_title = "Description"
    prmpt_prompt = "File Description"
    prmpt_default = ""
    	
    DIM SHARED ftype AS C
    	
    ftype = ui_get_text(prmpt_title,prmpt_prompt,prmpt_default)
    	'Prompt for a filename and store result in a variable called 'fname'.
    'Prompt for a filename and store result in a variable called 'fname'.
    dim prmpt_title as c 
    dim prmpt_filter as c 
    dim prmpt_default as c 
    dim prmpt_flag as c 
    
    prmpt_title = a5_eval_expression("=\"Choose File\"",local_variables())
    prmpt_filter = "(*.*)"
    prmpt_default = ""
    
    DIM fname AS C
    
    fname = ui_get_file( a5_eval_expression(prmpt_title,local_variables()),prmpt_filter,prmpt_default,"X")
    'if at(" ",fname) > 0
    file.rename(fname,strtran(fname," ","_"))
    'end if
    ?fname
    = "C:\Users\hubby\Desktop\credmed\Contract_and_CC_auth_addendum\Credit Card Authorization Credit Repair.docx"
    
    'tried with fname=file.rename(fname,strtran(fname," ","_"))
    ?fname
    = "0"
    it is renaming the file but how to I tell fname the new renamed filename?

  6. #6
    Member
    Real Name
    Steven Greer
    Join Date
    Jun 2008
    Location
    Manchester,PA
    Posts
    375

    Default Re: I need some formatting help

    Nevermind just used help and put in file.rename and got the correct way to get the new filename thanks stan very much

  7. #7
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,108

    Default Re: I need some formatting help

    fname=strtran(fname," ","_")
    There can be only one.

  8. #8
    Member
    Real Name
    Steven Greer
    Join Date
    Jun 2008
    Location
    Manchester,PA
    Posts
    375

    Default Re: I need some formatting help

    OK so I made some changes because I found that a user has a path such as c:\user\this user\Downloads and the file rename was giving errors and now I'm testing and I got stuck at the ftp transfer

    the code im using is edited for security purposes
    Code:
    'Date Created: 31-Mar-2016 09:59:28 AM
    'Last Updated: 21-Feb-2018 04:50:28 PM
    'Created By  : Steve
    'Updated By  : hubby
    'Prompt for text and store result in a variable called 'ftype'.
    'Get 'Value' property of 'Idclientd' in Form 'clientstart' .
    DIM window_name as C
    window_name = ":"+"credmaster"
    DIM varP_Object as p
    'Get a pointer to the specified window
    varP_Object = obj(window_name)
    'Check if the specified window exists
    if .not. is_object(varP_Object) then 
    	ui_msg_box("Error","The window '"+window_name+"' does not exist.",ui_stop_symbol)
    else
    	DIM SHARED clientid AS n
    	clientid = varP_Object:Idclientd.value
    end if
    dim prmpt_title as c 
    dim prmpt_prompt as c 
    dim prmpt_default as c 
    
    prmpt_title = "Description"
    prmpt_prompt = "File Description"
    prmpt_default = ""
    	
    DIM SHARED ftype AS C
    	
    ftype =alltrim(ui_get_text(prmpt_title,prmpt_prompt,prmpt_default))
    'Prompt for a filename and store result in a variable called 'fname'.
    'Prompt for a filename and store result in a variable called 'fname'.
    dim prmpt_title as c 
    dim prmpt_filter as c 
    dim prmpt_default as c 
    dim prmpt_flag as c 
    
    prmpt_title = a5_eval_expression("=\"Choose File\"",local_variables())
    prmpt_filter = "(*.*)"
    prmpt_default = ""
    
    DIM shared fname AS C
    
    fname =alltrim(ui_get_file( a5_eval_expression(prmpt_title,local_variables()),prmpt_filter,prmpt_default,"X"))
    dim dr as c
    dr=file.filename_parse(fname,"d")
    dim pth as c
    pth=file.filename_parse(fname,"p")
    dim fext as c
    fext=file.filename_parse(fname,"e")
    dim fn as c
    fn=file.filename_parse(fname,"ne")
    dim fupath as c
    fupath=alltrim(chr(34)+dr+pth+fn+chr(34))
    dim encfu as c
    encfu=alltrim(chr(34)+dr+pth+fn+".aes"+chr(34))
    'if at(" ",fn) > 0
    'file.rename(dr+pth+fn,strtran(dr+pth+fn," ","_"))
    'end if
    
    
    if ftype ="" 
    	ui_msg_box("error","You Didn't Choose a File Description",UI_STOP_SYMBOL)
    	end 
    	end if
    	if fname="" 
    		ui_msg_box("error","You Didn't Choose a File",UI_STOP_SYMBOL)
    		end 
    		end if
    sys_shell_wait(chr(34)+"c:\housing\aescrypt -e -p ******** "fupath)
    
    'dim extn as c
    'extn=Strtran(file.filename_parse(fname,"E"),".","")
    
    'xbasic_wait_for_idle(2)
    
    'dim st as c
    'dim en as c
    'st = "\\"
    '
    'en = " "
    dim upname as c
     upname=".aes"
    'dim ftsend as c
    'ftsend=ftype+"."+upname
    dim ftppath as c
    ftppath =alltrim("/srv/ftp/clientdocs/credit/"+clientid+chr(47)+ftype+fext+upname)
    	cmd = <<%a%
    connect|*****
    onerror|error|Could not connect
    login|*****|*******
    onerror|error|Could not log in
    mkdir|%a%"/srv/ftp/clientdocs/credit/" + clientid + crlf() + <<%a%
    onerror|quit
    quit 
    %a% 
    ftp_script_run_silent(cmd, .t.)
    				
    		xbasic_wait_for_idle(2)					
    				
    FTP_FILE_XFER("******","****","****",alltrim(encfu),alltrim(ftppath),"put")
    'Insert a new record into a remote SQL database.
    'DIM a connection variable
    'DIM cn as SQL::Connection
    'dim flagResult as l 
    'flagResult = cn.open("::Name::pat")
    'if flagResult = .f. then 
    '	ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text)
    '	end 
    'end if
    '
    ''Specify that we are using Portable SQL syntax
    'cn.PortableSQLEnabled = .t.
    'dim shared agent as c
    'agent=user_name()
    ''Dim a SQL arguments object, create arguments and set their values
    'DIM args as sql::arguments
    '
    '
    'if a5_eval_valid_expression("=clientid",local_variables()) then 
    '	args.add("idclientd",convert_type(a5_eval_expression("=clientid",local_variables()),"N"))
    'end If
    'if a5_eval_valid_expression("=ftsend",local_variables()) then 
    '	args.add("doc_type",convert_type(a5_eval_expression("=ftsend",local_variables()),"C"))
    'end If
    'if a5_eval_valid_expression("=agent",local_variables()) then 
    '	args.add("doc_who",convert_type(a5_eval_expression("=agent",local_variables()),"C"))
    'end If
    '
    '
    'dim sqlInsertStatement as c 
    'sqlInsertStatement = <<%txt%
    'INSERT INTO cred_docs  (idclientd, doc_type, doc_who) VALUES (:idclientd, :doc_type, :doc_who)
    '%txt%
    '
    'dim flag as l 
    'flag = cn.Execute(sqlInsertStatement,args)
    'if flag = .f. then 
    '	ui_msg_box("Error","Record was not inserted. Error reported was: " + crlf(2) + cn.CallResult.text,UI_STOP_SYMBOL)
    'else
    '	if cn.AffectedRows() = 1 then 
    '		ui_msg_box("Notice","File Has Been  Uploaded..",UI_INFORMATION_SYMBOL)
    '	else
    '		ui_msg_box("Error","File Has Not Been Uploaded." ,UI_STOP_SYMBOL)
    '	end if 
    'end if 
    'cn.close()  
    'xbasic_wait_for_idle(1)
    'file.remove(fupath)
    'file.remove(fupath+".aes")
    'delete fname
    'delete ftsend
    'delete fupath
    'delete pth
    'delete fn
    'delete dr
    I'm testing as I go and when i get to the ftp upload i keep getting error here is a screen shot
    alphaftperror.png

    I have put alltrim every where and for some reason I'm missing it prob don't need the alltrim but I was trying anything at this point
    Last edited by steve745; 02-26-2018 at 09:52 PM. Reason: sec

  9. #9
    Member
    Real Name
    Steven Greer
    Join Date
    Jun 2008
    Location
    Manchester,PA
    Posts
    375

    Default Re: I need some formatting help

    i think i see it looking again the " at the end of aes gonna try to remove it

  10. #10
    Member
    Real Name
    Steven Greer
    Join Date
    Jun 2008
    Location
    Manchester,PA
    Posts
    375

    Default Re: I need some formatting help

    ok i got it after doing some reworking will post correction soon just gotta clear info

  11. #11
    Member
    Real Name
    Steven Greer
    Join Date
    Jun 2008
    Location
    Manchester,PA
    Posts
    375

    Default Re: I need some formatting help

    So here is the code for others if ever needed and it will be here for reference if I ever need the coding again.

    Code:
    'Date Created: 31-Mar-2016 09:59:28 AM
    'Last Updated: 21-Feb-2018 04:50:28 PM
    'Created By  : Steve
    'Updated By  : hubby
    'Prompt for text and store result in a variable called 'ftype'.
    'Get 'Value' property of 'Idclientd' in Form 'clientstart' .
    DIM window_name as C
    window_name = ":"+"credmaster"
    DIM varP_Object as p
    'Get a pointer to the specified window
    varP_Object = obj(window_name)
    'Check if the specified window exists
    if .not. is_object(varP_Object) then 
    	ui_msg_box("Error","The window '"+window_name+"' does not exist.",ui_stop_symbol)
    else
    	DIM SHARED clientid AS n
    	clientid = varP_Object:Idclientd.value
    end if
    dim prmpt_title as c 
    dim prmpt_prompt as c 
    dim prmpt_default as c 
    
    prmpt_title = "Description"
    prmpt_prompt = "File Description"
    prmpt_default = ""
    	
    DIM SHARED ftype AS C
    	
    ftype =alltrim(ui_get_text(prmpt_title,prmpt_prompt,prmpt_default))
    'Prompt for a filename and store result in a variable called 'fname'.
    'Prompt for a filename and store result in a variable called 'fname'.
    dim prmpt_title as c 
    dim prmpt_filter as c 
    dim prmpt_default as c 
    dim prmpt_flag as c 
    
    prmpt_title = a5_eval_expression("=\"Choose File\"",local_variables())
    prmpt_filter = "(*.*)"
    prmpt_default = ""
    
    DIM shared fname AS C
    
    fname =alltrim(ui_get_file( a5_eval_expression(prmpt_title,local_variables()),prmpt_filter,prmpt_default,"X"))
    dim dr as c
    dr=file.filename_parse(fname,"d")
    dim pth as c
    pth=file.filename_parse(fname,"p")
    dim fext as c
    fext=file.filename_parse(fname,"e")
    dim fn as c
    fn=file.filename_parse(fname,"ne")
    dim fupath as c
    fupath=chr(34)+dr+pth+fn+chr(34)
    dim encfu as c
    encfu=dr+pth+fn+".aes"
    'if at(" ",fn) > 0
    'file.rename(dr+pth+fn,strtran(dr+pth+fn," ","_"))
    'end if
    
    
    if ftype ="" 
    	ui_msg_box("error","You Didn't Choose a File Description",UI_STOP_SYMBOL)
    	end 
    	end if
    	if fname="" 
    		ui_msg_box("error","You Didn't Choose a File",UI_STOP_SYMBOL)
    		end 
    		end if
    sys_shell_wait(chr(34)+"c:\housing\aescrypt -e -p ************* "fupath)
    
    'dim extn as c
    'extn=Strtran(file.filename_parse(fname,"E"),".","")
    
    'xbasic_wait_for_idle(2)
    
    'dim st as c
    'dim en as c
    'st = "\\"
    '
    'en = " "
    dim upname as c
     upname=".aes"
    dim ftsend as c
    ftsend=ftype+fext+upname
    dim ftppath as c
    ftppath =alltrim("/srv/ftp/clientdocs/credit/"+clientid+chr(47)+ftype+fext+upname)
    	cmd = <<%a%
    connect|******
    onerror|error|Could not connect
    login|****|*****
    onerror|error|Could not log in
    mkdir|%a%"/srv/ftp/clientdocs/credit/" + clientid + crlf() + <<%a%
    onerror|quit
    quit 
    %a% 
    ftp_script_run_silent(cmd, .t.)
    				
    		xbasic_wait_for_idle(2)					
    				
    FTP_FILE_XFER("****","****","******",alltrim(encfu),alltrim(ftppath),"put",.F.,"File Uploading")
    'Insert a new record into a remote SQL database.
    'DIM a connection variable
    DIM cn as SQL::Connection
    dim flagResult as l 
    flagResult = cn.open("::Name::pat")
    if flagResult = .f. then 
    	ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text)
    	end 
    end if
    
    'Specify that we are using Portable SQL syntax
    cn.PortableSQLEnabled = .t.
    dim shared agent as c
    agent=user_name()
    'Dim a SQL arguments object, create arguments and set their values
    DIM args as sql::arguments
    
    
    if a5_eval_valid_expression("=clientid",local_variables()) then 
    	args.add("idclientd",convert_type(a5_eval_expression("=clientid",local_variables()),"N"))
    end If
    if a5_eval_valid_expression("=ftsend",local_variables()) then 
    	args.add("doc_type",convert_type(a5_eval_expression("=ftsend",local_variables()),"C"))
    end If
    if a5_eval_valid_expression("=agent",local_variables()) then 
    	args.add("doc_who",convert_type(a5_eval_expression("=agent",local_variables()),"C"))
    end If
    
    
    dim sqlInsertStatement as c 
    sqlInsertStatement = <<%txt%
    INSERT INTO cred_docs  (idclientd, doc_type, doc_who) VALUES (:idclientd, :doc_type, :doc_who)
    %txt%
    
    dim flag as l 
    flag = cn.Execute(sqlInsertStatement,args)
    if flag = .f. then 
    	ui_msg_box("Error","Record was not inserted. Error reported was: " + crlf(2) + cn.CallResult.text,UI_STOP_SYMBOL)
    else
    	if cn.AffectedRows() = 1 then 
    		ui_msg_box("Notice","File Has Been  Uploaded..",UI_INFORMATION_SYMBOL)
    	else
    		ui_msg_box("Error","File Has Not Been Uploaded." ,UI_STOP_SYMBOL)
    	end if 
    end if 
    cn.close()  
    xbasic_wait_for_idle(1)
    file.remove(dr+pth+fn)
    file.remove(dr+pth+fn+".aes")
    delete fname
    delete ftsend
    delete fupath
    delete pth
    delete fn
    delete dr
    it's not as neat as it could be and I'm sure there is another way or several other ways to do the same thing but this is what works for me.

Similar Threads

  1. Formatting now()
    By johnfletchertt in forum Mobile & Browser Applications
    Replies: 7
    Last Post: 07-24-2015, 01:21 PM
  2. How to dsp data in a grid that has Html formatting using the formatting in the dsp
    By rrwebster3 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 10-16-2012, 09:13 AM
  3. Javascript £ formatting
    By canc in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 09-27-2012, 03:21 PM
  4. Help with formatting
    By richard222 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 06-09-2011, 10:34 PM
  5. IE6 Formatting
    By Bill Chan in forum Application Server Version 10 - Web/Browser Applications
    Replies: 3
    Last Post: 03-31-2011, 12:01 PM

Bookmarks

Posting Permissions

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