Im making a calculator Program to start off on visual basic. I got it to work with MsgBox, but now I'm trying to get it to work with the Print.

MsgBox Example

Public Class Form1
    Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick
        Dim Pizza As Integer
        Dim Taco As Integer
        Dim Cheese As String
        Dim Cat As String

        Pizza = InputBox("Please Enter the first number")
        Taco = InputBox("Please Enter the second number")
        Cheese = (Pizza + Taco)
        Cat = ("youranswer is " + Cheese)
        MsgBox(Cat)
    End Sub
End Class

Print Example

Public Class Form1
    Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick
        Dim Pizza As Integer
        Dim Taco As Integer
        Dim Cheese As String
        Dim Cat As String

        Pizza = InputBox("Please Enter the first number")
        Taco = InputBox("Please Enter the second number")
        Cheese = (Pizza + Taco)
        Cat = ("youranswer is " + Cheese)
        Print(Cat)
    End Sub
End Class

Say I type in 6 and 6 I'm geting erros saying Example:

Conversion from string "youranswer is 12" to type 'Integer' is not valid.

Ive tried many things, but it's not working. I want to know what I need to do to get it to print out how I want it. Do I need to do some conversions properly somehow?

The + sign is actually representing the sum.

Cheese can be converted to a number while "youranswer is" can not.

Because InputBox returns always an string (that maybe empty) I would try some thing like

Dim Pizza As String
Dim Taco As String
Dim Cheese As String
Dim Cat As String = "You entered bad values"
Pizza = InputBox("Please Enter the first number")
Taco = InputBox("Please Enter the second number")
If Taco.Lenght>0 AndAlso Cheese.Length>0 then
    Dim iTaco as integer
    Try
        iTaco = Ctype(Taco, Integer)
    Catch ex As Exception
        Goto BadValue
    End Try
    Dim iPizza as integer
    Try
        iPizza = Ctype(Pizza, Integer)
    Catch ex As Exception
        Goto BadValue
    End Try

    Cheese = (iPizza + iTaco).ToString
    Cat = "youranswer is " & Cheese
End If
BadValue:
Print(Cat)

Hope this helps

yeah thank you dude this helps alot a few things in there i have to study but I have no doubt that it will help me. I Knew that it was doign that, I saw a few code that you used when i clicked on help with my client but could't figure out how to use them.

Thanks again.

Be a part of the DaniWeb community

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