How to make a MessageBox wait in VB.net - vb.net

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.

Related

How to link TextBox data and DataGridView and save it in the MS Access database

I'm new to programming and I'm trying to make a simple information system. I've tried many codes and I think this is the easiest but it won't save the data. Please point out what I need to do. Thanks in advance.
Here is my code (for the save button):
If Len(Trim(txtStudentID.Text)) = 0 then
MessageBox.Show ("Please input data",MessageBoxButtons.OK,MessageBoxIcon.Error)
txtStudentID.Focus()
Exit Sub
End If
Try
GeneralInformationBindingSource.EndEdit()
GeneralInformationTableAdapter.Update(PayrollDatabaseSet.GeneralInformation)
MessageBox.Show (" Data Saved")
Catch ex As Exception
MessageBox.Show ("Error while Saving Data")
End Try

Disabling menu items using other winform (vb.net)

Hi I have a problem with my code: I have two windows form Menu and Login. I set Menu as MdiParent.
So this is what it looks like.
My problem is when I log in as Clerk I want User Account to be disbled. My code in Login Form is this:
If myReader.Read Then
MsgBox("Log-in Successfully", vbInformation, "Log-in")
If cmbtype.Text = "Clerk" Then
Menu.useracc.Enabled = False 'but i got an error here
Else
Menu.useracc.Enabled = True 'same as here
End If
Me.Close()
clear()
Else
MsgBox("Username and Password do not match. Please check and log-in again.", vbCritical, "Log-in Failed")
End If
What would be the right code to disable menu item from my Menu Form when Login Form closes.

Timer runs automatically on a MsgBox vb.net

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?

How can I click a javascript button in a webbrowser that the code to does not show up to in the webpage source?

Visit this site:
https://satoshimines.com/
Click play, place a bet of 0 and click play
Now here's what I find interesting, if you view the source of the page there's no code shown for the Game Board. I think one of the JavaScripts its calling upon is the board game. In inspect element you can see the elements for the board game
http://prntscr.com/78ge73
So, my question is it possible to click one of the game tiles if the site is loaded in a webbrowser inside VB? If so, please point me in the right direction.
Here's how I tried to click it. (Doesn't work.)
Private Sub Clicktile()
TextBox2.Text = TextBox2.Text + "Trying to click Tile..." + Environment.NewLine
'Try statement so if it dicks up the program won't crash
Try
'Declares in Memory the page source as a HtmlElementCollection
Dim ae As HtmlElementCollection = WebBrowser1.Document.All
'Declares in Memory each Element within the page source
For Each wpe As HtmlElement In ae
If wpe.GetAttribute("data-tile") = "1" Then
wpe.InvokeMember("click")
Else
TextBox2.Text = TextBox2.Text + "Error on ClickTile1" + Environment.NewLine
End If
Next
Catch ex As Exception
TextBox2.Text = TextBox2.Text + "Catch ex As Exception called" + Environment.NewLine
End Try
End Sub
Ahhhhh! You're trying to cheat! (or trying to SPAM)
When you click on tile, webpage send XMLHTTPRequest to get answer status. So you can't see what is under button before you click it!

Is there a difference between MsgBox and MessageBox.Show?

