הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, December 21, 2011 8:11 PM
I have one inputbox, but the problem is when I click the button Cancel my program falls. I wish that when I click on button Cancel, inputbox close. And i wish, when input field empty ,OK button can't be used. I have visual basic 2010
All replies (6)
Wednesday, December 21, 2011 8:23 PM ✅Answered
If the user clicks on Cancel, InputBox will return a zero-length string. You need to make sure that your program can handle this.
There is no way to disable InputBox's OK button when the input field is empty. You can specify a default value that will appear in the input field as soon as the InputBox is displayed it's the 3rd parameter in the InpuBox call), but there is nothing to stop the user deleting this value and clicking OK. Again, your programs needs to be able to handle a zero-length string returned from InputBox.
If you want exactly the behavior you describe, you can create your own dialog box and give it that functionality.
Wednesday, December 21, 2011 8:45 PM ✅Answered
See my earlier reply. InputBox will return an empty string if
- The user clicks cancel
- The input field contains an empty string and the user clicks OK
InputBox does not give you a way to prevent either of those actions, so you need be be able to handle them (or use a custom dialog box instead of InputBox).
Wednesday, December 21, 2011 8:16 PM | 1 vote
At a guess you have not checked the result of the inputBox.
But with invisible code it is difficult to be certain. :)
PS You cannot disable buttons in the standard InputBox - you get both of them. You could of course create a form that acts like an inputBox with the enter button disabled until the textbox has some content.
Regards David R
Every program eventually becomes rococo, and then rubble. - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
Wednesday, December 21, 2011 8:31 PM
Dim i As Integer = ListBox1.SelectedIndex
Dim brsr, brpon As String
If i = -1 Then
Exit Sub
End If
Dim n, m As Integer
n = ListBox2.Items.Count
m = n + 1
brsr = Microsoft.VisualBasic.InputBox("Unesite broj serije vežbe koju ste izabrali?", "Broj serija")
brpon = Microsoft.VisualBasic.InputBox("Unesite broj ponavljaja vežbe koju ste izabrali?" & vbCrLf & vbCrLf & "Broj ponavljaja možete uneti kao ceo broj npr. ( 5 )," & vbCrLf & "ili ukoliko se broj ponavljaja menja pri promeni serije npr.( 12,10,8, itd. )", "Broj ponavljaja")
ListBox2.Items.Add(m & "." & " " & "/" & ListBox1.Items(i) & "/ " & brsr & "/ " & brpon)
Wednesday, December 21, 2011 8:49 PM
Ok. Thank you
Wednesday, December 21, 2011 8:50 PM | 1 vote
Your options include:
1 loop around the input until something is entered.
2 use default values - but they can be deleted
3 construct your own input box - a simple form that is shown as a Dialog
In any case you ought to validate the input. You ask for numbers (at least that's what Google says - my Serbian is non-existent) but the user can type anything. I'd suggest your own form and have it validate the input - but that might be difficult if brsr and prpon have completely different things or ranges. In that case rely on the caller to do the validation.
Regards David R
Every program eventually becomes rococo, and then rubble. - Alan Perlis
The only valid measurement of code quality: WTFs/minute.