I want to make several of my textbox.text properties equal to variables. I tried:

 Dim outcome As New txtResult.Text
    outcome = "xxxxx"

this produced an error. :(

first, is this possible and if it is, what am I doing wrong???

Recommended Answers

All 8 Replies

I don't know VB.NET, but what is the specific error message?

Line 1 produced an error for me. Maybe you need to tell me more why you declared this in this way.

Dim outcome As String
outcome = "xxxxx"

You seem to be incorrectly instantiating a textbox variable. What are you trying to achieve? Putting a textbox dynamically on your form?

Hello again,

This problem was my own fault for not completly knowing what I was doing. here is the code I was attempting to do. I have a textbox named txtResult. I wanted to define a variable equal to the .text property of textbox. I defined the variable as follows.

  dim result as new txtDisplay.text

This was the incorrect way of trying to do this.

 dim result as integer
 result = val(txtDisplay.text)

This worked much better

I learned a lot about objects and methods while researching the issue I was having here

Just realize that there is nothing to stop the user from entering a value that will throw an exception when you try to convert it to an integer. Either check that the string is an integer-equivalent, or put it in a Try block to trap the error.

hi Jim,
thankyou for the advice.

Correct me if I am wrong, but I thought the VAL function stripped away anything that was not a number?

i am fairly new at coding vb.net and have not tried the try/catch code yet, but I will

It's been ages since I used vb.Net but as I recall, Val attempts to convert a string to a number but errors out if the string is not a valid number.

My mistake. Val will not throw an error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.