Adding Variables to Message Boxes in Visual Basic

VB
' THIS PROGRAM WILL TEACH YOU HOW TO PUT A VARIABLE INTO A MESSAGEBOX 
' This Program will base around a favourite Celebrity and a rating from 1-10.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim celebrity As String ' makes your celebrity's variable
        Dim rating As Integer   ' makes your rating variable

        celebrity = InputBox("Enter the name of your Celebrity") ' asks for celebrity name
        rating = InputBox("Give your celebrity a rating between 1-10.") ' asks for the rating between 1-10 (1 is the worst, 10 is the best)


        MsgBox("The celebrity you entered was " & celebrity & " and you rated them " & rating & " out of 10") ' makes messagebox with both variables.

    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        End ' this just makes button2 close the program.
    End Sub
End Class

MsgBox(& VariableName & " Text here") 
"& VariableName &" Would input your variable's data into the message box.
To further explain, your variable's 'data' is what your "inputbox" collects at the beggining of the program.

One thought on “Adding Variables to Message Boxes in Visual Basic

  • March 1, 2023 at 4:43 pm
    Permalink

    thanks needed it for class

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *