Resolved integer double string?

iamyou

Member
Joined
Sep 7, 2009
Messages
12
Programming Experience
Beginner
Hey i've got another problem with my coding in this sub...


VB.NET:
    Private Sub buyLemon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buyLemon.Click
        lemonL.Text += 1
    End Sub 'BuyLemons


can someone please tell me why its coming up with this error


Conversion from string "Lemons" to type 'Double' is not valid.


its for a lemonadeTycoon game im making
 
Last edited:
Because youre trying to increment a string using an integer, why are you adding 1 to string "lemons", maybe if you could tell me what you're trying to archieve i could help you.
 
When does the error appear, before you compile it or at runtime?

If it's at runtime, go back and turn Option Strict On. It wont 'stop' the error, but it will make your coding better in the long run :)
 
Because youre trying to increment a string using an integer, why are you adding 1 to string "lemons", maybe if you could tell me what you're trying to archieve i could help you.


im trying to increase a string by one everytime you click a button but for some reason its taking it in as a double there are no other variables or objects call lemonL and i cant realy change anything until i can test it
 
I think you've missed BlackByte's point. You cannot increase a string by 1. For example, the following is invalid :-

VB.NET:
 Dim TestString As String = "ABC"
        TestString += 1

but this is essentially what you are trying to do. Your program doesnt know that your textbox LemonL holds a number.

If you categorically know that LemonL holds a number value, the simplest way would be :-
VB.NET:
LemonL.Text = (Convert.ToInt32(LemonL.Text) + 1).ToString

If you cant guarantee it, you'll need to TryParse the value first before adding to it.

Separately, you could try using a NumericUpDown control instead for LemonL, and then you wouldnt need to do any conversions.
 
thanks that seemed to work but could explain how it works (what means what)
nothing much its just i like to know what im typing:)
 
VB.NET:
LemonL.Text = (Convert.ToInt32(LemonL.Text) + 1).ToString

means

Take the value of the text in LemonL textbox
Convert it to a 32-bit integer value
Add 1 to the result
Convert the result back to a string
Put the result back into the LemonL textbox
 
ok but what if i wanted something to equal that value ( lemon = lemonL.text ) what would i do in that case


and i was using numeric up down but i couldnt find out how to add to the value of something
 
Last edited:
and i was using numeric up down but i couldnt find out how to add to the value of something
VB.NET:
TheNumericUpDown.Value += 1
Or you could call the UpButton/DownButton methods.
 
no i mean like if numericupdown1.value gets bigger

Upbutton / DownButton methods?

like what ive got a button that increses the value and one that decreases the value already
VB.NET:
Private Sub buyLemon_Click <---- There
 
Last edited:
Back
Top