Results 1 to 21 of 21

Thread: [RESOLVED] Problems displaying forms

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2023
    Location
    Montagna in Valtellina - Sondrio - Italia
    Posts
    15

    Resolved [RESOLVED] Problems displaying forms

    Language: VB
    Version: VB.net; Framework 6.0 Vers.VS: 17.6.2
    No database
    It's a game
    Not an Office application
    Windows desktop application

    I'm new to the forum. I worked for some time in VB6, abandoned a few years ago and, after several years I resume with VB.net, but I encountered several difficulties regarding the evolution of language. I will recover.
    But I ask for help with a different problem: I can't use a project with two forms because, even though I'm allowed to create, rename, and edit the various forms, I can't make a call because the form isn't recognized.
    During the .show() call, the name of the called form is not recognized, whether it is renamed or not, and the error message states:
    Code BC30456 "Form1" is not a member of "FormProva" (project name). I tried to uninstall and reinstall Visual Studio several times, but always with the same result even on a newly created project.
    Is it possible that some configuration (inadvertently made) could create this? If so, can I do a reinstall from scratch?
    Is it possible to insert explanatory images?

    Can anyone help me? Thanks to those who wish to intervene.
    Vic.
    Last edited by jmcilhinney; May 30th, 2023 at 01:39 AM. Reason: Translated to English

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problemi con la visualizzazione di form

    Two observations...

    99% of members in this forum won't speak Italian.
    Is that a VB6 question? If yes, you're asking in the wrong forum...

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problemi con la visualizzazione di form

    Google translate says...

    Language: VB
    Version: VB.net; Framework 6.0 Ver.VS: 17.6.2
    No databases
    It's a game
    It is not an Office application
    Windows desktop application

    I'm new to the forum. I worked for some time in VB6, abandoned a few years ago and, after several years I resumed with VB.net, but I encountered various difficulties regarding the evolution of the language. I will recover.
    But I'm asking for help with a different problem: I can't use a project with two forms because, even though I'm allowed to create, rename and modify the various forms, I can't make a call because the form isn't recognized.
    When calling .show(), the name of the called form is not recognized, whether it is renamed or not, and the error message reads:
    Code BC30456 “Form1” is not a member of “FormTest” (project name). I've tried uninstalling and reinstalling visual studio several times but still with the same result even on a newly created project.
    Is it possible that some configuration (inadvertently made) could create this? If so, can I do a fresh reinstall?
    Is it possible to insert explanatory images?

    Can anyone help me? Thanks to anyone who would like to participate.
    Vic.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2023
    Location
    Montagna in Valtellina - Sondrio - Italia
    Posts
    15

    Re: Problemi con la visualizzazione di form

    Quote Originally Posted by .paul. View Post
    Two observations...

    99% of members in this forum won't speak Italian.
    Is that a VB6 question? If yes, you're asking in the wrong forum...
    Thank you for your intervention Paul.
    I'm new to the environment so, if you want, I ask you some clarifications.
    Meanwhile, at the top of the request was defined environment and some details. Of course, I'm talking about VB.net, the introduction tended to apologize for the elementary requests (I think).
    The problems highlighted relate to a project in VB version 17.6.2.
    If you want you can give me some tips.
    Regarding the fact that the users are almost not totally Italian-speaking, I can't understand what that means.

    Thank you for your time,
    Vic.
    Last edited by jmcilhinney; May 30th, 2023 at 01:40 AM. Reason: Translated to English

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Problems displaying forms

    This site only accepts posts in English. I have translated your thread title and your posts to English for you. Please make all future posts in English only. Any further non-English posts will be deleted.

    Questo sito accetta solo post in inglese. Ho tradotto il titolo della tua discussione e i tuoi post in inglese per te. Si prega di fare tutti i post futuri solo in inglese. Eventuali ulteriori post non in inglese verranno eliminati.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Problems displaying forms

    Please show us the exact code you're trying to use. Where exactly is this code located? My guess is that you are trying to use the default instance. That should generally work but there can be cases where it won't and it's not really advisable anyway. It can make certain things a bit easier, but it's not hard to do without them altogether. You should treat forms like any other objects, e.g.
    vb.net Code:
    1. Dim f1 As New Form1
    2.  
    3. f1.Show()

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2023
    Location
    Montagna in Valtellina - Sondrio - Italia
    Posts
    15

    Re: Problems displaying forms

    Thank you for the information provided. I apologise for the language, but I read the initial instructions for posting a message and evidently I did not see the rule on the use of language. I also thank you for your support and courtesy.

    I did some tests before sending you the offending code and I found that everything works normally if the forms involved are not renamed. In fact, the second form opens on the action of Button1, but if one (or all) of the forms are renamed, this no longer works.

    The first form contains a Button and a TextBox, the second only a Label.
    However, this is the code obtained as soon as the new project is created, immediately the Button and the TextBox are inserted; in the second form a Label is inserted. No other action is performed. At this point the code is as follows:
    Code:
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Form2.Show()
            Form2.Label1.Text = Me.TextBox1.Text
            Me.Hide()
        End Sub
    
    End Class
    Changing Form2.vp to App1.vp and if I change the name of form2 to 'frmApp1' no longer recognises the form from the Form1 call; and the code like this:
    Code:
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            frmApp1.Show()
            frmApp1.Label1.Text = Me.TextBox1.Text
            Me.Hide()
        End Sub
    End Class
    Everything works.

    I tried your previous suggestion:
    Code:
    Public Class Form1
        Dim F1 As New Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            F1.Show()
            Me.Close()
        End Sub
    End Class
    but the system responds:

    System.StackOverflowException: 'Exception_WasThrown'

    Thanks again for your attention, I hope you have a few moments to take an interest in the problem.
    See you soon, Vic.
    Last edited by Shaggy Hiker; May 30th, 2023 at 02:35 PM. Reason: Added CODE tags.

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Problems displaying forms

    Changing Form2.vp to App1.vp and if I change the name of form2 to 'frmApp1'
    Yeah, I think this is the issue ... HOW did you rename the form? I suspect what you renamed was the name of hte FILE, not the form itself... renaming one doesn't necessarily change the other. there is a way to do it all in one go... and it'll even search the code and update teh referenced form ...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Problems displaying forms

    There may be another issue, which I was going to write about, but after seeing what TG wrote, I think he's right.

    The other issue is that you are using default instances. This is all that was typically used in VB6, but it's not a good idea in .NET.

    Every form allows for a default instance as long as it has a constructor that takes no arguments. The default instance is quietly created the first time it is used, and acts like this:

    Public FormName As New FormName

    In other words, it is an instance of the form that has the same name as the form. Some of the consequences of this can surprise people. For one thing, they may end up creating a different instance and then try to reference it through the default instance without realizing that the two are totally different forms. Another issue is that the default instance has some special consequences when multi-threading, but since you aren't doing that, it shouldn't matter.

    As a general rule, you shouldn't use default instances unless you know what they are and what consequences arise from using them. In many cases, your startup form will be a default instance and that's usually fine, but any other form, such as the ones you are showing in your code, should not be default instances. Create your own instance and show that, as JMC showed, don't just call Form2.Show, as that will be the default instance.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    New Member
    Join Date
    May 2023
    Location
    Montagna in Valtellina - Sondrio - Italia
    Posts
    15

    Re: Problems displaying forms

    I renamed Form2.vp to App1.vp from Solution Explorer and the Form2 in frmApp1 from Properties.

    I must say, however, that I performed several other identical tests, but did not get the same result. After renaming Form2.vp to App1.vp and Form2 to frmApp1: the form is not recognized as happened before and the code shows the red wavy underline under frmApp1.
    I believe, however, that I have always performed the same operations.

  11. #11

    Thread Starter
    New Member
    Join Date
    May 2023
    Location
    Montagna in Valtellina - Sondrio - Italia
    Posts
    15

    Re: Problems displaying forms

    Thank you for the intervention.
    I must, unfortunately, say that I do not have the tools to totally understand what you are telling me. I started working with VB3 and have continued programming for quite some time using event-driven programming and have not actually made the leap to object-driven programming. This leads me, as I said in the presentation, to have a lot to catch up on.
    The suggestion provided initially in this regard:

    Public Class Form1
    Dim F1 as new Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    F1.Show()
    Me.Close()
    End Sub
    End Class

    did not resolve; system message: system.StackOverflowException

    I tried your suggestions and this is the code:

    Public Class Form1
    Public frmApp1 As New Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    frmApp1.Show()
    Me.Close()
    End Sub
    End Class

    system message on startup remains the same: System.StackOverflowException

    Where do I commit the fatal error?

    Thanks for your time, see you soon, Vic.

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems displaying forms

    Your code is creating a new Form1 in each new instance of Form1, causing infinite creation of new Form1s… Try this, to avoid that

    Code:
    Public Class Form1
        Public frmApp1 As Form1 ‘??? Why are you trying to open a new instance of Form1 from within an existing instance of Form1?
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            FrmApp1 = New Form1
            frmApp1.Show()
            Me.Close()
        End Sub
    End Class

  13. #13

    Thread Starter
    New Member
    Join Date
    May 2023
    Location
    Montagna in Valtellina - Sondrio - Italia
    Posts
    15

    Re: Problems displaying forms

    Quote Originally Posted by .paul. View Post
    Your code is creating a new Form1 in each new instance of Form1, causing infinite creation of new Form1s… Try this, to avoid that

    Code:
    Public Class Form1
        Public frmApp1 As Form1 ‘??? Why are you trying to open a new instance of Form1 from within an existing instance of Form1?
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            FrmApp1 = New Form1
            frmApp1.Show()
            Me.Close()
        End Sub
    End Class
    Thank you .Paul. for your intervention.
    I have tried your suggestion, but I probably make some mistake, because the result of calling the project as it is, results in closing Form1, but not opening form frmApp1.
    I have tried in several situations: creating a new form and then renaming it to frmApp1 (then making the changes to the related files) and also creating the new form with the Windows Forms procedure, but the effect is the same.
    If I may add that by replacing .Close with . Hide, the opening of the main form is repeated infinitely, but the second form is never opened.
    I also noticed that in the suggested code, the name frmApp1 is written once with capital F and the second time with lower case f.

    Private Sub Button1_click(sender As Object, e As EventArgs) Handles Button1.Click
    FrmApp1 = New Form1
    frmApp1.Show()
    Me.Close()
    End Sub

    Can you please try it out and see if it is me making a mistake, but I don't know what kind?
    I know I am annoying on very trivial content, but it would help me while waiting to follow a more systematic learning path.
    Thank you for your kind response,
    see you soon, Vic.

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Problems displaying forms

    The capitalization means nothing. VB will fix that for you automatically.

    The issue is not in the Button Click event handler, it's that you are creating a new Form1 to show from within Form1 itself. That is technically possible, but it is a VERY unusual thing to be doing. Normally form A creates form B, not another instance of form A.
    My usual boring signature: Nothing

  15. #15

    Thread Starter
    New Member
    Join Date
    May 2023
    Location
    Montagna in Valtellina - Sondrio - Italia
    Posts
    15

    Re: Problems displaying forms

    Quote Originally Posted by Shaggy Hiker View Post
    The capitalization means nothing. VB will fix that for you automatically.

    The issue is not in the Button Click event handler, it's that you are creating a new Form1 to show from within Form1 itself. That is technically possible, but it is a VERY unusual thing to be doing. Normally form A creates form B, not another instance of form A.

    Thank you for your intervention, but I think your point should be addressed to the person who suggested the way to solve the proposed problem.
    Regarding upper and lower case letters, I am well aware that the editor corrects the text; I had highlighted this fact because I believed (and I believe) that the suggestion was not really tried precisely because it was not unified by the VB editor. But that is not important.

    I stated that I had a problem and inadequate skills to solve it. I asked for help believing that a community of experts can surely do it quickly and easily.

    I, kindly, ask: how to call a new form starting from the situation described?
    If someone can give me the answer I will be really grateful.

    If it is not clear what the problem is, I will try to propose it again:

    I have two forms: Form1 not renamed, but I would like to do so and Form2, also to be renamed.
    I would like to call Form2 from Form1 and at the end of the work done by Form2, return to Form1 and continue the interrupted work using the values processed by Form2.

    I thank those who would like to propose a solution to what I thought was an easy problem for an expert to solve.

    Thanks again, looking forward, best regards, Vic.

  16. #16
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Problems displaying forms

    I diidn't take the time to read all the posts so maybe I missed something. But this is very basic,

    I would like to call Form2 from Form1 and at the end of the work done by Form2, return to Form1
    Code:
    Private Sub Button1_click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim frmForm2 as New Form2
    frmForm2.Show()
    
    End Sub
    Can't answer this part because I don't know what "values" represent or where they originated.

    Code:
    continue the interrupted work using the values processed by Form2.

  17. #17
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems displaying forms

    It's simple, but you need to change your shutdown mode so your app doesn't end when you close Form1.

    Code:
    Public Class Form1
        Dim frm As Form2
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            frm = New Form2       
            frm.Show()
            Me.Close()
        End Sub
    End Class
    To change shutdown mode,

    Project-->Properties-->Application-->Shutdown Mode

  18. #18
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems displaying forms

    Quote Originally Posted by wes4dbt View Post
    I diidn't take the time to read all the posts so maybe I missed something. But this is very basic,



    Code:
    Private Sub Button1_click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim frmForm2 as New Form2
    frmForm2.Show()
    
    End Sub
    Wouldn't ShowDialog be better?

    Quote Originally Posted by wes4dbt View Post
    Can't answer this part because I don't know what "values" represent or where they originated.

    Code:
    continue the interrupted work using the values processed by Form2.
    I think the OP means the values changed in Form2

  19. #19
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Problems displaying forms

    Quote Originally Posted by .paul. View Post
    Wouldn't ShowDialog be better?



    I think the OP means the values changed in Form2
    Maybe ShowDialog would be better I really don't know enough about what the OP is trying to achieve.

    I think the OP means the values changed in Form2
    I think your right. But where did these values come from? Form1? Database? Manually entered on Form2? WHat data Type are they. Are they in a datatable.

    How I chose to pass data between forms depends on the situation.

  20. #20
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems displaying forms

    @Vic

    Have a look at how to use Dialog forms for editing data. They're modal, so your main form execution stops and waits until you close the dialog...

    http://www.scproject.biz/Using%20Dialogs.php#bm11

  21. #21

    Thread Starter
    New Member
    Join Date
    May 2023
    Location
    Montagna in Valtellina - Sondrio - Italia
    Posts
    15

    Re: Problems displaying forms

    Quote Originally Posted by .paul. View Post
    It's simple, but you need to change your shutdown mode so your app doesn't end when you close Form1.

    Code:
    Public Class Form1
        Dim frm As Form2
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            frm = New Form2       
            frm.Show()
            Me.Close()
        End Sub
    End Class
    To change shutdown mode,

    Project-->Properties-->Application-->Shutdown Mode
    Okay, now it is much clearer. I think your example now, is adequate and clarifying.
    I have tried the example and adapted it to my current project: all OK!
    I thank you and those who participated with the intent to help and had the right spirit to get involved in a problem that was considered "too simple" and therefore not seen by all as worthy of comprehensive treatment. So overly concise answers are given (perhaps correct and recognizable to those familiar with the problem), but not very useful or usable for those who need to understand.
    Thanks again, see you soon, Vic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width