I am trying to make a validation where the user is able to choose between 2 different results from a MsgBox and if no one were selected it will close. But the method that I got is not working.
This is the code that I am actually using to make this validation:
Private Sub watcher_idle(sender As Object) Handles watcher.Idle
Dim result = MessageBox.Show("The application will close because a lot of time off.", "Are you sure?", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
End
ElseIf result = DialogResult.No Then
ElseIf Timer4.Interval = 3000 Then
Timer4.Start()
End
End If
End Sub
If user select Yes the application will close, if user select no it doesn't do anything and if the user does not select anything for 3 secs or something like that the application will close automatically. But this last step is not making anything. Does not work.
Do you have any idea what I am doing wrong?
Related
I've spent too long on this so far, and searches have not helped to find what I'm encountering.
I have a DataGridView that's bound to a BindingSource ExistingHAFData. When the user pushes a button, the code goes through all the selected rows and marks the name and date of when the recorded was "Deleted" (a record with a name and date does not show up in the active list; and can be undeleted in the future).
What is happening is this is working fine for all but the last record. For example, if the user selects five records, four will properly update; the last selected row will not -- actually, for clarity -- ALL selected rows on the grid properly update, but when I call Update for the adapter, only four is returned instead of five (and in the DB's data table, four received the values, the last did not).
Public DeleteAdapter As New SqlDataAdapter
Private Sub DeleteButton_Click(sender As Object, e As EventArgs) Handles DeleteButton.Click
Dim SelectedRowCount As Integer = MainData.Rows.GetRowCount(DataGridViewElementStates.Selected)
If SelectedRowCount > 0 AndAlso MessageBox.Show("Are you sure you want to close these requests? If they have not already been filled, this will halt their progress.", "Close Requests", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
For Each dataRow As DataGridViewRow In MainData.SelectedRows
dataRow.Cells("DeletedBy").Value = Common.GetFullUserName(Common.UserName.LastFirst)
dataRow.Cells("DeletedDate").Value = Now.ToShortDateString
Next
DeleteAdapter.UpdateCommand = New SqlCommandBuilder(DeleteAdapter).GetUpdateCommand(True)
Dim DidCommit As Boolean = MainData.CommitEdit(DataGridViewDataErrorContexts.Commit)
Dim LinesChanged As Integer = DeleteAdapter.Update(CType(ExistingHAFData.DataSource, Data.DataTable))
If LinesChanged > 0 Then
LoadRecords(Fields.All)
MessageBox.Show("Data successfully saved.", "Data Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("No new data was found to save to the database. If you have made changes, be aware that they have not yet been saved.")
End If
Else
MessageBox.Show("You must select at least one row before pressing Delete.", "No Rows Selected", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
In the code above, DidCommit is True. LinesChanged, however is one less than what I'd expect.
I have tried adding lines like MainData.EndEdit() after the last cell change, but that did not change the behavior. If I pause the routine before the commit and manually edit a cell, all rows save. (this hints to me it's not fully out of Edit mode, but I can find no evidence or way to end edit if this is the case)
#jmcilhinney had the missing piece. By adding ExistingHAFData.EndEdit(), I am now getting 100% of the modified rows saved to the database.
Dim DidCommit As Boolean = MainData.CommitEdit(DataGridViewDataErrorContexts.Commit)
ExistingHAFData.EndEdit()
Dim LinesChanged As Integer = DeleteAdapter.Update(CType(ExistingHAFData.DataSource, Data.DataTable))
I had been operating on the false assumption that it was the grid itself "causing" the problem, not the bindingsource.
I have a series of text boxes that are hidden, except one which users enter a value into. After a button is pressed, this text box disappears and the rest appear. From there, I want users to be able to enter different values into each text box. These values will be saved as variables. From there, users press a button and enter new values into the text boxes, until values have been entered into the text boxes for each number up to the first value entered into the hidden text box.
I'm not sure how else to explain this, but please let me know if you have any questions.
Correct me if im wrong. i think you want an input in different textbox?
Like textbox1 = 1, textbox2 = 2 and so on. If this is right then try this.
Lets try this to your 3 textbox for an example.
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
If TextBox1.Visible = True Then
If Trim(TextBox1.Text) <> "" Then
TextBox1.Visible = False
TextBox2.visible = True
Else
MsgBox("Required")
'or user error provider.
End If
Exit Sub
End If
If textbox2.visible = True Then
If Trim(TextBox2.Text) <> "" Then
TextBox2.Visible = False
TextBox3.visible = True
Else
MsgBox("Required")
'or user error provider.
End If
Exit Sub
End If
'and so on
End Sub
hope this is what you want. just basic but maybe usefull :)
This is the workflow of what you want to accomplish in JavaScript. VB.Net has similar functions to Visibility. https://msdn.microsoft.com/en-us/library/ms748821(v=vs.85).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
In the visual editor you can create buttons and add Click events to them, this is basic so I won't tell you how to do it. Google if you can't.
var options = document.getElementsByClassName("options");
var optionsSetOne = document.getByClassName('optionsSetOne');
This will select all your options. Now that you have all your options selected and in a variable called options you can play around with the visibility, as the user progresses thought the buttons.
First I would set all my options to hidden with:
options.style.visibility = 'hidden';
After the users progresses and clicks the button, I will make the first set of the options visible. With:
$('#buttonOne').click(function(){
optionsSetOne.style.visibility = 'visible';
});
This is the basic workflow of what you want to accomplish, you have to figure out how to save all the information the user gives to you.
I'm trying to make a loading screen with messageboxes, but you have to click the OK button... which I don't think anyone likes.
I want to make a program that will open the messagebox then wait for about 1 or 2 seconds, then open the next one and keep doing it until the loading is complete, here's the code I have so far.
Dim result = MessageBox.Show("Loading.", "Loading Form", MessageBoxButtons.OK)
If result = DialogResult.OK Then
MessageBox.Show("Loading..", "Loading Form", MessageBoxButtons.OK)
If result = DialogResult.OK Then
MessageBox.Show("Loading...", "Loading Form", MessageBoxButtons.OK)
If result = Windows.Forms.DialogResult.OK Then
MessageBox.Show("Loading Complete.", "Loading Complete", MessageBoxButtons.OK)
End If
End If
End If
Anyone have a solution?
If the message box is just a way of letting users know where the process is, it's best to just give them a progress bar or update a label on the form with your message. In addition, turn on the hour glass so users know that the program is still executing.
I'm getting runtime error when I enter alphabets in the inputbox
Dim amount As String
amount = InputBox("Enter the amount of people you want to participtate", "System Message")
If amount < 0 Or Not (IsNumeric(amount)) Then
MsgBox("Please enter positive number of people", vbExclamation, "System Message")
End If
Comparing strings to numbers is pretty dangerous and blew up in your face. You can make it work but you'll have to code is carefully, ensuring that you never try to compare a string that can't be converted to a number. That requires using another operator:
If Not IsNumeric(amount) OrElse amount < 0 Then
MsgBox("Please enter positive number of people", vbExclamation, "System Message")
End If
Note the changed order and the use of OrElse, the short-circuiting version of Or. It won't evaluate the right-hand side expression if the left-hand side is already True.
The more .NET centric way to do this is by using Integer.TryParse() to convert strings to numbers.
To avoid an error, you can make it like this ..
If IsNumeric(amount) Then
If value(amount) > 0 Then
'codes here
Else
MsgBox("Please enter positive number of people", vbExclamation, "System Message")
End If
Else
MsgBox("Please enter a number of people", vbExclamation, "System Message")
End If
So I was looking at validating a textbox, first I wanted to make sure that it was not empty and make sure that it was a number. I'm by no means an expert but I'll put the code I wrote to validate the user input. I put it in a function because I had a lot of text fields that the user had to enter.
Class MainWindow
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
tb2.Text = tbCheck(tb1)
End Sub
Private Function tbCheck(ByRef tb As TextBox) As Boolean
tbCheck = tb.Text.Length > 0
Try
tbCheck = (tb.Text / 1) > 0
Catch ex As Exception
tbCheck = False
End Try
Return tbCheck
End Function
End Class
This is just the simple program I wrote to check if the code worked as I had hoped.
Hope this can help someone or at least tell me if there is something I'm missing.
I have a simple program to average ten (user-defined) numbers and then print the result. At the end of the program I'd like to print Would you like to average a new set of numbers? (Y/N) If the user inputs y than I want the program to execute again from the top. If the user inputs n than the program should close. I've tried researching this, but only found ways to have the entire console exit and re-open which is not what I want.
To detect what the user has entered you have a couple options:
Console.ReadKey()
will read the next keystroke. You can then use a simple Select Case branch to choose what to do.
You can also use:
Console.ReadLine()
which will return a string (after the user presses enter). You can then use a simple If statement to determine what's in the string (and repeat the query if something other than "y" or "n" was entered.)
Example:
Shared Sub Main()
While True
AverageNums()
Console.WriteLine( "Do you want to run again? (Y/N)" )
Dim key = Console.ReadKey()
If key.Key = ConsoleKey.N Then
Exit While
End If
End While
End Sub
Shared Sub AverageNums()
' ...
End Sub
My response may be a little late in the game, but thought I'd share a compact version implementing a try-catch method.
Sub Main()
Do
Try
Console.Write("Enter a value: ")
Console.ReadLine()
'...
SomeProcedure()
Catch ex As Exception
Console.WriteLine(ex.ToString)
Finally
Console.Write("Enter another value? (N for No) ")
End Try
Loop Until Console.ReadLine() = "N"
End Sub
Sub SomeProcedure()
'...
End Sub