Return to SaveAs Dialog Box powerbuilder - dialog

I want to export a datawindow informations to a .txt file. When I click the export button the SaveAs Dialog Box opens. If a .txt document with the same name exists then a MessageBox pop-up questioning if I want to replace the file. If I press NO then SaveAs Dialog Box is closing. How can I prevent SaveAs Dialog Box from closing? I want to return in it and give another name to file.
Here is my code:
li_rc = GetFileSaveName (lcs_title, ls_path_filename, ls_filename, 'txt', 'TXT File (*.txt), *.txt' )
if li_rc > 0 then
if FileExists (ls_path_filename) then
//Existing file has been found
if MessageBox (lcs_title, 'Replace the file '+ ls_path_filename +'?', Question!, YesNo!, 1) = 2 then
//Do not replace the file
//Return to dialog?
else
//Replace the file
dw_1.SaveAs(ls_path_filename, Text!, false)
end if
end if
end if
Thanks!

Try this
boolean lb_need_file = true
do while lb_need_file
li_rc = GetFileSaveName (lcs_title, ls_path_filename, ls_filename, 'txt', 'TXT File (*.txt), *.txt' )
if li_rc > 0 then
if FileExists (ls_path_filename) then
//Existing file has been found
if MessageBox (lcs_title, 'Replace the file '+ ls_path_filename +'?', Question!, YesNo!, 1) = 2 then
//Do not replace the file
//Return to dialog?
else
lb_need_file = false
//Replace the file
dw_1.SaveAs(ls_path_filename, Text!, false)
end if
end if
end if
loop
Please let us know if this works for you

Related

Lotus Notes external doc files search text

By using the follow code i can find a strin in eny external file ( .txt ).
Function "funcCheckIfStrinInFileExist" use Instr function to find position of the string
and return 0 if an integer if string exist in myRecord (see bellow ).
Is there any way to search a .doc file (or .docx) , because (or .PDF !!!) if file is word document return error.
Thanks in advance.
Do While fileName$ <> ""
varCheckIfStrinInFileExist = funcCheckIfStrinInFileExist( fileName, myString )
If varCheckIfStrinInFileExist Then
Messagebox "i found the text in file : " + fileName
End If
fileName$ = Dir$()
Loop
'************************************************************************
funcCheckIfStrinInFileExist ( fileName, myString ) as integer
.......................................
Do Until Eof(filenum%)
'Read a line of data
Input #filenum%, myRecord
positionOfChar = Instr(myRecord$, varString)
If Cint(positionOfChar) > 0 Then
funcCheckIfStrinInFileExist = True
Close filenum
Exit Function
End If
Loop

How to get file name text from attachment in PR in SAP

I want to get the file name from an attachment inside a Purchase Requisition in SAP using VBA.
I have tried already changing the last line for some random numbers bu nothing happened and I can't manage to discover where I can get the file name.
session.findByid("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").pressToolbarButton "&MEREQDMS"
'here my code tells me if there are any attachment in purchase requisition item
doc = session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1,0]").Text
'starts on item line (0)
n = 0
Do While doc <> ""
session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1," & n & "]").SetFocus
session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1," & n & "]").caretPosition = 5
'opens the attachment page with the documents inside for download
session.findByid("wnd[1]").sendVKey 2
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Application.AutomationSecurity = msoAutomationSecurityByUI
q = 1
s = 0
'num_files returns me "PDF" or "XLS".
num_files = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getnodetextbypath(q)
...
Here is the file with file name I need VBA tells me ("Escopo Plataforma..."):
Please try the following.
for example:
...
'num_files returns me "PDF" or "XLS".
num_files = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getnodetextbypath(q)
myFileName = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getitemtext(CStr(q),"C 7")
I assume Item Name "C 7" will be different for you. This is how you determine the correct ItemName:
Record a script with the SAP GUI script recorder.
Click with the mouse in the column with the file name.
Leave the cursor there and finish the recording.
Look in the recorded script for the ItemName.
Regards, ScriptMan

Opening a dynamically created Excel workbook

I have a Windows Forms app with an Excel file I created using SpreadsheetGear. My application uses SaveFileDialog() to prompt the user to save the file to their computer using the following code:
'Bring up the save dialog to save the newly created Excel file
Using saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.FileName = "ExportFile.xlsx"
If DialogResult.OK <> saveFileDialog1.ShowDialog() Then
Return
End If
Try
e.Result.SaveAs(saveFileDialog1.FileName, FileFormat.OpenXMLWorkbook)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Save Error", MessageBoxButtons.OK)
End Try
End Using
That code works fine but the user doesn't want to worry about saving the file. He just wants it to open right away so he can copy/paste the information he needs and then discard the file without having to navigate to his save destination. I can't seem to get SaveFileDialog() to do that for me.
Is there a better way to do this?
This closed question helped me discover my answer. Process.Start with the filename from the SaveFileDialog works.
Updated Code:
'Bring up the save dialog to save the newly created Excel file
Using saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.FileName = "ExportFile.xlsx"
If DialogResult.OK <> saveFileDialog1.ShowDialog() Then
Return
End If
Try
e.Result.SaveAs(saveFileDialog1.FileName, FileFormat.OpenXMLWorkbook)
If File.Exists(saveFileDialog1.FileName) Then
Process.Start(saveFileDialog1.FileName) 'Open the newly created Excel file
Else
Throw New Exception("Could not find file to open. Please try again.")
End If
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Save Error", MessageBoxButtons.OK)
End Try
End Using

How do I open a File Dialog box in IDEAScript?

I would like to have the user select a file to import into my IDEA project as a part of an IDEAScript macro. How can I create the File Dialog box and get the file the user selects?
The following code will open a File Dialog window and return the file path for the file the user chooses.
Function GetFileName()
Dim ShellApp, Ret, s, i
Set ShellApp = CreateObject("Shell.Application")
Set Ret = ShellApp.BrowseForFolder(0, "Choose a file.", 16384)
MsgBox Ret.ParentFolder.ParseName(Ret.Title).Path
End Function

Search for filename using variable in Excel VBA

I have code that is supposed to search for a filename within a folder on a server and if that file exists the user is prompted to either overwrite the file or not. However, the code always prompts the user regardless of the file existing or not.
I found a few examples off of this site, however they use static file names. I am attempting to modify it to fit my needs, but not getting anywhere.
The code for finding if the file exists is as follows
'checks if file you're saving already exists
If FileThere("\\showdog\service\Service_job_PO\" & UserInput) = True Then
'do stuff here
the function for that code is this:
Function FileThere(filename As String) As Boolean
If FileThere = (Dir("\\showdog\service\Service_job_PO\" & UserInput) <> "") Then
FileThere = True
Else
FileThere = False
End If
End Function
I believe this should be the below. You want to check if the directory associated with the passed parameter filename exists.
Function FileThere(filename As String) As Boolean
If Dir(filename) <> "" Then
FileThere = True
Else
FileThere = False
End If
End Function
Edit:
I'm assuming you feed the full file path in this line, in which case you reference the file path that is sent over to the function FileThere.
If FileThere("\\showdog\service\Service_job_PO\" & UserInput) = True Then
You can cut this all down to a single test rather than double-up with a UDF:
If Len(Dir("\\showdog\service\Service_job_PO\" & UserInput)) > 0 Then
As per other comments above your initial code was using UserInput twice

Resources