Assigning Value to StringValue In F# - f#

I am working though this example of the Open XML SDK using F#
When I get to this line of code
sheet.Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart)
I am getting a null ref exception when I implement it like this:
sheet.Id.Value <- document.WorkbookPart.GetIdOfPart(worksheetPart)
Is there another way to assign that value? System.Reflection?

I got it working like this:
let sheet = new Sheet
(
Id = new StringValue(spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart)),
SheetId = UInt32Value.FromUInt32(1u),
Name = new StringValue("mySheet")
)
If You want to take a look to the entire sample translated to F#, it's here.

To clarify what's going on, the problem is that sheet.Id is initially null. If we look at the following:
sheet.Id.Value <- document.WorkbookPart.GetIdOfPart(worksheetPart)
The code tries to access the sheet.Id and invoke its Value property setter, but the Id itself is null. The answer posted by Grzegorz sets the value of the whole Id property - it's done in a construtor syntax, but it's equivalent to writing the following:
sheet.Id <- new StringValue(spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart))
This sets the whole Id property to a new StringValue instance.

Related

How do you get strip RTF formatting and get actual string value using DXL in DOORS?

I am trying to get the values in "ID" column of DOORS and I am currently doing this
string ostr=richtext_identifier(o)
When I try to print ostr, in some modules I get just the ID(which is what I want). But in other modules I will get values like "{\rtf1\ansi\ansicpg1256\deff0\nouicompat{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\froman\fcharset0 Times New Roman;}} {*\generator Riched20 10.0.17134}\viewkind4\uc1 \pard\f0\fs20\lang1033 SS_\f1\fs24 100\par } " This is the RTF value and I am wondering what the best way is to strip this formatting and get just the value.
Perhaps there is another way to go about this that I am not thinking of as well. Any help would be appreciated.
So the ID column of DOORS is actually a composite- DOORS builds it out of the Module level attribute 'Prefix' and the Object level attribute 'Absolute Number'.
If you wish to grab this value in the future, I would do the following (using your variables)
string ostr = ( module ( o ) )."Prefix" o."Absolute Number" ""
This is opposed to the following, which (despite seeming to be a valid attribute in the insert column dialog) WILL NOT WORK.
string ostr = o."Object Identifier" ""
Hope this helps!
Comment response: You should not need the module name for the code to work. I tested the following successfully on DOORS 9.6.1.10:
Object o = current
string ostr = ( module ( o ) )."Prefix" o."Absolute Number" ""
print ostr
Another solution is to use the identifier function, which takes an Object as input parameter, and returns the identifier as a plain (not RTF) string:
Declaration
string identifier(Object o)
Operation
Returns the identifier, which is a combination of absolute number and module prefix, of object o as a string.
The optimal solution somewhat depends on your underlying requirement for retrieving the object ID.

xamarin android Intent.getstringextra multiple variables

i created 4 variables namely, "id", "name", "address", "age"
why does the value duplicates whenever i try intent.putextra
Context context = view.Context;
Intent intent = new Intent(context, typeof(activity4));
intent.PutExtra(activity4.id, joblist[position].id);
intent.PutExtra(activity4.name, joblist[position].name);
intent.PutExtra(activity4.address, joblist[position].address);
intent.PutExtra(activity4.age, joblist[position].age);
now the problem is when I do this.
string userId= Intent.GetStringExtra(id);
string userName= Intent.GetStringExtra(name);
string userAddress= Intent.GetStringExtra(address);
string userAge= Intent.GetStringExtra(age);
when I put those strings in a textview, all four textviews would show the value for "age". as if all the data that was passed is only age. can anyone answer this? the output is like this
id= 12
name= 12
address= 12
age= 12
Intent.Extras don't work like that when you use the typeOf() keyword
typeOf is a C# keyword that is used when you have the name of the class. It is calculated at compile time and thus cannot be used on an instance, which is created at runtime. GetType is a method of the object class that can be used on an instance
Since it does not initialize like that your variables that you are assigning here are currently all null so the intent carries all the data in correspondence to null, Since the first value you enter with null is id you always get id
I would suggest you save the strings in either resource strings and reuse it or do something like this :
First Activity:
Intent intent = new Intent(_context, typeOf(SecondActivity));
intent.PutExtra("Variable Name",string_to_be_sent);
startActivity(intent);
Second Activity:
//Receiving data inside onCreate() method of Second Activity
String value =Intent.GetStringExtra("Variable Name");

