This is a very strange problem I could not understand it, the code is very clear as you can see, I don't know if I am tired or could not see something... please tell me why I am getting False as a result, while it should be True, I have a list with one item and it is the exact one in the variable
thanks
property forbidenFolders : {"/Volumes/USERS/"}
set ff to "/Volumes/USERS/" as text
my isForbidenFolder(ff)
on isForbidenFolder(SelectedFolder)
repeat with i in forbidenFolders
log "forbiden folders: " & i
log "actual folder : " & SelectedFolder
if i = SelectedFolder then
log "this folder is forbiden"
return true
end if
end repeat
log "NOT forbiden"
return false
end isForbidenFolder
result here
That's the reference trap.
The syntax repeat with item in list iterates thru the list with references e.g. a reference to item 1 of list, a reference to item 2 of list etc. rather than the item itself.
To be able to check for equality you have to dereference the item using contents of
if contents of i = SelectedFolder then
When i is set to the item of a list in a repeat loop, you are getting a reference to the item. You need to coerce it into a string for your comparison.
if (i as string) = SelectedFolder
Related
I'm interested: is it possible to filter a list using boolean test specifier?
Like this for example:
set allList to every message of mailbox "Sent Messages" of iCloud account "iCloud"
-- gives an execution error:
set filtList2 to every item of allList whose subject contains "test"
while this line works as expected:
set filtList1 to every message of mailbox "Sent Messages" of iCloud account "iCloud" whose subject contains "test"
I understand, that I can filter the list using a loop:
set filtList3 to {}
repeat with aMessage in allList
if subject of aMessage contains "test" then
set end of filtList3 to aMessage
end if
end repeat
end tell
Why boolean test specifier gives me an error on a list?
Thank you!
OK, it turns out, that boolean test specifiers for lists are not implemented in AppleScript, so one should use loops instead.
I want to know the mails with a particular word in the subject that were sent in the last 5 days. Here is the code snippet.
For Each m In objInbox.items
If InStr(1,UCase(m.subject), "LEAVE;",vbTextCompare) <> 0 and m.SentOn >= now-5 then
msgbox "There is a mail sent on"&m.SentOn
End If
Next
I get an error saying that
Object doesn't support this property or method:m.SentOn
If I remove m.SentOn >= now-5 condition from IF, it works as expected.
You need to make sure the item is really a MailItem object. In VB Script, you can either use the TypeName function (check for "MailItem"), or you can use the Class property (all OOM objects expose it). For the MailItem object, it will be 43.
Not every item in a mailbox folder is necessarily a MailItem.
Try adding a check on the object type before you run the check, like this:
For Each m In objInbox.Items
If TypeName(m) = "MailItem" Then
If InStr(1,UCase(m.subject), "LEAVE;",vbTextCompare) <> 0 and m.SentOn >= now-3 Then
msgbox "There is a mail sent on" & m.SentOn
End If
End If
Next
edit: modified to vbscript specifically rather than outlook-vba
I need help with the component Persits's AspUpload. I need a simply method to get item text from form. I read the manual online http://www.aspupload.com/manual_simple.html but i think that the method presented is not good. In the manual the used method is:
<%
For Each Item in Upload.Form
Response.Write Item.Name & "= " & Item.Value & "<BR>"
Next
%>
I need to get the item.value from item. I already know the item.name. I try with this code, but it doesnt run
var1 = Upload.Form.Item.Name("var1").Item.Value
The error is:
Wrong number of arguments or invalid property assignment: 'Upload.Form.Item'
I've found a solution but i don't like it
For Each Item in Upload.Form
if Item.Name = "var1" then var1=Item.Value end if
Next
Do you have any more elegant solution? Thanks
Admittedly the documentation isn't the clearest but Upload.Form is a collection the documentation says;
To reference an individual form item of the collection you may use a 1-based integer index, or a string corresponding to the NAME attribute of a text item of your upload form.
So you can access it like most collections in Classic ASP
name = Upload.Form("var1").Name
value = Upload.Form("var1").Value
As long as var1 equates to the NAME attribute of the HTML form field element (INPUT, SELECT, TEXTAREA etc).
I have to modify a VB6 app and am repeatedly beating my head against a wall over control arrays.
I know that the event handler for the array includes its index value and I can set some variable there, but i should be able to directly access the selected radio button in an array of OptionButton. Currently I'm doing this
For i = 0 To optView.Count - 1
If optView.Item(i).value = True Then
currIndex = i
Exit For
End If
Next
Is this really my only option?
Yes, this is our only option. The control array object does not contain any selecting logic (which makes sense, as "selected" might mean different things for different controls). The only change I'd make is replacing the For with For Each.
Another way to do this that I have used. Write a function, and then call the function, passing in the control name, to return the index number. Then you can reuse this in the future especially, if you add it to a module (.bas).
Function f_GetOptionFromControlArray(opts As Object) As Integer
' From http://support.microsoft.com/KB/147673
' This function can be called like this:
' myVariable = f_GetOptionFromControlArray(optMyButtons) 'Control syntax OK
' myVariable = f_GetOptionFromControlArray(optMyButtons()) 'Array syntax OK
On Error GoTo GetOptionFail
Dim opt As OptionButton
For Each opt In opts
If opt.Value Then
f_GetOptionFromControlArray = opt.Index
Exit Function
End If
Next
GetOptionFail:
f_GetOptionFromControlArray = -1
End Function
I have the following AppleScript so far:
# List of possible options to control the development environment.
set WhatDoUWantToDoList to {"1", "2", "3", "4"}
set MySites to {"test1", "test2"}
# task selected
set selectedTask to {choose from list WhatDoUWantToDoList with prompt "Pick your task now!!!" without multiple selections allowed}
if selectedTask is equal to {"1"} then
display dialog selectedTask
else
# site selected
set selectedSite to {choose from list MySites with prompt "Pick the site your working on!!!"}
if (selectedTask is not equal to false and selectedSite is not equal to false) then
display dialog selectedTask
display dialog selectedSite
else
display dialog "you messed up!"
end if
end if
I am trying to say if option 1 is selected in list 1 display only the selected task, however, if any other option is selected in list 1 you have to move to the new code block, and must select an option in list 2, if you cancel on list 1 and list 2 you screwed up.
Any ideas on what I am missing here?
{ } in AppleScript creates a list, so when you set selectedTask, you're putting the results from choose from list into another list. When you try to compare the result to {"1"}, it's actually {{"1"}}, so it isn't equal.
Use parentheses ( ) for grouping instead.
using this code worked: if selectedTask contains "1" then
Choose from list will always return an array because multiple selection is possible. The basic idea is:
set selectedValues to (choose from list {"Value 1", "Value 2"} with prompt "Choose")
if (selectedValues is not false) then
set selectedValue to item 1 of selectedValues
display dialog ("You chose " & selectedValue as text)
else
display dialog ("You did not chose!")
end if