ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!

Jump to content



Photo

visual basic help


  • Please log in to reply
visual basic help

#1

xinzx1337
xinzx1337
    Offline
    2
    Rep
    6
    Likes

    Advanced Member

Posts: 102
Threads: 15
Joined: Jul 07, 2015
Credits: 0
Eight years registered
#1

Im a beginner with programming and im trying to make a simple calculator but i get this error i think i have done all steps right 
 

Error 1 Value of type 'Single' cannot be converted to 'System.Windows.Forms.Label'. c:\users\user\documents\visual studio 2010\Projects\WindowsApplication3\WindowsApplication3\Form1.vb 10 23 WindowsApplication3
thanks for help 
 

  • 0

#2

airheadz750
airheadz750
    Offline
    2
    Rep
    -2
    Likes

    Advanced Member

  • PipPipPipPip
Posts: 123
Threads: 1
Joined: Jun 28, 2015
Credits: 0
Eight years registered
#2

Could you post your code so i can have a look? its abit hard to tell without knowing what im seeing :)


  • 0

If i helped you, make sure to hit that green arrow +1 :)


#3

xinzx1337
xinzx1337
    Offline
    2
    Rep
    6
    Likes

    Advanced Member

Posts: 102
Threads: 15
Joined: Jul 07, 2015
Credits: 0
Eight years registered
#3
Public Class Form1
    Dim Num1 As Single
    Dim Num2 As Single
    Dim Answer As Single
 
    Private Sub Submit_Click(sender As System.Object, e As System.EventArgs) Handles ButtonSubmit.Click
        Num1 = TextBoxNum1.Text
        Num2 = TextBoxNum2.Text
        Answer = Num1 + Num2
        LabelAnswer = Answer
 
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Quit.Click
        Close()
    End Sub
 
 
End Class

  • 0

#4

xinzx1337
xinzx1337
    Offline
    2
    Rep
    6
    Likes

    Advanced Member

Posts: 102
Threads: 15
Joined: Jul 07, 2015
Credits: 0
Eight years registered
#4

Could you post your code so i can have a look? its abit hard to tell without knowing what im seeing :)

could you find the error ?


  • 0

#5

pas
pas
    Offline
    0
    Rep
    9
    Likes

    Member

Posts: 33
Threads: 7
Joined: Jul 24, 2015
Credits: 0
Eight years registered
#5

 

Public Class Form1
    Dim Num1 As Single
    Dim Num2 As Single
    Dim Answer As Single
 
    Private Sub Submit_Click(sender As System.Object, e As System.EventArgs) Handles ButtonSubmit.Click
        Num1 = TextBoxNum1.Text
        Num2 = TextBoxNum2.Text
        Answer = Num1 + Num2
        LabelAnswer = Answer
 
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Quit.Click
        Close()
    End Sub
 
 
End Class

 

 

TextBoxNum1.Text is a string but you're trying to store it as a single? do you not need to convert it into a single first..


  • 1

#6

xinzx1337
xinzx1337
    Offline
    2
    Rep
    6
    Likes

    Advanced Member

Posts: 102
Threads: 15
Joined: Jul 07, 2015
Credits: 0
Eight years registered
#6

TextBoxNum1.Text is a string but you're trying to store it as a single? do you not need to convert it into a single first..

how can i do it ?


  • 0

#7

pas
pas
    Offline
    0
    Rep
    9
    Likes

    Member

Posts: 33
Threads: 7
Joined: Jul 24, 2015
Credits: 0
Eight years registered
#7

how can i do it ?

 

try:

 

Num1= Convert.ToSingle(TextBoxNum1.text)

Num2= Convert.ToSingle(TextBoxNum2.text)

 

instead of:

 

  Num1 = TextBoxNum1.Text
  Num2 = TextBoxNum2.Text

Edited by pas, 26 July 2015 - 12:42 PM.

  • 1

#8

xinzx1337
xinzx1337
    Offline
    2
    Rep
    6
    Likes

    Advanced Member

Posts: 102
Threads: 15
Joined: Jul 07, 2015
Credits: 0
Eight years registered
#8

 

try:

 

Num1= Convert.ToSingle(TextBoxNum1.text)

Num2= Convert.ToSingle(TextBoxNum2.text)

 

instead of:

 

  Num1 = TextBoxNum1.Text
  Num2 = TextBoxNum2.Text

 

thanks  but still not working 


Edited by xinzx1337, 26 July 2015 - 12:54 PM.

  • 0

#9

xinzx1337
xinzx1337
    Offline
    2
    Rep
    6
    Likes

    Advanced Member

Posts: 102
Threads: 15
Joined: Jul 07, 2015
Credits: 0
Eight years registered
#9

found the problem all needed to do was add a .Text to LabelAnswer 


  • 0

#10

raphaelfigueire
raphaelfigueire
    Offline
    2
    Rep
    1
    Likes

    New Member

Posts: 24
Threads: 0
Joined: Jun 26, 2015
Credits: 0
Eight years registered
#10

a


  • 0


 Users browsing this thread: