Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
So basically, a user is gonna type in the hours in an inputfield and I'm gonna get the amount they write as an int in my code.

C#
public InputField hours, minutes; 
public int wantedHours, wantedMinutes;

Basically what I want is that people are gonna write a value in the inputfields. One of the inputfields is gonna be the hours you see in my code and the other one is gonna be minutes. What I want is to get those inputfield inputs as wantedHours and wantedMinutes.

What I have tried:

I have tried some things but I realized they were not related to the thing I want to get so they were basically useless.
Posted
Updated 26-Jan-22 9:28am
v3
Comments
Richard MacCutchan 26-Jan-22 5:46am    
Where is the code that you actually try to access those fields?

1 solution

THIS WORKED FOR ME:

C#
string wantedHoursString = hours.text;

if (int.TryParse(hours.text, out int result))
{
    wantedHours = result;
}

string wantedMinuteString = minutes.text;

if (int.TryParse(minutes.text, out int resultt))
{
    wantedMinutes = resultt;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900