converting string to integer, subtracting strings.

Hi,

 I have a textbox into which the user will enter a number

I then have button that when the user clicks, the number taken from the textbox will be subtracted by one or more(depending on the users situation) and displayed in a label.  

The problem i am having at the moment is that when i attempt to do this an error comes up saying that "the operator '-' cannot be used with string or int".

String Score1 = txtScore1.Text:

String netScore1;

 

netScore1 = Score1 - 1;

lblNetScore1.Text = netScore1;

 

I have also tried to declare my variable as an integer but it wont allow me to implicity convert a string to an integer.

int score1 = txtScore1.Text: 

 

any suggestion?

 

 

0
marcobodia
2/25/2008 4:09:07 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies
1210 Views

Similar Articles

[PageSpeed] 27

please, try this code:

netScore1 = Convert.ToInt32(Score1) - 1;


Please, mark as answer if this post helped you
"I am nobody
Nobody is perfect
Therefore, I must be perfect!"
0
lotuzwine
2/25/2008 4:28:07 PM

I tried this:

 

string score1 = txtScore1.Text;string netscore1;

 

netscore1 =
Convert.ToInt32(score1) - 1;

lblNetScore1.Text = netscore1;

 

 

but it returned this error:

 

Error 1 Cannot implicitly convert type 'int' to 'string' 

 

 

0
marcobodia
2/25/2008 4:37:24 PM

hi,

please, try this:

int iNetScore1 = Convert.ToInt32(score1) - 1;
netscore1 = iNetScore1.ToString();
lblNetScore1.Text = netscore1;


Please, mark as answer if this post helped you
"I am nobody
Nobody is perfect
Therefore, I must be perfect!"
0
lotuzwine
2/25/2008 4:40:10 PM

excellent!

It worked perfectly.

 

thanks a million

0
marcobodia
2/25/2008 5:01:47 PM
Reply:

Similar Artilces:

string to string[]
Hi, I've got this code : string[] Params; string SQL = "SELECT * FROM T_MANAGEMENT_PAGES"; SqlCommand myCommand = new SqlCommand(SQL, myConnection); myConnection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(); try { while (myReader.Read()) { Params_Type = myReader.GetValue(0).ToString(); } } catch { } finally { } myReader.Close(); My problem is to obtain Params_Type. But each time, it says : "impossible to convert '[object]' in 'string[]' &quo...

String and String[]
What will be the advantage of using myString: String[10] over myString: String Man wrote: > What will be the advantage of using > myString: String[10] > over > myString: String "String[10]" is a fixed-length, statically allocated, Ansi-based ShortString. "String" is a dynamic-length, dynamically allocated, reference counted, Ansi-based or Unicode-based (depening on Delphi version) Long string. Unless you absolutely need the static, fixed length nature of ShortString, such as in records that interact with external systems, you should stay ...

String and string?
Hi guys, I was wondering the difference between small letter string type and a capital letter String type. Does anyone know about this? Highly appreciate for your answers! Thankz! The "proper" version is String, as it references the System.String class of the .NET Framework Class Library. The ability to use string is provided by C#, where it is an alias to String. Similarly, the "proper" version of an integer is Int32, as it references System.Int32.  The ability to use int is provided by C#, and the ability to use Integer is provided by VB.NET, and both int and Integer are aliases...

string and string[]
hello, whats the difference here between string and string[] thanks "string" denotes an item of type String "string[]" denotes an array of type String itemsThanks, EdMicrosoft MVP - ASP/ASP.NET Gracia mon ami...

string() = string()
this code does not work (not instance of object) Dim Items(), Other() As String Items = New String() {"A","B","C"} Other = New String() {} Other = Items how can I get all the values ? angiras Hi, If I understand your requirement correctly, this should do it Dim Items() As String = {"A", "B", "C"} Dim Other(Items.Length - 1) As String Items.CopyTo(Other, 0) To more closely match you code above, but this will be less efficient Dim Items(), Other() As String ...

