How to express a Double in Shape.SetFormula? - string

I am trying to input a Double value into a Shape.SetFormula command
for example the following is something which I recorded via the journaling function of NX:
moveObjectBuilder1.TransformMotion.Angle.SetFormula("12.5")
According to the microsoft website, the value inside the () can only be an Integer, and obviously, any value (no matter Integer or Double value) written in this form "xxx" can be executed.
As far as I understood, "" is a String, so I changed the code like the following :
Function value() As String
Return 25/2
End Function
Sub Main(ByVal As String)
.
.
.
moveObjectBuilder1.TransformMotion.Angle.SetFormula(value())
.
.
.
End Sub
However, there will be a syntax error if the code is written like this.
May I ask, how can I let the Shape.Formula() command read a Double value? Or how can I let the Function return a value which will be in this format "..."?
Thank you very much!

I have no experience with that application but, as far as I can tell, the parameter for that method is type String because it accepts a String containing a mathematical formula that will be parsed internally. In that case, something like this should work:
moveObjectBuilder1.TransformMotion.Angle.SetFormula("25 / 2")
and do exactly the same thing as this:
moveObjectBuilder1.TransformMotion.Angle.SetFormula("12.5")
If that's not working for you then please explain EXACTLY what happens when you do it.

I've managed to solve my own problem. It was actually quite stupid, I am just simply not an expert in programming. It only took me several more tries to get the solution to my problem.
moveObjectBuilder1.TransformMotion.Angle.SetFormula("Sqrt(2)")
This is the correct way to express "Rotate this object with the angle of square root of 2."
Okay now let's talk about the problem which I've encountered. What I want is, import a value via a function, and then process it. So, SetFormula only accepts String. Therefore I can do the following :
Function value() As Double
Return 25/2
End Function
Sub Main(ByVal arg() As String)
.
.
.
moveObjectBuilder1.TransformMotion.Angle.SetFormula(value().ToString)
.
.
.
End Sub

Related

String.Split() method creates empty array spot

I am not a professional programmer, just FYI.
I am having trouble splitting a string. The resulting array has a length of 3, with the second spot (index 1) being completely empty.
I could manipulate the array to work the way I'd like, but I would rather understand why it is acting this way and code it properly from the beginning.
Dim defaultSetting() As String
Dim curSetting as String = "MENU_ITEM_ON_OPEN;;OPTIONAL_LEAVE"
defaultSetting = curSetting.Split(";;")
MsgBox(defaultSetting.Length) 'this is 3
MsgBox(defaultSetting(0)) 'this is as expected "MENU_ITEM_ON_OPEN"
MsgBox(defaultSetting(1)) 'this is empty and I do not know why
MsgBox(defaultSetting(2)) 'this is "OPTIONAL_LEAVE" and should be stored in defaultSetting(1)
Any help would be appreciated, thank you.
The problem here is that Option Strict is set to Off.
The overload of Split which is used expects a ParamArray of Char.
Because of this, the string ";;" is "silently" converted to a single char.
You can check this with following code:
Dim x As Char = ";;"
MsgBox(x)
You want to split by a string, which means you have to use another overload:
defaultSetting = curSetting.Split({";;"}, StringSplitOptions.None)
Thanks to a comment made by dbasnett I was able to find code that worked the way I was expecting, although I am not really sure why if anyone care to explain. But if not, this question has been answered, thanks.
defaultSetting = testString.Split(CType(";;", Char()), StringSplitOptions.RemoveEmptyEntries)

application.run with variables set within run method function

I am trying to run a macro with variables as follows:
Range("A1").Application.Run (SetConditionalFormatingSub,ConditionB="=""O-BETTER-T-PRV""",ConditionW = "=""O-WORSE-T-PRV""",ConditionM = "=""O-MIXED-T-PRV""")
But I get an error as follows:
Compile error
Expected =
Still a novice in excel coding, can't figure out what seems to be the problem.
Hopefully you guys can help! Thanks in advance.
Try:
Range("A1").Application.Run "SetConditionalFormatingSub", "='O-BETTER-T-PRV'", "='O-WORSE-T-PRV'", "='O-MIXED-T-PRV'"
Notes:
don't use parentheses () when calling a sub;
you can't use names for sub parameters (like ConditionW) with Run method - it only accepts arguments by position (the same order they are defined in your macro);
you can't use quotes inside quotes. Instead, use single quotes, for example " 'Hello' ", instead of " "Hello" "
I don't think you need an Application.Run method for your task. You can set conditional formatting for your range directly using FormatConditions.Add method:
FormatConditions.Add Method

Is stringA in StringB in MATLAB

Is there a way to check if a string exists within another string in MATLAB. In python this is done easily with a in b. I do not want indexes or anything like that. I just want to check if its true or not. The answers that I find is "strcmp" or "strfind" and also regexp. regexp returns indexes. strcmp(a, b) does not seem to work. I have a string a = 'ac' and another string b = 'bc_gh_ac'. And want to check if a in b.
Best regards
The answer is indeed strfind. You have to be careful with the order of the parameters which at first seems unusual - the pattern is the second argument, not the first. The following code demonstrates:
a='ac';
b='bc_gh_ac';
strfind(b,a)
If you simply want to test whether the string is present or not then use the isempty function:
if ~isempty(strfind(b,a))
disp('String is present');
end

Get Cell Content in one sheet to another

I need to get my cell content in excel worksheet to another worksheet by using a user defined function. So I searched stackoverflow and found the following vba code.
Function GetValue(sheetName As String, cellAddress As String) As Variant
GetSheetValue = ThisWorkbook.Sheets(sheetName).Range(cellAddress)
End Function
This is the right thing i expected.But it doesn't work for me. I need to develop a user defined function as like follows.
=GetContent(Sheet1,B6)
I've tried many things but I can't do it. So I'm very appriciate any responses about this matter. (Provide Screenshots about my example)
Thank You
ScreenShot 02
ScreenShot 03
I've found the answer. My function must be correct as following code.
Function GetContent(sheetName As String, cellAddress As String) As String
GetContent = ActiveWorkbook.Sheets(sheetName).Range(cellAddress)
End Function
I didn't concern abot the function name and return as the same. But we have to must do it. Also in string data type we have use quotaions and Case sensitive. So thanks all of you for valuable help. It helps me to fid out the answer. Now wecan use the functions as follows.
=GetContent("Sheet2","b5")
Thank You!

Expected array when calling function

I'm trying to learn a little VBA an I'm in the process of saving ranges as CSV files.
However, I'm having trouble with this line of code
Call SaveRangeAsCSV(SelectDown("B5:D5"), "C:\Test\test.csv", True)
And here is a snippet of the SelectDown function.
Private Function SelectDown(Range As String) As Range
SelectDown = Range(Range, ActiveCell.End(xlDown)).Select
End Function
I get the error: Expected array. I cannot seem to understand what the problem is. Any help would be appreciated :-)
It sounds like the function SaveRangeAsCSV is expecting an array, but you are passing in a Range. This function is not a built-in Excel function, so I can't check it. Maybe you could check what arguments it is expecting?
My function now looks like this and is working perfectly.
Private Function SelectDown(RangeAddress As String) As Range
Set SelectDown = Range(RangeAddress, ActiveCell.End(xlDown))
End Function

Resources