You have tried to assign the MsgBox and are not using the method’s return value.
MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)
Would be displaying the message box to your user, this method returns a MsgBoxResult object which you should use, as shown below.
Dim delete = MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)
If delete = MsgBoxResult.Yes Then
'Your logic
End If
Alternative you can just add an If statement and do:
If MsgBox("Do you really wish to delete?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
End If
As an additional note the MsgBox function appears to be outdated, you should try and use MessageBox.Show.
Dim delete = MessageBox.Show("Should this item be deleted", "Form Title", MessageBoxButtons.YesNo)
If delete = DialogResult.Yes Then
End If
- Remove From My Forums
-
Question
-
I have a problem in VB.Net with the msgbox function. When it runs, it does not always display. Sometimes it just pops onto the taskbar, but and I have to click it to get it to display. The msgbox is coded as follows:
Dim Reply As Integer
Dim style As MsgBoxStyle
style = MsgBoxStyle.YesNo Or MsgBoxStyle.Question Or MsgBoxStyle.DefaultButton2
Reply = MsgBox(«You have made changes to this record, do want to save them?», style, «Cancel»)If Reply = vbYes Then
SaveRecord()
End IfThis is a Web based project
Answers
-
Bill
I know you can put the msgbox in and it will display a messagebox but what was being said was that this will not occur on the client machine but on the server. So what will happen is that you application will halt until someone on the server machine clicks the msgbox.
This may not be an issue when you developing and you Server and Development Machine/Client are the same but when you deploy on IIS — it will be a problem as the msgbox wont occur on the client machine viewing you web page — it will occur on the IIS machine.
This is why using msgbox wont work. But there is nothing to stop you physically using it.
This is the important part:
Inherits System.Web.UI.Page
The VB.Net you know so well is for Windows Forms. What we have here is an ASP.Net WebForms page. You can’t use MsgBox() in a web page, because raw HTML doesn’t have a direct match.
Okay, you can with the right tweaks, but it won’t work the way you want — the message will show in a special private desktop on the server, where it blocks the request until the thread times out, and the end user will never see it. It might sometimes seem to work the way you want, but this is only in your development environment, where the web server and client browser are on the same machine. The closest you can get in the real world is registering a javascript function to run at DOM startup to call alert(), and that’s just nowhere near as nice.
This is just one of many differences between the Web Forms and WinForms platforms. Web Forms is intended to make it easier for developers to transition from the WinForms world to web development, but it’s still a whole new platform, based of necessity on the HTTP Request/Response model. It still requires significant study to learn well, just like any other platform.
So when building a web page, you need to think in terms of creating an HTML element to show your message. It’s important to remember that any VB.Net event code you write runs on the web server, only after sending a new request to the server that completely re-starts the page lifecyle, and far away from the end user; never in the user’s web browser. This can be very frustrating at first, because you’ll tend to know VB.Net and the WinForms APIs fairly well, compared to javascript and company hardly at all. But it does get easier with time.
But in this case, you’re really only using MsgBox() to output debugging information. What you can do instead here is use the System.Diagnostics.Trace class. Trace will let you put the messages right into the Visual Studio output window… or a file, or a database, or the console, or wherever you want to see them.
|
0 / 0 / 0 Регистрация: 07.01.2016 Сообщений: 63 |
|
|
1 |
|
|
04.08.2022, 06:32. Показов 1024. Ответов 14
Помогите исправить ошибку: Ошибка BC30451 «MsgBox» не объявлена. Возможно, она недоступна из-за своего уровня защиты. Появилась в VS2017.
0 |
|
bite 3745 / 3248 / 709 Регистрация: 13.04.2015 Сообщений: 7,558 |
|
|
04.08.2022, 08:26 |
2 |
|
«MsgBox» не объявлена Не может быть. Можно взглянуть на скриншот кода и ошибки?
0 |
|
MihailAk 0 / 0 / 0 Регистрация: 07.01.2016 Сообщений: 63 |
||||
|
04.08.2022, 08:30 [ТС] |
3 |
|||
|
Не может быть. Можно взглянуть на скриншот кода и ошибки? Нашел метод исправления. Но все равно глючит, выдает ошибку
0 |
|
bite 3745 / 3248 / 709 Регистрация: 13.04.2015 Сообщений: 7,558 |
|
|
04.08.2022, 08:34 |
4 |
|
Нашел метод исправления Это костыль.
0 |
|
bite 3745 / 3248 / 709 Регистрация: 13.04.2015 Сообщений: 7,558 |
|
|
04.08.2022, 08:38 |
5 |
|
Появилась в VS2017
0 |
|
0 / 0 / 0 Регистрация: 07.01.2016 Сообщений: 63 |
|
|
04.08.2022, 08:46 [ТС] |
6 |
|
А как это можно настроить?
0 |
|
bite 3745 / 3248 / 709 Регистрация: 13.04.2015 Сообщений: 7,558 |
|
|
04.08.2022, 08:51 |
7 |
|
А как это можно настроить? Да не надо это настраивать. Оно само работает, пока не сломаешь. Поэтому я и просил скрин, чтобы посмотреть где ты накосячил.
0 |
|
0 / 0 / 0 Регистрация: 07.01.2016 Сообщений: 63 |
|
|
04.08.2022, 08:55 [ТС] |
8 |
|
Это скрин Миниатюры
0 |
|
bite 3745 / 3248 / 709 Регистрация: 13.04.2015 Сообщений: 7,558 |
|
|
04.08.2022, 08:56 |
9 |
|
MihailAk, а самый верх, где импорты и наследования?
0 |
|
MihailAk 0 / 0 / 0 Регистрация: 07.01.2016 Сообщений: 63 |
||||
|
04.08.2022, 08:59 [ТС] |
10 |
|||
|
У меня есть вот такой модуль для общих переменных:
0 |
|
bite 3745 / 3248 / 709 Регистрация: 13.04.2015 Сообщений: 7,558 |
|
|
04.08.2022, 08:59 |
11 |
|
MihailAk, если не можешь разобраться, то используй тогда вместо MsgBox MessageBox.Show
0 |
|
0 / 0 / 0 Регистрация: 07.01.2016 Сообщений: 63 |
|
|
04.08.2022, 09:02 [ТС] |
12 |
|
Ок. Только это длинное название. Бюрократизмом попахивает для такой простой задачи!
0 |
|
bite 3745 / 3248 / 709 Регистрация: 13.04.2015 Сообщений: 7,558 |
|
|
04.08.2022, 09:03 |
13 |
|
Бюрократизмом попахивает для такой простой задачи! Это из Framework-a, а MsgBox из старого Барсика.
0 |
|
0 / 0 / 0 Регистрация: 07.01.2016 Сообщений: 63 |
|
|
04.08.2022, 09:05 [ТС] |
14 |
|
Это из Framework-a, а MsgBox из старого Барсика. А как Барсик подключить к проекту?
0 |
|
bite 3745 / 3248 / 709 Регистрация: 13.04.2015 Сообщений: 7,558 |
|
|
04.08.2022, 10:14 |
15 |
|
Решение
А как Барсик подключить к проекту? MsgBox должен работать «из коробки», ты что-то сломал. Добавлено через 1 час 4 минуты
1 |
|
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
04.08.2022, 10:14 |
|
15 |
|
|


Сообщение было отмечено MihailAk как решение




