'Sub Main' was not found in, BC30420 VS 2022 17.2.5 - vb.net

I can't change the "Startup object" it only shows "Sub Main" in the list without anything else, what happened is that I initially changed "Form1" name to "FormLogin",I changed the form name twice:
First I Rename from "Design>Name" from "form1" to "FormLogin"
Then I Rename the file name with Click-Right>Rename from "form1.vb"
to "FormLogin.vb"
And made additions inside the form and the program worked fine, and then I decided to add another form After I added it and added modifications to it, I wanted to test them, so I went to Properties in order to modify it to the other form, but suddenly I saw the "Startup object" changed instantly from "Form1" to "Sub Main" and I can't modify it

After a few hours of searching, it seems that it is a defect:
https://developercommunity.visualstudio.com/t/Visual-Studio-doesnt-permit-to-change-s/10049115
https://developercommunity.visualstudio.com/t/Startup-Form-Dropdown-List-Not-Populated/10049171
As a workaround which worked for me. Create a Shared Sub Main and add the below code, with the Form you would like to run.
Program.vb
Public Class Program
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New [Form])
End Sub
End Class
Update
Updating VS2022 to Version 17.3.6 fixed the issue, now all Forms appear in the drop-down list Startup Project.

Related

Document_Open() event does not fire on every computer

I have a Word which is used for form filling. The users are filling what is asked and some macros runs depending on what they chose or where they click. This works fine.
I recently decided to make a newer version which countains some ComboBox that are filled when the document is opened. To do that, I used the Document_Open() event.
Now here is the part I don't get : On my side, every time I do open the document, the event is triggered and the ComboBox that should get filled are filled. The problem is, so far I asked some people to test it on their own computer with their Word. Both of them came back to me saying that the ComboBox weren't filled when the document was openned.
To be more specific let's go in the code itself :
In ThisDocument, I have multiple subs that works perfectly fine and this Document_Open() event which gives me trouble.
Private Sub Document_Open()
Application.Run ("Fill.ComboBox")
End Sub
Here, Fill is the name of the Module which contains :
Sub ComboBox()
'Calling another Sub in this Module which adds the Items in the ComboBoxes
'from what parameters it is given
End Sub
Now that this has been stated, why would it work on my side but not work when another user tries it from their computer ?
Miscorsoft Word Versions :
I myself use Microsoft Office Profesionnal 2013 and so are the two users that tested it. That being said, this is intended to be working on any Word liscense from 2007 up to the current versions.
You can try in a module in your document:
Public Sub AutoOpen()
ComboBox
End Sub
I just used this in a Word 2016 document to automagically run a macro.
For documentation: https://support.microsoft.com/en-us/help/286310/description-of-behaviors-of-autoexec-and-autoopen-macros-in-word

Visual Studio 2013: Cannot update textbox with event handler

I am building an application using one of our vendors interfaces, which is required to keep a status message box updated.
I have some events which I have handled for testing using a Message box, but now I come to pass these messages to the display box I get nothing.
Public Shared Sub PageAirHandler(ChannelNum As Integer, Index As Integer, ChannelType As CLARITYCOMLib.ChannelType, PageName As String) Handles Status1.AirStatusChanged
MessageBox.Show(PageName)
ControlPanel.AirStatusBox.Text = PageName
End Sub
The messagebox dutifully displays the PageName string, but the textbox does nothing... even if I replace the PageName String variable with "test"
ControlPanel.AirStatusBox.Text = "test"
I get no activity, no errors, nada.
I have googled around, but every example I can find seems to show the same code.
I have recreated the textbox, tried buttons, labels and other objects with the same result.
Setting up a button click handler to update any of these works as expected.
Apologies if this is a noob blunder, but it's driving me nuts!
Using dlg As New Form2
dlg.ShowDialog()
End Using
Things like:
Form2.Show()
Form2.Show(Me)
Form2.ShowDialog()
Form2.ShowDialog(Me)
SHOUL BE AVOIDED but are possible, because Vb.net creates an implicit instance.
But the problem is, this instance gets killed if
the call has be done.
There you can see that a class instance of a project does not interact correctly
in some cases.
As Hans Passant said, your call to set the textbox text
targets the wrong instance.
Invoking to user controls is also possible with:
Me.invoke(sub()
TextBox1.Text = "Blabla"
End sub)

visual basic error BC30456 'Form1' is not a member of 'WindowsApplication1'

Hello I am trying to do an exercise and keep getting this error when compiling.
Visual Basic error BC30456 'Form1' is not a member of 'WindowsApplication1'
I'm not sure how to fix it.
Below is my code:
Public Class frmCentsConverter
Private Sub txtAmount_TextChanged(sender As Object, e As EventArgs) Handles txtAmount.TextChanged
If IsNumeric(txtAmount.Text) Then
Dim NumberofCents As Integer
NumberofCents = CInt(txtAmount.Text)
lblDollars.Text = CStr(NumberofCents \ 100)
lblCents.Text = CStr(NumberofCents Mod 100)
End If
End Sub
Private Sub lblTitle_Click(sender As Object, e As EventArgs) Handles lblTitle.Click
End Sub
End Class
If you have renamed the startup form1 it is likely you also have to change the Startup form setting. You can find this setting to open 'My Project' in the 'Solution Explorer'. Select the Application section, change the 'startup form' as appropriate.
Hope this will help, Harrie
To set the startup form in Windows Forms
In Solution Explorer, right-click the project and choose Properties.
The Project property page opens with the Application properties displayed.
Choose the form you want as the startup form from the Startup Object drop-down list.
I got this information from this website:
https://msdn.microsoft.com/library/a2whfskf(v=vs.100).aspx
I can confirm this works on Visual Studio 2015 as well.
Under the tab, Application.Designer.vb
You'll see the following the code:
Me.MainForm = Global.WindowsApplication1.Form1
Change Form1 to your NEW form name.
Example: Changed Form 1 "Hello World" to frmHello
Original:
Me.MainForm = Global.WindowsApplication1.Form1
Change to:
Me.MainForm = Global.WindowsApplication1.frmHello
It could be a bug after form renaming.
Try to change file Application.myapp under Project Folded
<MainForm>Form1</MainForm>
p.s. Application.Designer.vb is created dynamically, so changes there would be overwritten after the next clean build.
This is how I fixed it.
Right click on the Name of your project and then click properties.
Locate the Target framework under the Applications tab.
Change it to ".NET Framework 4.5" (mine was on 4.5.2).
Click/accept/whatever it is to confirm your selection from the popup box.
Build/Rebuild solution.
This worked for me in VB.net 2015.
Good Luck!
I know how to fix it.
If you get this problem, open the error message by clicking the error line until Application.Designer.vb shows up & then find the "Form1" name in that place.
Sample in Application.Designer.vb tab:
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.aplikasi_set_diskumau.Form1
End Sub
I found the "Form1" name in that part of code, just replace that "Form1" with the name of your form.
I managed to solve this by changing to .NET Framework 3.5, clean and rebuild, then change back to 4.8. For some reason it seems 4.8 is not updating Application.Designer.vb properly. By the way, updating that file manually does not work, it will be overwritten in the next build.

Merged projects, how to access public subs in main project

I have VS 2012 with the main project as a Windows form application and an added project as a excel workbook. I have some code that are exactly the same on both projects so I am trying to save time by sharing that code.
From my excel project I added a reference to my windows form project and imported the namespace. I can access the public functions on my main project, but I cannot seem to be able to access my public subs.
I also tried creating a module a adding a link between the projects but that would cause me to also update the code in two places. Besides, I think that creating a link may also cause some issues at deployment.
For example, in my windows form project I have the following I want to access from my second project
Public Sub closeXLApp()
'This sub is called to close the application without
'saving any changes to the workbook. The sub closes
'the app, workbook and sheet and performs some garbage clean up
'as well making sure that the opened Excel instance is cleared from memory.
xlBook.Close(SaveChanges:=False)
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing
GC.Collect()
End Sub
On my second project I created a reference and imported the namespace as:
Imports Compensation_Template_Welcome_Page
So when I try to access the above public sub from my second project as:
Private Sub btnMinCloseProject_Click(sender As Object, e As EventArgs) Handles btnMinCloseProject.Click
'This procedure runs when the btnMinCloseProject is clicked. The
'procedure calls the function to close workbook without saving changes.
closeXLApp()
End Sub
I get an error saying that the sub is not declared or not accessible due to its protection level.
Is there a better way to accomplish this? Even if is a longer route, I just want it to make it efficient in the long run.
Thanks
You're sub closeXLApp() is not static (shared), so you need to create an instance of the class where this sub is containted and then call the sub.

VS 2010 stops responding when opening form designer

I have VisualBasic project wih many forms,and one of it is form1.Whenever the initializecimponent method is called,VS stops responding and i have to end it using taskmgr.The bug is inside the form1.designer.vb, because i am able to view and edit other forms and usercontrols in designer.Anoter strange thing is that the stand alone exe runs successfully outside the IDE.I also tried adding the form to another project and that project too crashes.Whenever i build/debug/view form1 in designer, i get two dialogs one after the other:VS2010 has stopped working, VS2010 is restarting( but it never does!)
Create a copy of the form, and begin removing parts of the form until it works. The last thing you removed is what failed. You'll have to do this manually by removing three parts of each control:
The Declaration (at the bottom)
The instantiation (at the top)
The configuration (in the middle). Below is an example of the configuration
'
'LeftLabel
'
Me.LeftLabel.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.LeftLabel.AutoSize = True
Me.LeftLabel.Location = New System.Drawing.Point(3, 3)
Me.LeftLabel.Name = "LeftLabel"
Me.LeftLabel.Size = New System.Drawing.Size(39, 13)
Me.LeftLabel.TabIndex = 1
Me.LeftLabel.Text = "Label2"
You'll also need to remove any references to that control, such as it being added to a container.
Do this one control at a time, then build the project and open the form. If the form does NOT open, restart visual studio and do the next control. if it DOES open, then the last thing you removed was the culprit.
For programmers facing the same problem, here is the solution:
Make sure that your user controls doesn't creates instances of themselves inside themselves.even though your program might run without any error, VS designer will crash.here is an example for such kind of code:
Public class controlx
public sub new()
dim x as new controlx
End sub
End class
you might think its a silly logical error, but such errors can be very much frustrating and time consuming.always breakdown your code to smaller units so that its manageable as Brian said.