Delete recipe in rsview file using command button??

Briana,
I assume that you are trying to delete the ASCII tecxt file that contains a RSView Recipe.

It is possible to write a Visual Basic program, or a Macro (list of Commands stored as a text file), that is called by a command button, that will delete a Recipe file. It would also be possible to change the values in a Recipe file, say to all blanks, or 0's, so that the file frame and title is still in place.
 
I have completely ditched the RSView Recipe (quite frankly it sucks) and written my own. I make WIN API calls to open a standard Windows File browser like you see in other applications for file operations. I include references (Menu->Tools->References) for Microsoft forms, Microsoft Office Object library, Common language Runtime Execution engine, and Common Language Runtime Library. You can then navigate to wherever your want, cut, copy, paste, rename and delete files.

Here is the VBA code to open a windows file browser. Place the code in a module called FileBrowser. My recipes are written in a format that allows me to open and edit them offline in Excel as well as being able to be loaded into the PLC and edited from within RSView. Unfortunately, I can't post that part of the code because it would divulge proprietary recipe structure. In the Rockwell KB however there is an old technote about how to parse an RCP file to load a recipe to tags from VB. If you do want to make your own recipe app, I suggest you start there. Hopefully you will find this helpful.


'*******************************************************
'Calls win API procedures to open a common dialog box
'to get the name of a file to 'open or save to.
'*******************************************************
'type definition the data structure for open/save file dialogs
Type tagOPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
strFilter As String
strCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
strFile As String
nMaxFile As Long
strFileTitle As String
nMaxFileTitle As Long
strInitialDir As String
strTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
'declare the functions in the common dialog dll
Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean
Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Global Const ahtOFN_READONLY = &H1
Global Const ahtOFN_OVERWRITEPROMPT = &H2
Global Const ahtOFN_HIDEREADONLY = &H4
Global Const ahtOFN_NOCHANGEDIR = &H8
Global Const ahtOFN_SHOWHELP = &H10
Global Const ahtOFN_ENABLEHOOK = &H20
Global Const ahtOFN_ENABLETEMPLATE = &H40
Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80
Global Const ahtOFN_NOVALIDATE = &H100
Global Const ahtOFN_ALLOWMULTISELECT = &H200
Global Const ahtOFN_EXTENSIONDIFFERENT = &H400
Global Const ahtOFN_PATHMUSTEXIST = &H800
Global Const ahtOFN_FILEMUSTEXIST = &H1000
Global Const ahtOFN_CREATEPROMPT = &H2000
Global Const ahtOFN_SHAREAWARE = &H4000
Global Const ahtOFN_NOREADONLYRETURN = &H8000
Global Const ahtOFN_NOTESTFILECREATE = &H10000
Global Const ahtOFN_NONETWORKBUTTON = &H20000
Global Const ahtOFN_NOLONGNAMES = &H40000
Global Const ahtOFN_EXPLORER = &H80000
Global Const ahtOFN_NODEREFERENCELINKS = &H100000
Global Const ahtOFN_LONGNAMES = &H200000
Private Const conDefaultDir = "C:\1400 Ton M3 Press\RCP" 'Was "My Documents"
Private Const conOpenDialogTitle = "Open MegaDiamond Press Recipe File"
Private Const conSaveDialogTitle = "Save MegaDiamond Press Recipe File"
Function testit()

MsgBox "You selected: " & GetOpenRecipeFileName
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function
Function GetOpenRecipeFileName() As Variant ' Returns the file name of a recipe to open or null if canceled.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Sef flags that the chosen file must already exist, don't change directories when you're done, dont display the read-only box.
lngFlags = ahtOFN_FILEMUSTEXIST Or ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR

'initialize the filter string for Megadiamond cubic pres files and all files
strFilter = ""
strFilter = ahtAddFilterItem(strFilter, "MegaDiamond Cubic Press Files (*.mpf)", "*.MPF")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

' Now actually call to get the file name.
varFileName = ahtCommonFileOpenSave(OpenFile:=True, InitialDir:=conDefaultDir, Filter:=strFilter, Flags:=lngFlags, DialogTitle:=conOpenDialogTitle)
If Not IsNull(varFileName) Then
varFileName = TrimNull(varFileName)
End If
GetOpenRecipeFileName = varFileName
End Function
Function GetSaveRecipeFileName() As Variant ' Returns the file name of a recipe to open or null if canceled.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Sef flags that the chosen file must already exist, don't change directories when you're done, dont display the read-only box.
lngFlags = ahtOFN_FILEMUSTEXIST Or ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR

'initialize the filter string for Megadiamond cubic pres files and all files
strFilter = ""
strFilter = ahtAddFilterItem(strFilter, "MegaDiamond Cubic Press Files (*.mpf)", "*.MPF")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

