Console application - first Message Box is not focused - vb.net

I am in the process of developing a VB.Net console app to get ID & password from users and should pop a message when invalid ID or password is entered, but I am stuck with a peculiar behavior observed while using Message box in console app. When the first message box is shown, its Out-Of-Focus & we explicitly need to bring the message box to focus. But the next subsequent message boxes are In-Focus.
Below is just the sample code.
Sub Main()
Start:
Console.WriteLine("Press Enter")
Console.ReadLine()
MsgBox("Good Day")
GoTo Start
End Sub
Just want to know why such thing is happening & what should be done so the first message box also will be In-Focus.?

You can use the MessageBoxOptions.ServiceNotification to show the dialog on top.
This is converted from a C# application, so not exactly sure if this is correct VB.NET (it should be though):
MsgBox( "Good Day"
, ""
, MessageBoxButtons.OK
, MessageBoxIcon.Asterisk
, MessageBoxDefaultButton.Button1
, MessageBoxOptions.ServiceNotification
)
But note this:
You shouldn't use a MessageBox inside a Console application. These are just two different worlds.
To explain why:
What do you expect when you run this application remotely using the console? There is no way to show that messagebox then. Use Console.WriteLine, but with different coloring if you want to show something is in error, or a warning, or something good.

Related

SAP status message error captured to automatically close

I am new SAP GUI scripting. I have a question regarding to how to stop SAP GUI script running if there's any status messages captured.
I recently create SAP GUI script recording and Excel macro for automation, so far, everything works very well if there's any data collected. However if there's no data collected and will have status bar then the script will become error.
So I tried to find a way to create some code if the status error show up, the script will automatically close, but seems like I only can make it work if the error is only for "No items selected (see long text)". However there are also other few status error will shown up as well, so I'm thinking to make the status bar captured the whole error if possible.
Hopefully you guys can help me regarding this in SAP GUI scripting,
thanks.
If session.findById("wnd[0]/sbar").Text = "No items selected (see long text)" Then
Exit Sub
End If
You can check for the messagetype of the status bar. If it is E then you've got an error.
Instead checking for the text like in your code you check for the messagetype
If session.findById("wnd[0]/sbar").MessageType= "E" Then
' Whatever code is needed here
Exit Sub
End If

VB.net app will only run as Administrator only

I made a few improvements to code that has been functioning without issues. On the development, the app runs with a problem. Installed on a test computer and it does not run unless I right click and run as administrator. The below code is where gets not running as Administrator.
The for loop is adding file names to a list. Administrator the program just ends no errors just quits. i counter gets to 3 of a total of 6 files. Never gets through to post the message "Did it make it here". But does post the message inside the for loop. i counts to 3. If run as admin then no issues. All file names are short and basic with no special characters. The files locations is Application.CommonAppDataPath. The loop is called from Form load.
Hoping someone could tell me what is going on.
Try
Selected_Machine = XMLReadSetting("Machine", "Selected", "Selexx")
For i = 0 To UBound(files)
MessageBox.Show("Here 2 i " & i & " File Name" & files(i))
cboMachine.Items.Add(IO.Path.GetFileNameWithoutExtension(files(i)))
If Selected_Machine = IO.Path.GetFileNameWithoutExtension(files(i)) Then
cboMachine.SelectedItem = IO.Path.GetFileNameWithoutExtension(files(i))
End If
Next
Catch err As SyntaxErrorException
MessageBox.Show(err.Message)
End Try
MessageBox.Show("Did it make it here?")
Found the issue. Inside the for loop it make a change that calls the text changed event of the list box. In the text changed event I write data to a settings file. The settings file did not have write access. Not sure how that happend but problem solved
Thank you all for the help.

How to declare a public variable for a specified user login?

I have a login system that works well, using XML files to store logins, and then I can read the users and passwords, see if it matches, if it does, move to the next form, if it doesn't, error message.
However, when the form switches over, I want to be able to display the username in the to left corner, so the user knows who they are displayed as. But I don't know how to memorise the specific user that logged in on the previous form onto the new form now?
I tried making a "public variable" (sort of hard to do for me, not sure if i even did it right), which will read the textbok that the user inputs their name in if the username was correct, and gets dipaslayed for the next form. I don't thin the public vairable worked very well.
If BlnUserFound = True Then
'ActiveUser is the "public vairable"
ActiveUser = tbxUser.Text
'Open the main screen
Me.Hide()
Home.Show()
Else
MessageBox.Show("User Details Not found" & vbCrLf _
& "Please Try Again", "Login Error")
End If
What am I doing wrong?!
Just simply connect it to another new variable name and use it in form 2 e.g
dim ActiveUser2 as string
ActiveUser2 = Form1.ActiveUser then just simply easiest way would be have a label or something on your form, set it to not visible and then just apply ActiveUser2.text to the Label.Text

Creating a error box that makes the program wait for an input

If my program has a text box empty in the search field it will still run all the way through and complete its process. I want an error box to pop up stating an value must be put in and pause the program until a value is put in.
This is what i started with i just don't know how to pause the program.
If TextBox1.Text = "" Then
Form4.Show()
End If
I have my form 4 show options, solutions, etc. . .
If TextBox1.Text = "" Then
Form4.ShowDialog()
Exit Sub
End If

Visual Basic .NET Dynamic updating Textbox

I just started to study Visual Basic .NET. I would like to build a dynamic system log text box.
When program is passing one point of code or function, a textbox in another form is updating with the system log.
For example, when the program starts, it appends "System start" to the textbox in another form. When the program starts to use the "cal" function, then the program appends "System: start to cal data" on the textbox in another form.
However, I am not really sure how to update this system log dynamically. Do I need to use threading? Can I do it without threading? Can anyone give me an example?
To add to Mertis's suggestion, what you can do is to fire a code which concatenates details to your textbox whenever an object is called/code is executed
for example, a function was executed:
Function sampleFunc()
.....
Textbox1.text = Textbox1.Text & vbnewline & DateTime.Now & _
" a Function was Executed"
End Function
Note that I added a datetimenow, in case you needed time details.