Click here to Skip to main content
15,860,972 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Visual Studio List Box with 1,000,000 entries / Who else noticed this capacity? Pin
Member 1507871621-Jul-22 5:53
Member 1507871621-Jul-22 5:53 
Questionthis is my code trying to deduct qty from tableproduct after sales Pin
Titus Miclus Afful7-Jul-22 0:11
Titus Miclus Afful7-Jul-22 0:11 
AnswerRe: this is my code trying to deduct qty from tableproduct after sales Pin
Victor Nijegorodov7-Jul-22 0:31
Victor Nijegorodov7-Jul-22 0:31 
GeneralRe: this is my code trying to deduct qty from tableproduct after sales Pin
jsc427-Jul-22 1:07
professionaljsc427-Jul-22 1:07 
GeneralRe: this is my code trying to deduct qty from tableproduct after sales Pin
Richard MacCutchan7-Jul-22 1:27
mveRichard MacCutchan7-Jul-22 1:27 
AnswerRe: this is my code trying to deduct qty from tableproduct after sales Pin
Richard Deeming7-Jul-22 2:08
mveRichard Deeming7-Jul-22 2:08 
QuestionRaise Event on another Form Pin
EngrImad21-Jun-22 5:01
EngrImad21-Jun-22 5:01 
AnswerRe: Raise Event on another Form Pin
Dave Kreskowiak22-Jun-22 7:18
mveDave Kreskowiak22-Jun-22 7:18 
What you're doing seems backwards, but, hey, it's your app and I don't know anything about it.

Since Form2 doesn't (and SHOULDN'T!) know anything about Form1. By doing this, you forever tie both forms together making it impossible to use one of them without the other.

Your Form2 code is creating a NEW INSTANCE of Form1, NOT using the existing instance! That's why it doesn't work. You do not need the "WithEvents", or even that entire line, on Form2.

If Form2 needs to subscribe to events exposed by Form1, you have to pass your instance of Form1 to a constructor on Form2 so it knows which instance events to subscribe to. Then the constructor needs to "wire-up" the event handlers for whatever events it needs, manually using AddHandler.

My VB.NET is really rusty, so the following may not even compile let alone run:
VB.NET
Public Class Form1
    Public Event Show_My_Message(ByVal message As String)

    Private Sub btnOpenForm2_Click(sender As Object, e As EventArgs) Handles btnOpenForm2.Click
        Dim form2 As New Form2(Me)         ' This passes the reference to the Form1 instance to the Form2 instance
        form2.Show()                       ' Show an instance of Form2
    End Sub

    Private Sub btnShowMessageOnForm2_Click(sender As Object, e As EventArgs) Handles btnShowMessageOnForm2.Click
        RaiseEvent Show_My_Message("Some message")
    End Sub
End Class

Public Class Form2
    Public Sub New(Form1 eventProvider)       ' THIS IS BAD PRACTICE! Form1 should be replaced by an interface!
        AddHandler eventProvider.Show_My_Message, AddressOf ShowMyMessageHandler
    End Sub

    Public Sub ShowMyMessageHandler(ByVal message As String)
        MsgBox(message)
    End Sub
End Class


GeneralRe: Raise Event on another Form Pin
jsc426-Jul-22 6:23
professionaljsc426-Jul-22 6:23 
QuestionCopy Record(s) from 1 Database to Another Database with the same Tables Pin
crmfghtr20-Jun-22 16:42
crmfghtr20-Jun-22 16:42 
AnswerRe: Copy Record(s) from 1 Database to Another Database with the same Tables Pin
Victor Nijegorodov20-Jun-22 20:24
Victor Nijegorodov20-Jun-22 20:24 
QuestionGet Process Percentage Pin
EngrImad18-Jun-22 8:33
EngrImad18-Jun-22 8:33 
AnswerRe: Get Process Percentage Pin
PIEBALDconsult18-Jun-22 8:35
mvePIEBALDconsult18-Jun-22 8:35 
GeneralRe: Get Process Percentage Pin
EngrImad19-Jun-22 0:22
EngrImad19-Jun-22 0:22 
GeneralRe: Get Process Percentage Pin
Dave Kreskowiak19-Jun-22 8:00
mveDave Kreskowiak19-Jun-22 8:00 
GeneralRe: Get Process Percentage Pin
EngrImad19-Jun-22 3:57
EngrImad19-Jun-22 3:57 
AnswerRe: Get Process Percentage Pin
Richard Deeming19-Jun-22 21:41
mveRichard Deeming19-Jun-22 21:41 
AnswerRe: Get Process Percentage Pin
David Mujica22-Jun-22 3:42
David Mujica22-Jun-22 3:42 
QuestionStrange behavior readline Pin
JR21214-Jun-22 1:05
JR21214-Jun-22 1:05 
AnswerRe: Strange behavior readline Pin
Richard MacCutchan14-Jun-22 5:16
mveRichard MacCutchan14-Jun-22 5:16 
GeneralRe: Strange behavior readline Pin
JR21216-Jun-22 2:16
JR21216-Jun-22 2:16 
AnswerRe: Strange behavior readline Pin
Alan N14-Jun-22 5:30
Alan N14-Jun-22 5:30 
GeneralRe: Strange behavior readline Pin
JR21216-Jun-22 2:13
JR21216-Jun-22 2:13 
QuestionDatabase relating entity having various data members Pin
lazy_dude12-Jun-22 20:17
lazy_dude12-Jun-22 20:17 
AnswerRe: Database relating entity having various data members Pin
Richard Deeming12-Jun-22 21:26
mveRichard Deeming12-Jun-22 21:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.