Is there a difference between the following two?
msgbox()
messagebox.show()
Some tutorials use msgbox(), and some use the other, messagebox.show()---I see that both can have an editable style, but I was wondering: Why are there two?
Is it to accommodate older programmers (who have learnt on an older version of Visual Basic)?
So in that case, which one should I use in Visual Basic 2010 (Visual Studio 2010)?
MsgBox() is the same as Messagebox.Show().
It exists for VB6 programmers who are used to it.
There are no rules on which one to use, but since MsgBox simply ends up delegating to MessageBox, I personally would go directly with MessageBox.
Here is the source code for Msgbox. As you can see it doesn't do anything particularly interesting before calling MessageBox.Show.
<MethodImpl(MethodImplOptions.NoInlining), HostProtection(SecurityAction.LinkDemand, Resources:=HostProtectionResource.UI)> _
Public Shared Function MsgBox(ByVal Prompt As Object, ByVal Optional Buttons As MsgBoxStyle = 0, ByVal Optional Title As Object = new Object()) As MsgBoxResult
Dim owner As IWin32Window = Nothing
Dim text As String = Nothing
Dim titleFromAssembly As String
Dim vBHost As IVbHost = HostServices.VBHost
If (Not vBHost Is Nothing) Then
owner = vBHost.GetParentWindow
End If
If ((((Buttons And 15) > MsgBoxStyle.RetryCancel) OrElse ((Buttons And 240) > MsgBoxStyle.Information)) OrElse ((Buttons And &HF00) > MsgBoxStyle.DefaultButton3)) Then
Buttons = MsgBoxStyle.OkOnly
End If
Try
If (Not Prompt Is Nothing) Then
[text] = CStr(Conversions.ChangeType(Prompt, GetType(String)))
End If
Catch exception As StackOverflowException
Throw exception
Catch exception2 As OutOfMemoryException
Throw exception2
Catch exception3 As ThreadAbortException
Throw exception3
Catch exception9 As Exception
Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValueType2", New String() { "Prompt", "String" }))
End Try
Try
If (Title Is Nothing) Then
If (vBHost Is Nothing) Then
titleFromAssembly = Interaction.GetTitleFromAssembly(Assembly.GetCallingAssembly)
Else
titleFromAssembly = vBHost.GetWindowTitle
End If
Else
titleFromAssembly = Conversions.ToString(Title)
End If
Catch exception4 As StackOverflowException
Throw exception4
Catch exception5 As OutOfMemoryException
Throw exception5
Catch exception6 As ThreadAbortException
Throw exception6
Catch exception13 As Exception
Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValueType2", New String() { "Title", "String" }))
End Try
Return DirectCast(MessageBox.Show(owner, [text], titleFromAssembly, (DirectCast(Buttons, MessageBoxButtons) And DirectCast(15, MessageBoxButtons)), (DirectCast(Buttons, MessageBoxIcon) And DirectCast(240, MessageBoxIcon)), (DirectCast(Buttons, MessageBoxDefaultButton) And DirectCast(&HF00, MessageBoxDefaultButton)), (DirectCast(Buttons, MessageBoxOptions) And DirectCast(-4096, MessageBoxOptions))), MsgBoxResult)
End Function
There is a difference when you are attempting to mix icons with different buttons. MsgBox has predefined styles (there may be a way to create new styles).
For example:
MsgBox("Do you wish to save changes?", MsgBoxStyle.YesNoCancel, "Save Changes")
^ This will display a box with Yes, No and Cancel buttons without an icon.
MsgBox("Do you wish to save changes?", MsgBoxStyle.Question, "Save Changes")
^ This will display a box with a Question mark icon but with ONLY an OK button.
MessageBox.Show("Do you wish to save changes?", "Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
^ This will display a box with Yes, No and Cancel buttons AND a Question mark icon.
As you can see, using MessageBox.Show enables you to have any buttons you want with any icon.
But the really nice thing about MsgBox is that it can be SystemModal e.g. If MsgBox("There is a new Quick Message!" & Environment.NewLine & "Do you want to read it now?", MsgBoxStyle.Information + MsgBoxStyle.YesNo + MsgBoxStyle.SystemModal, "Quick Message") = MsgBoxResult.Yes Then...
I couldn't find a simple way of making If MessageBox.Show(... to be SystemModal.
My messages now get full prominence on screen. Yippee.
According to this site and the answers so far to my own question (see remark), as well my inability to display a specific help file using the msgbox function, I'd have to say use messagebox rather than msgbox if you want to show help. The msgbox function displays a help button, but apparently there is no way to put a helpfile in it! I'm showing the code I played around with below, and there is also a good code sample on the first link.
Imports Microsoft.visualbasic 'have to have this namespace to use msgbox
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Helpfilepath As String = "C:\Windows\Help\mui\0409\aclui.chm"
Dim msgresult As Byte
'BTW, Must use 0 for BLANK PARAMETER. Using messageboxoptions.defaultdesktoponly errors out with help btn.
msgresult = MessageBox.Show("Text", "Messagebox", 0, _
0, 0, 0, Helpfilepath)
'displays help button, but how do you display the help file?
msgresult = MsgBox("Text", MsgBoxStyle.MsgBoxHelp, "msgbox")
'BTW, must use dialogresult rather than messageboxresult with windows forms
If msgresult = DialogResult.Yes Then
'etc
End If
End Sub
End Class
The message box created using MsgBox() has a title of the form which created it, whereas the message box window created by MessageBox.Show() does not have any title.