MS Project formula calculation returns inconsistent results - formula

In MS Project Professional I have a custom field that returns the correct value...sometimes, no value at other times, and an #ERROR at still other times with no apparent rhyme or reason.
The goal: I need to capture the [Resource Names] field for use in an external application - easy enough - but when I have a fixed units task with limited resource units I need to exclude the "[##%]" portion of the name. Example: Sam[25%] but I need just, "Sam"
The formula: IIf(IsNumeric(InStr(1,[Resource Names],"[")),LEFT([Resource Names],Len([Resource Names])-5),[Resource Names])
The results are in summary:
Marian == M
Sam == #ERROR
Sam[25%] == Sam
IDNR == #ERROR
Core Dev == Cor
Bindu == Bindu
Bindu[50%] == Bindu
Michele == Mi
Michele[25%] == Michele
Disha == empty
Disha[33%] == Disha
Stuart[50%] == Stuart
Stuart == S
Strangely enough, Summary Tasks show no value which is correct.
The need: can someone help me fix the formula? Or, should I just suck it up and manually delete the offending brackets and numbers?

If you only ever have one resource assigned to a task, this formula will work: IIf(0=InStr(1,[Resource Names],"["),[Resource Names],Left([Resource Names],InStr(1,[Resource Names],"[")-1)).
However, building a formula to handle more than one resource would be extremely tedious with the limited functions available. In that case a macro to update the field would work much better:
Sub GetResourceNames()
Dim t As Task
For Each t In ActiveProject.Tasks
Dim resList As String
resList = vbNullString
Dim a As Assignment
For Each a In t.Assignments
resList = resList & "," & a.Resource.Name
Next a
t.Text2 = Mid$(resList, 2)
Next t
End Sub

Related

Regex in if else statement in R

