Question:
Visual Basic.net help!?
RoMa5_
2007-04-09 03:47:50 UTC
how can i creat a messgebox wher the user can enter values... i wanna calculate the average grade of a class... a messgae box pop up the user enter the number of the grades the he enters a grade after the other! i just dont know how to create a message box that contains a text box and a ok buuton! 10x!
Three answers:
2007-04-09 14:53:20 UTC
What you want is a inputbox. A messagebox displays text and does not return a value, where as a inputbox does.

Inputbox(Prompt as String, Title as String, DefaultResponse as String, XPos, YPos)



Not there are a couple of ways to preform the task that you want.

1)Go through a countrol counter loop.

2)Enter grades through a infinant loop.



The first way is the easiest.

We will create a counter as integer(for the loop) and a total amount as double(for the grade input).

So ...



Dim counter as Integer, total as Double



'Then initiate the controlled loop

'Lets say we want five(5) grades

'Make it loop through five(5) times

For counter = 1 To 5

'Add those grades together

total += Val(InputBox("What grade?", Me.Text))

Next

'Display the percentage

MsgBox(total / 5 & "%", , Me.Text)



-----------------------



The second way is not defining the amount of grades you want to user the input (infinate amount).



'Start by declaring your variables



Dim final As Integer

Dim counter As Integer = 0

Dim current As String



'Initiate an infanant loop



While 1 > 0

'Get the grade

current = InputBox("Grades", Me.Text)

'Test the string input

Select Case current

Case Is > "a"

MsgBox("Error, must a number value", , Me.Text)

'If it is blank show the grades

Case Is = ""

MsgBox(final / counter, , Me.Text)

'Exit the loop

Exit While

Case Else

'If the user entered a number

'Add the grades together

final += CInt(current)

'Get the input number

counter += 1

End Select

End While
?
2007-04-09 12:30:59 UTC
Since you want a popup message to allow userinput, VB.NET has a function similar to a message box called an input box. The InputBox deals with user input by providing a popup message prompt with a title. There is provision for a default response if the user returns without entering.



dim str AS String

str = inputbox("Prompt","Title","Default String")



You can use this in your program by first using an input box to prompt the user for the number of values to be entered.. Then using a second input box in a FOR/NEXT loop to collect test scores...
Can G
2007-04-09 11:28:08 UTC
Do you remember me? I answered your last question about linking forms in Visual Basic. I am the programmer that answered your last question. I have your answer. First add two textboxes to the form1. Insert a label that tells the user to enter the year we are in to the textbox1 and his/her birthday. and add a button to calculate the difference. Add a Label and make its name (lab) Subtract the textboxes heres how to do it :



Dim c as integer

c = textbox1.text

Dim g as integer

g = textbox2.text

lab.text = c - g

If lab.text = "7" then

messagebox.show ("first grade")

end If



If lab.text = "8" then

messagebox.show ("second grade")

end If



If lab.text = "9" then

messagebox.show ("third grade")

end If



So the code for showing a message box is



MessageBox.Show ("The thing you will write")



If you want to show a text that is in a textbox or label or anything for example :



lets have a textbox that user puts his name in it.write this code to the button :



dim name as string

name = TextBox1.text

MessageBox.Show (name)



So when you are showing the user a text in a textbox or something, dont use this ( " )



Note : I added you to my contacts.



Hope I helped !


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...