livecode and mergext dropbox sync - livecode

i am using mergext dropboxsync to synchronise my data from the ipad.
my question is.
how we get the file from the special folder specialfolderpath
and how we check if the file exist into the dropbox.
i am no using fields for folder or the files i want the procedure to be hidden from the user
to get my folder and path i use the simple bellow code.
put specialfolderpath("documents") & "/myfile.sqlite" into myPath
and here is the code from the button i use
on mouseUp
goToParent --<command
repeat for each line tempitem in fld "sFolders" --<hide field
add 1 to t
if tempitem ="hairaid-backup" then
put 1 into fExist
end if
end repeat
--!! if folder exist
if fExist is a number then
else
try
mergDropboxCreateFolder (hairaid &"-"&backup)
catch e
answer e
end try
end if
end mouseUp

I would not really recommend synchronising a sqlite database over dropbox. You are likely to have better results creating a tree for files for dropbox to sync as one large file is likely to end up with conflicted versions.
However, answering your question in the general sense you would need to do something like this:
put url ("binfile:"&myPath) into myData
mergDropboxWriteFile relativePath,myData
Then to get the data you:
put merDropboxGetFile(relativePath) into myData

Related

How to detect if user clicks on File >> Print as option or presses CTRL+P from within MS word or Excel using VBA code?

I want to detect when user clicks File >> Print or CTRL+P inside ms word or excel and use this detection to run a batch file using vba code, is this possible?
This code should self start along with the program.
I tried to find similar code but was unable to find anything useful to my need.
Any help would greatly appreciated.
Thanks
The way your question is written seems ambiguous to me. At first read, it seems like you are trying to distinguish between these two methods of telling a file to print. I know of no way to do this in vba.
However, you can intercept the print event or command.
Another possible meaning is that you want your procedure to run whenever the user attempts to print. See Intercepting Events Like Save or Print by Word MVPs Dave Rado and Jonathon West. See also Application.WorkbookBeforePrint Event.
Note, this does not block screenshots or saving to another file. Do you mind sharing why you are trying to do this? What you hope to accomplish?
You can use the DocumentBeforePrint and WorkbookBeforePrint Events. Below quoted from linked pages on Intercepting Events and WorkBookBeforePrint documentation.
A DocumentBeforePrint event procedure looks like this:
Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, _
Cancel As Boolean)
'Your code here
End Sub
If you want to prevent printing from occurring in certain
circumstances, you can set the Cancel variable to True, e.g.:
Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, _
Cancel As Boolean)
Dim Result As Long
Result = MsgBox("Have you checked the " & "printer for letterhead paper?", vbYesNo)
If Result = vbNo Then Cancel = True
End Sub
From Excel documentation
This example recalculates all worksheets in the workbook before
printing anything.
Private Sub App_WorkbookBeforePrint(ByVal Wb As Workbook, _
Cancel As Boolean)
For Each wk in Wb.Worksheets
wk.Calculate
Next
End Sub
End Quoted Material
Intercepting the Command instead of the Event
Another, less effective, method is to Intercept the actual commands. You could name your procedure PrintPreviewAndPrint and have another called FilePrintQuick that calls your procedure PrintPreviewAndPrint. Earlier versions use FilePrint and FilePrintDefault. Thank #Timothy Rylatt for the command names. He adds: Note that neither of these will intercept the backstage command accessed via File | Print. For that you need to use an event.
Sub PrintPreviewAndPrint()
' Your code here
End Sub
Sub FileQuick()
FilePreviewAndPrint
End Sub
In Word, these would go in your template or in a Global Template.
In Word, you make a template a Global Template by placing it in your Word Startup Folder.
Dealing with making this Global in Excel
My understanding of how Excel handles global macros is far poorer than that for Word. To assist with this, I asked my own question in the Microsoft Answers Excel Programming forum. Here is a link to that question and the answers I received. Andreas Klinger, who is engaged in that thread, is an experienced and knowledgeable Excel programmer, which I am not.

How can I have an Excel VBA application in use without multiuser lock?

I have an app I coded in Excel that suits the needs of my project; it serves the purpose of keeping track of quite a lengthy process and prerequisites and such.
It feeds off of a certain number of tables in my file.
The thing is, only one user can currently work on that file; and since we have multiple teams working on different parts in parallel, it would be nice to host that somehow in a way that would remove the single-user restriction.
Do any of you have an idea of how I could work around this?
I worked on a solution for a very similar project of keeping track of a hospital's labor utilization (nursing employee census, if you will) on a day-to-day basis across every nursing-based department in the hospital system. This solution relies on a couple conditions:
That it will be unlikely two or more people will need to save data to the final file at the same time (meaning within seconds of each other).
All the various users of the file will have access to at least one commonly-shared network drive or location.
In our case, we created a new file each day, but it wouldn't be difficult to adjust the data-writing code to append data, rather than create a new file and dump data into that new file.
The rough outline of the process is this:
Create a read-only destination file (.xlsx in our case) in a network location that contains tables of data split between n worksheets.
Create an interactive form (.xlsm) that allows user input and then on form submission, opens the destination .xlsx file and saves the form data to it, then closes it. This interactive .xlsm file can be placed in the same network location, with shortcuts created on as many peoples' desktops (or departmental shares, for example) as necessary.
With the speed of Excel and VBA, this means you're only "opening" the destination file for a second or two to write the form data, no matter how long one user may have a copy of the form open.
One thing that will be necessary is to check if the file is open, and gracefully alert the user if they need to try again, which you can do with a function covering the related error codes, for example:
Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iError As Long
On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iError = Err
On Error GoTo 0
Select Case iError
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case 53: IsFileOpen = "Not Found"
Case Else: Error iError
End Select
End Function
which can be called via some code like (pseudo code):
Private Sub UpdateData(ByVal thesheet As String)
Dim xlApp As New Excel.Application
Dim xlWkbk As New Excel.Workbook
If Not IsFileOpen(FileName) Then
Set xlWkbk = xlApp.Workbooks.Open(filename)
xlWkbk.Worksheets(theSheet).Activate
Else
MsgBox "Sorry, the file is currently in use. Please try again", vbOKOnly
Exit Sub
End If
End Sub
Or you could have it simply wait a few seconds (e.g. Wait 5) or more if the writing process doesn't cover that much data. The specific amount of seconds to wait would depend on testing write times based on your scenario and your data. That would be added as a nested If Not statement inside the previous one.
Then, when the result is that the file is not in use, simply write a series of subroutines to write the form data (stored as variables) to the destination sheet. End with something like
xlWkbk.Save
xlWkbk.Close
Set xlWkbk = Nothing
Set xlApp = Nothing
to save and close the workbook and clear your variables (memory cleanup and all that).
You may already be aware of this practice, but while you'll want to keep Excel visible during development, you'll definitely want to set Application.Visible = False on the production files for two reasons:
This will prevent users from getting confused by a lot of automation
It covers Application.Updating as well, which will really speed up data processing.

Test to see if a file already exists

I have an iOS game, I am trying to save settings (which are generally stored within an array) to file.
currently,I have the file opened and read in the openStack handler; I have the file written in the shutdown handler...
but, in the openStack handler, how do I test to see if the file has actually been created... and if it doesn't exist I want to create one and write in some default settings
What's the best way to do this?
Usually, I just open and read the file. Next, I put the contents into variables. If the contents happens to be empty, then I use a default value. This makes it unnecessary to check that the file exists and, more importantly, is more compatible with future versions of your software.
on readPrefs
put specialFolderpath("documents") & "/prefs.dat" into myPath
put url ("binfile:" & myPath) into myPrefs
// here, the result may contain "can't open file"
put line 1 of myPrefs into gHighscore
if gHighScore is empty then put 0 into gHighscore
put line 2 of myPrefs into gLicenseKey
if gLicenseKey is empty then put "unregistered" into gLicenseKey
end readPrefs
You could also check for the file and use a slightly different script:
on readPrefs
put specialFolderpath("documents") & "/prefs.dat" into myPath
if there is a file myPath then
put url ("binfile:" & myPath) into myPrefs
put line 1 of myPrefs into gHighscore
put line 2 of myPrefs into gLicenseKey
end if
if gHighScore is empty then put 0 into gHighscore
if gLicenseKey is empty then put "unregistered" into gLicenseKey
end readPrefs
More variations are possible, e.g. you could check the result and set default values if the file can't be opened.
You can check if the file already exists and if it does not exist you can put the default values into the file, which will then be created.
See below
if there is not a file "mysettings.dat"
then put myDefaultsettings into URL "binfile:mysettings.dat"