converting web control string values to integers
I have a form using dropdown lists with numbers (1,2,3,4,5) I want to use these numbers to perform calculations but they are returned as stings. How can I convert them into integers? [C#] string MyString = "123"; int x = Int32.Parse(MyString); // throws an exception if MyString does not contain a numeric value such as "123b" [VB.NET] Dim MyString As String = "123" Dim x As Integer = Int32.Parse(MyString) ' throws an exception if MyString does not contain a numeric value such as "123b" Picky thanks much - that worked - was struggling...

Is there any function to convert string to integer in VB.net?
Is there any function to convert string to integer in VB.net? thank you very much.As Heinlein said "specialization is for insects" explore beyond the universe. Hi There, You can do this Dim Val as String = "50" Dim i As Integer = Convert.ToInt32(Val)DC517Don't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved. thank you very much dennisAs Heinlein said "specialization is for insects" explore beyond the universe. Hi There, No problem, always welcome...

Convert string to string array.
Hi, We have a string array argument in datawindow object for 'IN' sql statement. Our user enter a string in a single line edit. How to convert the string to a string array for the argument of datawindow? ex. user input : 'A', 'B', 'C' => str_arr[]={'A', 'B', 'C'} dw_1.retrieve(str_arr) Thanks in advance. Take a look at the n_cst_string object in the pfc. It has a method called of_ParseToArray that does exactly what you're looking for. It's a pretty simple task to 'port' the code ...

convert octet string to string
I'm trying to use IDM 3.5.1 provision an AD environmnet with users from eDir. We wanna provision as much info as possible, but one attribute gives us headaches. This is an auxiliary attribute associated with each user in eDir that has it's syntax set to octet string. Problem is we need to provision this over to another attribute in AD that uses string as its syntax. Is thee a way through XPath or ECMA script to have the value converted during the provisioning? I've no experience with either XPath or ECMA so please be detailed in your replies. Thx -- jdoeconsu...

Converting a list of string into string
When I try the following code in Prism I get the error "Error 8 (CE15) Type mismatch, cannot assign array of System.String to System.String " ***************************************************************** var mobileNumberList :List<string> mobNumberArray :string Begin mobileNumberList.add('1234567890'); mobNumberArray := mobileNumberList.ToArray();//error here end; *************************************************************** What needs to be done to convert an array of strings to a string Venkatesh Venkatesh VT a écrit : > When I...

How to convert a String into a UTF8 String
Hello! I want to convert a normal String into a UTF8 String for example:myString = BüromyUTF8String = Büros  I dont know how to do this. In PHP you can do this with myUTF8String = utf8_encode(myString) Thank you for all hints! try this string test ="ÁÉÍÓÚ áéíóú àèìòù äëïöü Ññ €"; byte[] a= System.Text.Encoding.UTF8.GetBytes(test); string test2= System.Text.Encoding.UTF8.GetString(a);  greetingsBest Regards,Sebastián DopicoBlog Desarrollador Thank you Sebastián! If I make it like that - test2 looks the same as test.But I think my problem is solved. (Someone tol...

Convert UPPERCASE string to Upper-Lower Case (ie. THIS IS MY STRING -> This Is My String)
I recently had the need to convert an all capitalized string to upper/lower case, but couldn't find anything to do it in XSLT 1.0.  If it helps anyone out, I wrote the following:   Call it using: <xsl:template match="Ads">  <xsl:call-template name="ToUpperLowerCase">   <xsl:with-param name="inputString" select="YOURSTRINGHERE"/>   <xsl:with-param name="index" select="0"/>   <xsl:with-param name="loopCount" select="st...

PB 11 .Net Web Form return a simple string?
Is it possible to create a pb 11 webform app that will accept input parms and return a simple string in response? Not trying to convert an existing app, I just want to be able to create web forms that can accept input parms, query a database to determine the answer based on the parms, and then return the answer in string format. For example, if I typed in the following url http://localhost.com/test?empid=1000 it might return "John Doe" as a simple string. WebForm is the wrong direction. You can create a .net assembly and use this inside asp. No big deal. ...

a string in a string in a string in my code behind....
I know my title talk about code-behind, but this is really a client-side problem (and surely a newby one too, sorry about that).I have a javascript function that my make a little text appear when the onmouseover event of a link is activated.So, normally, if my link was inside my html code, it would be something like this:<a href = "whocare.com"  onmouseover="poplink('I want to test something');">test</a>BUT, for some reason, I have to write this part in code behind with the LiteralControl function....and that will give something like that:this.Controls.Add(new LiteralCo...

Web resources about - converting string to integer, subtracting strings. - asp.net.web-forms

Math Dots(Dinosaur):: Connect To The Dot Puzzle / Kids Flashcard Drills for Adding & Subtracting on the ...
Get Math Dots(Dinosaur):: Connect To The Dot Puzzle / Kids Flashcard Drills for Adding & Subtracting on the App Store. See screenshots and ratings, ...

"I'm trying my best not to be cynical, but: Is subtracting context par for the course for NYT editorialists?" ...
"In this case it was almost as if the columnist was so eager to seize upon the Godwin's reference that she failed to even attempt to comprehend ...

Cruise lines still adding ships while subtracting from Caribbean - canada.com
The Caribbean is on sale. If you haven’t noticed, late summer and fall pricing for Caribbean cruises is well below the norm and, while it’s still ...

Subtracting AP poll leaves BCS again scrambling for legitimacy
The BCS now has even more legitimacy problems caused by losing the Associated Press poll as part of its formula, but the organization still is ...

VCs: Adding Or Subtracting Value To Biotech Startups?
Last month legendary investor Vinod Khosla commented that 95% of VCs add “zero value” and 80% probably “add negative value” in how they advise ...

Subtracting Ads : Web User Develops Program to Delete Unwanted Commercials
The sudden growth of advertising on the Internet's World Wide Web was making veteran hacker and Net surfer James Howard cranky. So the 23-year-old ...

Report: Google May Be Subtracting Its Photo Service From Google+ And Offering As A Standalone Product ...
Cue the Google+ is dead talk. Today Bloomberg reported that the photos service that’s been the biggest boon to Google+ may become independent ...

Podcast nerdery: Subtracting audio from a stereo file
Here’s some podcast/audio nerdery that won’t be of interest to most people, but it’s saved my bacon more than once and just this morning it appears ...

"Simplicity is about subtracting the obvious, and adding the meaningful."
“Simplicity is about subtracting the obvious, and adding the meaningful.

Do Tom Friedman and David Brooks All by Themselves Make the New York Times Op-Ed Page a Value-Subtracting ...
Dan Drezner makes the case with respect to Tom Friedman: >Man, the State and trust: Thomas Friedman captures the sentiments of a lot of the foreign ...

Resources last updated: 12/6/2015 7:26:38 PM