Convert String To Integer And Vice-Versa - string

I'm building a calculator application, and I have a Form, with a TextBox called txtVisor, that has the property NumbersOnly = true. I want to get the content of it(that I already know: txtVisor.Text) and convert it into a Integer, to do multiply it by 12, then convert the result into a String to set the txtVisor.Text as the result of the operation. How could I do this?
PS: I'm using NSBasic 7.0

txtVisor.Text = cstr( cint(txtVisor.Text)*12 )
The current version is NS Basic/CE 8, which will make your life much easier when it comes time to deploy your app.

Related

How do i get an input of time in milliseconds?

private long START_TIME_IN_MILLIS;
private long TimeLeftInMillis = START_TIME_IN_MILLIS;
i have declared these variables, which is meant to store an input from an EditText, but in my OnCreateView i have this line
START_TIME_IN_MILLIS = edtInsertTime.getText();
but it gives me an error, how do I get the input of time in milliseconds and store it in START_TIME_IN_MILLIS?
You didn't post the error you received, and that would be helpful since it can be of hundred reasons..
Just looking at this code, you have variable of type long, ( which is a numeric type ), and what you get from edtInsetTime.getText()? , a type "Editable" according to the documentation, and you can't store Editable object in a long variable.
https://developer.android.com/reference/android/widget/EditText
public Editable getText ()
Returns Editable - The text displayed by the text view.
To get a long value from it, you first need to get a String from this EditText, then convert it to a long format, and then assign it to the variable.
Examplary code would be.
START_TIME_IN_MILLIS = Long.valueOf(edtInsertTime.getText().toString());
Breaking it down.
String text = edtInsertTime.getText().toString()
returns the String value of an edittext
That value then can be converted to a long value by parsing the String to long, with methods like
Long.parseLong(text)
or
Long.valueOf(text)
Asking this question means you don't have basic understanding of how types works in java, so feel free to read about it https://www.baeldung.com/java-primitives

Arithmetic operation in jmeter Groovy

I created a script that receives a variable from another sampler.
I put the variable in a new variable (not want to mess with the source).
And I tried to double the result, the problem is that it multiply as a string and not as in math.
The variable is 6, and I wanted to display 12, but it display 6.0 6.0.
Moreover, how can I save the results in a new variable?
System.out.println(" Impression Price *2 is: " + Impression_price*2);
System.out.println(" Impression Price*2 is: " + (Impression_price.multiply(2.0)));
You need to cast your args[3] which is a String to a corresponding numeric type, for example:
def Impression_price = args[3] as float
Demo:
More information: Creating JMeter Variables in Java - The Ultimate Guide
You need to convert String do double using Double.parseDouble, for example:
def Impression_price= Double.parseDouble(args[3]);
When you log you need to convert back to String using String.valueOf, for example:
log.info(String.valueOf(Impression_price*2));
To put a non String value you need to use vars.putObject:
vars.putObject("Impression_price_double", Impression_price *2);

vb.net Unable to keep decimal places when converting string to single

I have been working on a vb.net project and have run into a problem. I have tried various implementations from Stackoverflow and MSDN but nothing is working. All I am trying to do is convert a string value to a single and keep the precision.
An example of the code would be something like this:
Dim Total As Single = 0
Dim s as String = "427.00"
Total += Single.Parse(s)
// Total = 427
// Expected : 427.00 <-- I need this
I have tried using cultureinfo.invariant,
I have tried using string.format,
I have tried using double instead of single,
I don't know what I am missing.
Any insight would be appreciated, and I can provide more code of what the application is trying to do if necessary.
In addition to #Alex B.'s comment, this is how you would achieve this. Total is a String but the program will bomb if either is not a Single type giving you some type safety.
Dim Total As String = "0"
Dim s as String = "427.00"
Total = (Single.Parse(Total) + Single.Parse(s)).ToString("0.00")

SSRS 2012 #error when combining string and monthName return types in iif() statement

I am having a really strange error when using the iif() statement in SSRS 2012.
I am trying to choose to print the name of a month whenever a month value is not equal to 99, and when it is equal to 99, I would like to print the string "Y.T.D" I was trying to achieve this using the statement:
=iif(Fields!Month.Value = 99, "Y.T.D", MonthName(Fields!Month.Value, true) )
Whenever I try to use this MonthName() function the months are printed correctly but the 99 field returns as "#error". This statement works fine when I leave the month as an integer or if I simply put in a dummy string, and I have already tried casting the MonthName() as a string (eg. "cStr(MonthName())").
Any ideas???
To answer my own question/to quote another answer I recieved from Syed Qazafi Anjum on Microsoft's forum:
=iif(Fields!Month.Value=99,"Y.T.D",monthname(iif(Fields!Month.Value<=12,Fields!Month.Value,12),true))
As taken from:
http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/d484d8d4-3809-4850-ada6-8cac1239bfce/
The MonthName function gets evaluated even when the month number is 99. Use switch instead of iif to fix this.

String text to long value

Well, thats it!
I need to convert a string text (like"Hrd$457"), into a long value.
The blackberry IDE has a button that do it, but i need do this by code.
Please note that the string is alpha numeric.
THX!
NOTE:
Sorry if my question was not really clear. The IDE button that im talkin about converts the entire string in a long value that makes that string a unique number. The BlackBerry documentation says:
"To create a unique long key, in the BlackBerry® Integrated Development Environment, type a string value.
com.rim.samples.docs.userinfo
Right-click the string and click Convert ‘com.rim.samples.docs.userinfo’ to long."
So, i need to do exactly the same but by code.
I really appreciate your help buddies, and thanks so much for trying to help.
If you are just looking for a number constant for a string you can do the following.
String str = "asdfasdf345asdfasdf";
int asInt = str.hashCode();
long asLong = (long) asInt;
Returns the first 8 bytes of a SHA1 digest as a long. The same result can be obtained interactively using the BlackBerry JDE by highlighting a string, right-clicking, and choosing "Convert '' to long" from the context menu.
long net.rim.device.api.util.StringUtilities.stringHashToLong(String key)
This is another approach. If there are multiple numbers you can loop through the String using the scanner.
Scanner scanner = new Scanner(str);
scanner.useDelimiter("\\D+");
Long number = scanner.nextLong();
Not sure I fully grasp your example, but how's this?
String match = Pattern.compile("\\d+").matcher("Hrd$457").group();
long longValue = Long.parseLong(match).longValue();

Resources