Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,938 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,439 people online right now. Registration is fast and FREE... Join Now!




Where is my wrong in this code

 
Reply to this topicStart new topic

Where is my wrong in this code, VB Studio Error

savio1
14 Dec, 2007 - 05:21 PM
Post #1

New D.I.C Head
*

Joined: 6 Dec, 2007
Posts: 3


My Contributions
Hi,

I'm trying to write my first code in VBNet, But I got the bluw line under the word " answer" in the last line.

Here is the code:
CODE

[color=#3333FF]Public Class [/color] Form1

    [color=#3333FF]Private Sub [/color] Button1_Click([color=#3333FF]ByVal[/color] sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        [color=#3333FF]Dim[/color] number1 [color=#3333FF]As Integer[/color]
        [color=#3333FF]Dim[/color] number2 [color=#3333FF]As Integer[/color]
        [color=#3333FF]Dim[/color] answer [color=#3333FF]As Integer[/color]

        number1 = 3
        number2 = 5

        answer = number1 + number2

        TextBox1.Text = [color=#FF0000][u]answer[/u][/color]
    [color=#3333FF]End Sub
End Class[/color]


I follow the tutorial in homeandlearn.co.uk

Please help to Understand my Error.

All the best
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Where Is My Wrong In This Code
14 Dec, 2007 - 05:27 PM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,280



Thanked: 136 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Well, answer is of type integer and TextBox1.Text is of type string. I thought it implicitly cast such things, but to be on the safe side, try TextBox1.Text = answer.ToString()

User is online!Profile CardPM
+Quote Post

savio1
RE: Where Is My Wrong In This Code
14 Dec, 2007 - 05:35 PM
Post #3

New D.I.C Head
*

Joined: 6 Dec, 2007
Posts: 3


My Contributions
QUOTE(baavgai @ 14 Dec, 2007 - 06:27 PM) *

Well, answer is of type integer and TextBox1.Text is of type string. I thought it implicitly cast such things, but to be on the safe side, try TextBox1.Text = answer.ToString()



Thank you very mush for your fast reply.

I try it and it work fine.

Also I try this Method and it work to.

answer = CInt(number1 * number2)

TextBox1.Text = CStr(answer)

Is this right Method to use?

Thanks
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Where Is My Wrong In This Code
14 Dec, 2007 - 06:35 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,317



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
In the future, please use code.gif tags when posting your code. Do not color code it.
User is offlineProfile CardPM
+Quote Post

vb_bmw
RE: Where Is My Wrong In This Code
16 Dec, 2007 - 12:44 AM
Post #5

New D.I.C Head
*

Joined: 16 Dec, 2007
Posts: 5


My Contributions
Hi all!

I'm new in this WebSite!

never mind!

I wants replay that in vb.net we have some convert Type Function!


some of them is:

Cstr(ex)
For Convert ex to String Format
Cint(ex)
For Convert ex to Integer Format
and more ... .

but we have the Advanced on that can Convert all
that is Ctype.

you can convert any type with this Function like this:

CODE
Ctype(Object as expression,Object as type) as type


biggrin.gif

I hope this useful for you!

sorry for bad english



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 04:28PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month