I have a rather simple question. I am trying to get the if else statement below to work.
It is supposed to assign '1' if the if statement is met, 0 otherwise.
My problem is that I cannot get the regex in the if statement to work ('\w*|\W*). It is supposed to specify the condition that the string either is "Registration Required" or Registration required followed by any character. I cannot specify the exact cases, because following the "Registration required" (in the cases where something follows), it will usually be a date (varying for each observation) and a few words.
Registration_cleaned <- c()
for (i in 1:length(Registration)) {
if (Registration[i] == ' Registration Required\\w*|\\W*') {
Meta_Registration_cleaned <- 1
} else {
Meta_Registration_cleaned <- 0
}
Registration_cleaned <- c(Registration_cleaned, Meta_Registration_cleaned)
}
You may use transform together with ifelse function to set the Meta_Registration_cleaned.
For matching the regular expression grep function can be used with pattern "Registration Required\w*".
Registration <- data.frame(reg = c("Registration Required", "Registration Required ddfdqf","some str", "Regixxstration Required ddfdqf"),stringsAsFactors = F)
transform(Registration,Meta_Registration_cleaned = ifelse(grepl("Registration Required\\w*",Registration[,"reg"]), 1, 0))
Gives result:
reg Meta_Registration_cleaned
1 Registration Required 1
2 Registration Required ddfdqf 1
3 some str 0
4 Regixxstration Required ddfdqf 0
I might have misunderstood the OP completely, because I have understood the question entirely differently than anyone else here.
My comment earlier suggested looking for the regex at the end of the string.
Registration <- data.frame(reg = c("Registration Required", "Registration Required ddfdqf","Registration Required 10/12/2000"),stringsAsFactors = F)
#thanks #user1653941 for drafting the sample vector
Registration$Meta_Registration_cleaned <- grepl('Registration required$', Registration$reg, ignore.case = TRUE)
Registration
1 Registration Required TRUE
2 Registration Required ddfdqf FALSE
3 Registration Required 10/12/2000 FALSE
I understand the OP as such that the condition is: Either the string "Registration required" without following characters, or... anything else. Looking forward to the OPs comment.

R error while using OR

In a dataframe poll, statement 1 works but statement 2 does not. Any advise as why this is happening ? Error which is coming wrong.
Statement 1:
test = subset(poll, Internet.Use=="1" | Smartphone == "1")
Statement 2 :
limited = subset(po11, Internet.Use=="1" | Smartphone == "1")
Error in subset(po11, Internet.Use == "1" | Smartphone == "1") :
object 'po11' not found
In your second statement you are writing po11 (with two digits "1" instead of two characters "l").
Therefore R can´t find this object, because it doesn´t exist.

String recognition in idl

I have the following strings:
F:\Sheyenne\ROI\SWIR32_subset\SWIR32_2005210_East_A.dat
F:\Sheyenne\ROI\SWIR32_subset\SWIR32_2005210_Froemke-Hoy.dat
and from each I want to extract the three variables, 1. SWIR32 2. the date and 3. the text following the date. I want to automate this process for about 200 files, so individually selecting the locations won't exactly work for me.
so I want:
variable1=SWIR32
variable2=2005210
variable3=East_A
variable4=SWIR32
variable5=2005210
variable6=Froemke-Hoy
I am going to be using these to add titles to graphs later on, but since the position of the text in each string varies I am unsure how to do this using strmid
I think you want to use a combination of STRPOS and STRSPLIT. Something like the following:
s = ['F:\Sheyenne\ROI\SWIR32_subset\SWIR32_2005210_East_A.dat', $
'F:\Sheyenne\ROI\SWIR32_subset\SWIR32_2005210_Froemke-Hoy.dat']
name = STRARR(s.length)
date = name
txt = name
foreach sub, s, i do begin
sub = STRMID(sub, 1+STRPOS(sub, '\', /REVERSE_SEARCH))
parts = STRSPLIT(sub, '_', /EXTRACT)
name[i] = parts[0]
date[i] = parts[1]
txt[i] = STRJOIN(parts[2:*], '_')
endforeach
You could also do this with a regular expression (using just STRSPLIT) but regular expressions tend to be complicated and error prone.
Hope this helps!

Classic ASP, IIS 8.5, CINT CLNG not working

Reinstalled my dev machine with win 8.1
Enabled ASP, installed my legacy websites that I have to maintain, installed sites as an application in IIS, enabled parent paths, send errors to browser on, full detail set on in error pages. All is working well, except when I work with numbers
I'm working in a system that captures financial data inputted by users, so often a number will be: 100.0 or
100.000 or
100 or
100,00
so I have a function that (I've used on loads of websites in the past) that will standardise the irregularities into a constant format, such as 100.00 (ie: proper decimal, always using a dot, etc)
This line now fails on win 8.1 IIS 8.5: If Cdbl(myString) = Cdbl(0) Then
Function ProperDecimal(s_String)
Dim CharPlace, DotChar, iLoop, strCurrentChar, myString
myString = TRIM(s_String)
If ISNULL(myString) OR myString = "" Then myString = 0
myString = REPLACE(myString,",",".")
'Find where the comma or dot is, ie: 100.00 is in position 3 (from the right)
CharPlace = 1
DotChar = 0
For iLoop = Len(Replace(myString, " ", "")) to 1 Step -1
strCurrentChar = mid(Replace(myString, " ", ""), iLoop, 1)
If strCurrentChar = "." OR strCurrentChar = "," Then
DotChar = CharPlace
Exit For
End If
CharPlace = CharPlace + 1
Next
'If string is zero, leave it at zero, we dont need 0.00
If Cdbl(myString) = Cdbl(0) Then
'ignore it, no decimal places needed
ProperDecimal = myString
Else
'Where is the DOT
Select Case DotChar
Case 0 'eg: 100 will be converted to 100.00
ProperDecimal = (myString & ".00")
Case 1 'eg: 100. will be converted to 100.00
ProperDecimal = (myString & "00")
Case 2 'eg: 100.0 will be converted to 100.00
ProperDecimal = (myString & "0")
Case 3 'eg: 100.00 will remain
ProperDecimal = (myString)
Case Else '(4, 5, 6, 7, 8, etc) 'eg: 100.001
ProperDecimal = ProperDecimal(Round(myString,2))
End Select
End If
End Function
Call ProperDecimal("112.05")
This lead me to try other methods other than CDbl
Response.write(isNumeric(s_String)) 'works, returns false because this is a string
Response.write(CINT(myString))
Response.write(CLNG(myString))
Response.write(CDBL(myString))
Returns this:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CINT'
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CLNG'
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CDBL'
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CINT'
If I then change the If statement to convert the 0 to a string, it works:
If myString = CSTR(0) Then
But I really dont want to be comparing strings to strings especially with numbers
This is now the second project this is happening on. The previous project I had to change the decimal comma to a fullstop (112,05 had to be 112.05) so I thought it had something to do with regional settings and the comma being listed as decimal character. But am getting different results now, its driving me up the wall.. plz assist if you can. Ta
CInt on the server works fine (2008 R2), on the clients pc (windows Xp and windows 7) but on my windows 8 machine, this is an issue.
I made my own two functions which I use now instead of CInt and CDbl. You can make more if needed. Pretty simple and tested,
EDIT:
Changed the function names toe shorter versions. Easier to replace and to use. Also does not clash with Javascripts parseInt if you do a search
Function pInt(Str)
Dim val : val = 0
'==Test Comma=='
On Error Resume Next
val = CInt(Replace(Str, ".", ","))
'==Test Period=='
On Error Resume Next
val = CInt(Replace(Str, ",", "."))
On Error Goto 0
pInt = val
End Function
Function pDbl(Str)
Dim val : val = 0
'==Test Comma=='
On Error Resume Next
val = CDbl(Replace(Str, ".", ","))
'==Test Period=='
On Error Resume Next
val = CDbl(Replace(Str, ",", "."))
On Error Goto 0
pDbl = val
End Function
I am not a pro in ClassicASP/VBScript but this works. I like my C# ASP.net

VBScript - Date and Time Constraints for Running a File

Ok I am new with writing VBScript and I want to write a string of code that plays a file (WAV format) only on a certain day and only between specific times. After piecing together multiple fragments of code I found on the internet I was left with the following:
Dim myDateString
Dim thing1
thing1 = 0
myDateString = Date()
If myDateString < "13/08/13" Then
thing1 = 1
end if
if thing1 = 1 then
If myDateString > "15/08/13" Then
thing1 = 2
end if
end if
if thing1 = 2 then
hournow = hour(Time())
If hour(Time()) >= 9 And Hour(Now()) < 22 Then
set WshShell = CreateObject("WScript.Shell")
music = "C:\Users\MYUSERNAME\Desktop\MYSOUND.wav"
WshShell.Run "wmplayer """ & music & """",0,True
Else
wscript.quit 1
End If
Else
wscript.quit 1
End If
Ok so I had set this for the date I ran this on, within the hour I was in. But
it didn't work. I expected the VBS to start playing MYSOUND.wav but it didn't. When running the file
there were no errors though, so I was wondering what I did wrong!
I running Windows 7
If anyone could tell me what I did wrong, and how to fix it that would be great.
Double points if anyone could post a corrected version of the code!
Thanks to any answers!
First, indent your code and give your variables meaningful names!
Then, your date comparison doesn't work because you're trying to compare strings as if they were dates. This usually won't work (depending on your "system locale"): you need to use date type variables and an actual date comparison function (DateDiff in VBScript).
(EDIT: as Ansgar Wiechers pointed out, you don't need to use DateDiff to compare dates in VBScript, "DateStart <= Now And Now <= DateEnd" will do just fine)
Try this:
Dim DateStart, DateEnd, WshShell, music
DateStart = DateSerial(2013, 8, 13)
DateEnd = DateSerial(2013, 8, 15)
If DateDiff("D", DateStart, Now) >= 0 And DateDiff("D", Now, DateEnd) >= 0 Then
If Hour(Now) >= 9 And Hour(Now) < 22 Then
'*** delete after debugging ***
MsgBox "play sound"
Set WshShell = CreateObject("WScript.Shell")
music = "C:\Users\MYUSERNAME\Desktop\MYSOUND.wav"
'*** 2nd parameter : 0 hides wmplayer, 1 shows it ***
WshShell.Run "wmplayer """ & music & """", 1, True
Else
'*** delete after debugging ***
MsgBox "Not the right time"
End If
Else
'*** delete after debugging ***
MsgBox "Not the right day"
End If
Also, if you want to debug a small script like this, you can call MsgBox to do a simple tracking of what's actually executed (in your example, replacing your "WScript.Quit 1" by MsgBox would show you that the date is not properly compared.

Resources