' Now actually call to get the file name.
varFileName = ahtCommonFileOpenSave(OpenFile:=False, InitialDir:=conDefaultDir, Filter:=strFilter, Flags:=lngFlags, DialogTitle:=conSaveDialogTitle)
If Not IsNull(varFileName) Then
varFileName = TrimNull(varFileName)
End If
GetSaveRecipeFileName = varFileName
End Function
Function ahtCommonFileOpenSave( _
Optional ByRef Flags As Variant, _
Optional ByVal InitialDir As Variant, _
Optional ByVal Filter As Variant, _
Optional ByVal FilterIndex As Variant, _
Optional ByVal DefaultExt As Variant, _
Optional ByVal FileName As Variant, _
Optional ByVal DialogTitle As Variant, _
Optional ByVal hwnd As Variant, _
Optional ByVal OpenFile As Variant) As Variant
'All parameters are optional.
' In:
' Flags: one or more of the ahtOFN_* constants, OR'd together.
' InitialDir: the directory in which to first look
' Filter: a set of file filters, set up by calling
' AddFilterItem. See examples.
' FilterIndex: 1-based integer indicating which filter
' set to use, by default (1 if unspecified)
' DefaultExt: Extension to use if the user doesn't enter one.
' Only useful on file saves.
' FileName: Default value for the file name text box.
' DialogTitle: Title for the dialog.
' hWnd: parent window handle
' OpenFile: Boolean(True=Open File/False=Save As)
' Out:
' Return Value: Either Null or the selected filename
Dim OFN As tagOPENFILENAME
Dim strFileName As String
Dim strFileTitle As String
Dim fResult As Boolean
' Give the dialog a caption title.
If IsMissing(InitialDir) Then InitialDir = CurDir
If IsMissing(Filter) Then Filter = ""
If IsMissing(FilterIndex) Then FilterIndex = 1
If IsMissing(Flags) Then Flags = 0&
If IsMissing(DefaultExt) Then DefaultExt = ""
If IsMissing(FileName) Then FileName = ""
If IsMissing(DialogTitle) Then DialogTitle = ""
If IsMissing(hwnd) Then hwnd = Application.WindowHandle
If IsMissing(OpenFile) Then OpenFile = True
' Allocate string space for the returned strings.
strFileName = Left(FileName & String(256, 0), 256)
strFileTitle = String(256, 0)
' Set up the data structure before you call the function
With OFN
.lStructSize = Len(OFN)
.hwndOwner = hwnd
.strFilter = Filter
.nFilterIndex = FilterIndex
.strFile = strFileName
.nMaxFile = Len(strFileName)
.strFileTitle = strFileTitle
.nMaxFileTitle = Len(strFileTitle)
.strTitle = DialogTitle
.Flags = Flags
.strDefExt = DefaultExt
.strInitialDir = InitialDir
' Didn't think most people would want to deal with
' these options.
.hInstance = 0
'.strCustomFilter = ""
'.nMaxCustFilter = 0
.lpfnHook = 0
'New for NT 4.0
.strCustomFilter = String(255, 0)
.nMaxCustFilter = 255
End With
' This will pass the desired data structure to the
' Windows API, which will in turn it uses to display
' the Open/Save As Dialog.
If OpenFile Then
fResult = aht_apiGetOpenFileName(OFN)
Else
fResult = aht_apiGetSaveFileName(OFN)
End If
' The function call filled in the strFileTitle member
' of the structure. You'll have to write special code
' to retrieve that if you're interested.
If fResult Then
' You might care to check the Flags member of the
' structure to get information about the chosen file.
' In this example, if you bothered to pass in a
' value for Flags, we'll fill it in with the outgoing
' Flags value.
If Not IsMissing(Flags) Then Flags = OFN.Flags
ahtCommonFileOpenSave = TrimNull(OFN.strFile)
Else
ahtCommonFileOpenSave = vbNullString
End If
End Function
Function ahtAddFilterItem(strFilter As String, strDescription As String, Optional varItem As Variant) As String
'Build the file filter string, appends to the existing filter string as filter items are added. String should be emptied before calling the first time
If IsMissing(varItem) Then varItem = "*.*"
ahtAddFilterItem = strFilter & strDescription & vbNullChar & varItem & vbNullChar
End Function
Private Function TrimNull(ByVal strItem As String) As String 'Trim the null characters of a string.
Dim intPos As Integer
intPos = InStr(strItem, vbNullChar)
If intPos > 0 Then
TrimNull = Left(strItem, intPos - 1)
Else
TrimNull = strItem
End If
End Function
 
Last edited:

Similar Topics

Dear All!!! Please tell me the way how can i delete recipe from Runtime. There are only save and restore options in the inbuild recipe function...
Replies
3
Views
2,791
Hello, someone have experience about how to delete an alarm message(alarm already solved) from alarm viewer with something coming from PLC? THANKS
Replies
3
Views
829
Hello, someone have experience about how to delete an alarm message(alarm already solved) from alarm viewer with something coming from PLC? THANKS
Replies
0
Views
373
In my project, I've set up a few user accounts (Operator, Technician, Admin). The person assigned as Admin has said "I want to be able to...
Replies
8
Views
1,119
In the Communications > Network > Protocol 1 - AB Tag Names > PLC10 configuration page there is a Tag Names section (not the same as the separate...
Replies
4
Views
2,478
Back
Top Bottom