English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to ask the user if he wants to input a new set of values. The question needs to loop untill the user answers no. The code i've used is below. I've been told that the "vbyes" comment is incorrect - and i can understand that - however i don't know what to replace it with.

Thanks

msgbox "do you want to input another reading...(etc)

If MsgBox = vbyes Then
Check = True
Do
(statements)
MsgBox "Do you want to input another reading...(etc)
If Msgbox = vbNo Then
Check = False
Exit Do
ElseIf MsgBox = VbYes Then
Check = True

End if

Loop Until Check = False

ElseIf VnNo Then
End if

End Sub

As much detail as you can provide would be much appreciated!!

Thanks for your time!

2007-12-28 07:20:33 · 5 answers · asked by thedaa25 2 in Computers & Internet Programming & Design

5 answers

Instead of a msgbox use a inputbox instead.

2007-12-28 07:41:55 · answer #1 · answered by youngboy1606 7 · 0 0

MsgBox is a function that returns the ID of the button clicked. You can't call it and then check it the way you are doing it. You can either assign the return value to a variable and then check the variable or check the return code as it comes back. Your looping looks much more complicated than it needs to be. I'm not sure how you're collecting your values, but this code should give you an idea of what it would look like:

Dim Answer As Integer
Dim Value As String
Do
Answer = MsgBox("More values?", vbYesNo)
If Answer = vbNo Then
Exit Do
End If
Value = InputBox("Enter value")
Loop

or you could combine these lines together and get rid of the Answer variable:

Answer = MsgBox("More values?", vbYesNo)
If Answer = vbNo Then

becomes

If MsgBox("More values?", vbYesNo) = vbNo Then

2007-12-28 07:51:46 · answer #2 · answered by TreyJ 3 · 0 0

I'm more familiar with VBA message boxes, but am assuming it's similar. When using the MsgBox command you should declare the type of buttons to appear; vbYesNo, vbOKOnly, vbOKCancel, etc. The button click returns a numeric value which you can then check as part of your loop. I think 6 is for Yes and 7 is for No.

Check the online help for button values by searching for "MsgBox".

2007-12-28 07:43:04 · answer #3 · answered by Charlie 4 · 0 0

I like to set the message box result into a variable which captures the users response.

Dim answer As DialogResult

Do
'Code to process numbers goes here

answer = MessageBox.Show("Prompt Text", "Caption Text", MessageBoxButtons.YesNo)

Loop While answer = vbYes

An input box will prompt the user like a message box but also allow the user to enter data in responce.

Dim answer As String
Dim myNum as Double

DO
answer = InputBox("Enter a number or leave blank for NO", "Do Again")

myNum = Val(answer)
'Process myNum here
Loop While answer <> "" OR answer = "No"
You will have to process the variable answer to determine if it is blank which means exit the loop. If the answer is not blank then the string will have to be converted into a double using the val function to extract a numeric value which you will process

2007-12-28 10:06:52 · answer #4 · answered by MarkG 7 · 0 0

MsgBox("Your Message")

2016-05-27 12:12:10 · answer #5 · answered by ? 3 · 0 0

fedest.com, questions and answers