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
Related
I'm a bit of a noob. When I try to build my solution I get this single error and I don't know what to do to fix it.
'Calculate and display cost estimate
decCostEstimate = decFeet * decCostPerFoot
**lblCostEstimate = decCostEstimate.ToString("C")**
I'm not sure what to do. Please help me.
You want to set the Text property of the label, not the label itself
lblCostEstimate.Text = decCostEstimate.ToString("C")
Your code tries to assign a string value to an object of type Label, thus causing the error.
The label is an object from the type Label.
It is not possible to write an object from Type int or string, etc. into an label-object.
To make the label show your result just put the result into the text-property of the label:
lblCostEstimate.Text = decCostEstimate.ToString("C")
Access 2013
I'm calling a formula to modify a string and it's changing the values w/in the parent sub.
Example:
Debug.Print Str 'Hello World my name is bob
BOBexists = InStringChceck(Str,"bob")
Debug.Print Str 'HELLO WORLD MY NAME IS BOB
Debug.Print BOBexists 'TRUE
I've used this function, InStringCheck, in Excel VBA before (and it's just an example, all of my string tools are doing this same thing now and I don't know why)
Function InStringCheck(Phrase as string, Term as string) as Boolean
Phrase = UCase(Phrase)
Term = UCase(Term)
if instr(1, Phrase, Term) then InStringCheck = True else InStringCheck = False
end function
In several of my functions I manipulate the input variables, to arrive at a solution, but I don't want those manipulations to persist outside of the function unless I pass them back up - some how they're being passed up, but they're not dimed as public variables
VBA parameters are implicitly passed by reference (ByRef). This means you're passing a reference to the value, not the value itself: mutating that value inside the procedure will result in that mutated value being visible to the calling code.
This is often used as a trick to return multiple values from a function/procedure:
Public Sub DoSomething(ByVal inValue1 As Integer, ByRef outResult1 As Integer, ...)
You have two options:
Pass the parameters by value (ByVal)
Introduce local variables and mutate them instead of mutating the paramters (and heck, pass the parameters ByRef explicitly)
If you have lots of occurrences of parameters being implicitly passed ByRef in your project, fixing them everywhere can easily get tedious. With Rubberduck you can easily locate all occurrences, navigate there, and apply appropriate fixes:
Disclaimer: I'm heavily involved in the Rubberduck project.
Building a little on #Sorcer's answer, VBA has default Sub/Functions parameters passing "by reference" (i. e.: "ByRef" keyword assumed if not specified) so that if you don't want their "inside" modifications survive outside them you have to explicitly type "ByVal" keyword before them in the arguments list.
But you have the option to avoid such modifications take place altoghether by using StrComp():
Function InStringCheck(Phrase as string, Term as string) as Boolean
InStringCheck = StrComp(Phrase, Term, vbTextCompare) = 0
End Function
Which could also lead you to avoid the use of InStringCheck() in favour of a direct use of StrComp() in your code
The program asks for input in gui editbox as a value, then it takes this value and applies the equation to get the pressure. I haven't been able to do so and I heard from some classmates that matlab takes the input as a string and doesn't operate strings.
get(handles.spl,'String') this is how I get the value, I tried get(handles.spl,'Double') instead but it didn't work, also tried str2double.
I don't know what else to try, I'm also pretty new in programming.
I'd appreciate the help, thanks.
You are correct that the uicontrol String property returns...a string. So you'll need to convert it to a number using str2double.
u = uicontrol('style', 'edit', 'String', '42');
strvalue = get(u, 'String');
numvalue = str2double(strvalue);
% 42
i have an easy question but i m stack at the moment and i was wondering if anyone can help me out,
i want to display from the messagebox in powerbuilder inside the box static text and then the value of a variable,
ok i can show easily the value like that,
Messagebox( 'Message', NbrRows)
But i want to show inside the box before the value of the variable NbrRows the text,
'Total events so far' and then the variable value.
I know that the syndax of the messagebox is like that for example with an exclamation icon
MessageBox("Result", Abs(NbrRows), Exclamation!, OKCancel!, 2)
please any help would be really appreciated,
thank you in advance
The MessageBox() built-in function can take different datatypes for its second parameter (message) but if you need to mix different types at once, pbscript does not support to concatenate a string with another type like a long or a boolean e.g "foo" + 42. To do so, you need to convert other types to text with the string() function:
MessageBox( 'Message', 'Total events so far' + string(NbrRows))
//or if some other processing needed with the value
MessageBox( 'Message', 'Total events so far' + string(Abs(NbrRows)))
Beware that a null value will propagate to the whole expression in the case where NbrRows could be null, resulting in no message at all. Using the [general] format with string() is a useful trick that will replace a null value with an empty string:
MessageBox( 'Message', 'Total events so far' + string(Abs(NbrRows), '[general]'))
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();