Lotusscript search windows directory for subdirectories and files. Recursion?

I'm trying to write a LS agent to scan a directory in windows eg:'C:\' for any files and sub-directories. For each sub-directory, it will go inside and search for more files and sub-directories and continues until there's no more to look for. I'm used to write recursive code to replace or remove characters in a long string but for this one I'm totally lost. Below is my code (it's a mix of code from the domino help file and one I found in IBM site):
Sub Initialize
Dim pathname As String, filename As String
pathname = "C:\*.*"
filename = Dir(pathname, 16)
Print "Begin scan"
Do While filename<>""
If IsDir(pathname+filename)=True Then
Print pathname+filename+" is a directory"
'look for more directories and files in here
Else
Print filename+" is a file"
End If
filename=Dir()
Loop
Print "Finish scan"
End Sub
Function IsDir(Path As String) As Integer
Dim Void&
Dim Result As Boolean
On Error GoTo ErrorHandler
Void=FileLen(Path)
Result=False
GoTo Over
ErrorHandler:
Result=True
Resume Over
Over:
IsDir=Result
End Function
What do I need to change to make the code recursive at the commented part? ('look for more directories and files in here). I'm not just trying to find a specific file or directory. I want all that's available withing one. If I'm able to do that, then I can retrieve them and save into a NotesDocument.
I've used this solution a couple of times and it works a treat:
First of all, you don't want to call Initialize recursively. You need a function that you're passing a pathname into.
Secondly, because of the stateful way that the DIR function works, I think you have to do this with two loops. In the first loop, you process your regular files and you put the folder names ino a list. Then in the second loop, you go through the list of folders and call the recursive function passing in the path to each one.

Why Does Last Line of VB6 Text File Being Read/Written to Another File Print Only Partially?

I am creating several text folders programmatically using VB6, and then concatenating them all together into a single file.
I write text to the files using
Print #lngFileHandle, Text
so there should be a CR/LF even after the very last line of text in each file.
Then I append all these "subfiles" together into another text file that was opened this way:
Open strFileName For Append As #lngFileHandle
Strangely, my final resulting file looks good EXCEPT that the very last line of the last file being appended is only partially there.
The last few lines look like this in the file I'm reading FROM:
`<Name>` Referral for Service Home Delivered Meals`</Name>`
`<Name>` Referral for Service Adult Day Care/Health`</Name>`
`<Name>` Referral for Service Congregate Meals`</Name>`
but after being read in from that file and output to the final file, they look like this:
`<Name>` Referral for Service Home Delivered Meals`</Name>`
`<Name>` Referral for Service Adult Day Care/Health`</Name>`
`<Name>` Referral for Service Congr
The code I'm using to read in this particular "subfile" and output it to the final file is:
With mobjNewEntriesLog
Do While Not .IsEOF
strOutput = .ReadLine
mobjMainLog.PrintLine strOutput
Loop
End With
The .IsEOF function is as follows:
Public Function IsEOF() As Boolean
If blnOpened Then
IsEOF = EOF(lngFileHandle)
Else
IsEOF = True
End If
End Function
It would make more sense to me if I wasn't getting the last line at ALL, but getting just PART of it?--I don't get that.
Anybody see anything that would make the last line only print partially to the final file?
TIA.
Ensure you are closing your file as this may be required to flush out any data that is pending to be written.
VB6 file numbers are not file handles, so don't call them that. They are indexes into a file descriptor table in the runtime where the actual handle, mode, buffer length, buffer, ponters, etc. are stored.
The Close statement is not synchronous, but a "lazy close" that may not have flushed all data and updated the EOF pointer of the file by the time you turn around and try to read it again. This behavior is intentional as far as I can determine, perhaps for performance reasons.
A Reset statement can be used to force all open files closed, and it is synchronous. This isn't always practical, however it may be fine in your case. Easy enough to try: add a Reset before you re-open any of your files to concatenate them.

Resources