Error: Value of type 'String' has no member 'totalAnswered'

I am using CoreData for my project and I came into this error:
Error: Value of type 'String' has no member 'totalAnswered'
Here is my circumstance:
I have a CoreData model with the entity "Scores" and the ff. attributes:
datePlayed
totalScore
totalAnswered
I am using a table to show the data above.
Here is the problem part of my code for the Cell data:
if let date = score.datePlayed, let score = score.totalScore, let questions = score.totalAnswered {
I have no trouble saving into the entity "Scores" using the term "score" as illustrated in the code above. Also, I have no trouble showing the "score.datePlayed" and the "score.totalScore". However, the code "score.totalAnswered" is where I am having problems. It receives the error code above.
I have tried cleaning my project but the error still persist.
What should I do to show the data of "score.totalAnswered"?
EDIT:
I am using the code above to display the data using the ff. code:
cell.textLabel?.text = "Date: \(date)\nScore: \(score)/\(questions)"
Look at the 2nd let. You create a new variable named score that hides the original variable named score. So the 3rd let is trying to access the wrong score.
The best solution is to use a different variable name on the 2nd let.

Deedle - create empty list and series

I am new to F#, looking at it as an alternative to Matlab.
In reference to this question, how can I create an empty Serie and an empty Frame.
If I did not just miss it, why an empty Serie or Frame has not been designed in the library,
something like list.empty ?
Adding Frame.empty and Series.empty is a great suggestion. I think these should be in the library and I'm adding an issue to GitHub to make sure they get added.
In the meantime, you should be able to use something like this:
let empty : Series<int, float> = series []
let empty : Frame<int, string> = frame []
Note that I had to add type annotations - from my code snippet, the compiler cannot figure out what is the type of keys and values, so I had to explicitly specify that (but if you use the values as arguments to other functions, then this should not be needed).
The second line does not actually work in the current version, because of a bug (oops!) so you can use Frame.ofRows instead, which works fine:
let frame : Frame<int, string> = Frame.ofRows []
EDIT: The bug is now fixed in version 0.9.11-beta

FirstOrDefault on List not working

I have a list like
var listDataDemo = model.Jobs.ToList();
The listDataDemo has data like following
Count = 13
[0]: {PaymentItemModel}
when i type in Immediate Window like
listData.FirstOrDefault()
it gives result
Amount: 0
Date: {1/01/0001 12:00:00 AM}
Method: "PayPal"
PayerName: null
PayerNumber: null
PaymentDetailType: Payment
TransactionId: null
But when i write(code in my class)
var demoVal = listData.FirstOrDefault(p=>p.Method=="PayPal")
The name 'demoVal' does not exist in the current context(no value)
How to get a value from LIST.
Please help me.
The below code is working fine for me. Just have a look:
List<test> testList = new List<test>();
testDB testObj = new testDB();
testList = testObj.fn_getAll();
var abc = testList.FirstOrDefault(a => a.Id == 3);
And you just try to change the name of the variable, this might be causing the issue.
I hope it will help you.. :)
Off the cuff, the predicate you're providing to FirstOrDefault to filter results looks like it has a syntax error: (p=>p.Method="PayPal") should be (p=>p.Method=="PayPal").
Granted this was probably a typo, for completeness:
'=' is an assignment operator, for when you want to assign a value to a variable.
'==' is an equality comparison operator, for when you want to test equality between values and get 'true' or 'false'.
Edited to answer beyond the typo...
Are you using Entity Framework?
EF has extension methods for FirstOrDefault also, except the filter parameter is an SQL query. If you're using EF, then you could be missing the following:
using System.Collections.Generic;
using System.Linq;
It looks like the predicate in your call to FirstOrDefault has a typo. You want == for comparison, not = for assignment.

Resources