Take Pity on a procedural programmer Please

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

frmMIS.UserName.Text is defaulted to 'sa'
I change it to 'sa1' when logged in as admin.
I hit btnApply.
I want frmMISRoutine.UserName.Text to become 'sa1' immediatly.
I do not want to show the form immediately.
I hit btnRoutines and load frmMISRoutine screen.
I want to see frmMISRoutine.UserName.Text as 'sa1'
How the hell can I do it...my code is below:
I don't mind learning how to write classes/modules but shouldn't this be a
simple enough thing to do. I still think that it is not much use beeing able
to share objects between screens if you have to load that screen straight
away. It doesn't seem very dynamis, what if you wanted to update the value on
4 screens, would you have to show them all?

UserName.Text on both forms is defaulted to 'sa'

' Apply button to set Routines.UserName.Text from 'sa' to 'sa1'
Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnApply.Click
Dim frmMISRoutine As New Routines
frmMISRoutine.UserName.Text = Me.UserName.Text

Me.ClientSize = New System.Drawing.Size(584, 435)
pnlProperties.Visible = False
btnProperties.Enabled = True
btnApply.Visible = False
btnCancel.Visible = False
sbMIS.Text = "Use buttons to navigate the application (e.g.) [Properties
sets the database and log parameters]."
PollDirectory = txtPollDirectory.Text
End Sub

' Open Routines Form. the UserName.Text should be 'sa1'.
Private Sub btnRoutines_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRoutines.Click
Dim frmMISRoutine As New Routines
frmMISRoutine.Show()
Me.Close()
' When this loads Routines UserName is still sa aaarrrrgggghhhhhh!!!
End Sub
 
marcmc said:
frmMIS.UserName.Text is defaulted to 'sa'
I change it to 'sa1' when logged in as admin.
I hit btnApply.
I want frmMISRoutine.UserName.Text to become 'sa1' immediatly.
I do not want to show the form immediately.
I hit btnRoutines and load frmMISRoutine screen.
I want to see frmMISRoutine.UserName.Text as 'sa1'
How the hell can I do it...my code is below:
I don't mind learning how to write classes/modules but shouldn't this be a
simple enough thing to do. I still think that it is not much use beeing able
to share objects between screens if you have to load that screen straight
away. It doesn't seem very dynamis, what if you wanted to update the value on
4 screens, would you have to show them all?

UserName.Text on both forms is defaulted to 'sa'

' Apply button to set Routines.UserName.Text from 'sa' to 'sa1'
Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnApply.Click
Dim frmMISRoutine As New Routines
frmMISRoutine.UserName.Text = Me.UserName.Text

Me.ClientSize = New System.Drawing.Size(584, 435)
pnlProperties.Visible = False
btnProperties.Enabled = True
btnApply.Visible = False
btnCancel.Visible = False
sbMIS.Text = "Use buttons to navigate the application (e.g.) [Properties
sets the database and log parameters]."
PollDirectory = txtPollDirectory.Text
End Sub

' Open Routines Form. the UserName.Text should be 'sa1'.
Private Sub btnRoutines_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRoutines.Click
Dim frmMISRoutine As New Routines
frmMISRoutine.Show()
Me.Close()
' When this loads Routines UserName is still sa aaarrrrgggghhhhhh!!!
End Sub

Well your problem seem to be you are dealing with two different Routines
objects. Everytime you do Dim frmMISRoutine As New Routines it makes a
new Routines object and set everything to the default. If you only want
to deal with one object, make a class level variable called
frmMISRoutine and then only use the "new" keyword once.

Public Class XYZ
dim frmMISRoutine as Routines

Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnApply.Click
frmMISRoutine = New Routines
frmMISRoutine.UserName.Text = Me.UserName.Text

Me.ClientSize = New System.Drawing.Size(584, 435)
pnlProperties.Visible = False
btnProperties.Enabled = True
btnApply.Visible = False
btnCancel.Visible = False
sbMIS.Text = "Use buttons to navigate the application (e.g.)
[Properties sets the database and log parameters]."
PollDirectory = txtPollDirectory.Text
End Sub

' Open Routines Form. the UserName.Text should be 'sa1'.
Private Sub btnRoutines_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRoutines.Click
'Dim frmMISRoutine As New Routines
'Now the frmMISRoutine already exists, don't make a new one
frmMISRoutine.Show()
Me.Close()
' When this loads Routines UserName is still sa aarrrrgggghhhhhh!!!
End Sub
 
I presume that btnApply and btnRoutines are both buttons on the main
form? In that case replace these lines:

Dim frmMISRoutin As New Routines
frmMISRoutine.UserName.Text = Me.UserName.Text

with:

Me.UserName.Text = "sa1"
 
yes Chris they are on the main form, thankyou and more aaaarrrrggghhhh...

First example says that frmMISRoutine is not declared even though I declare
it within a class called dbProps
The second example does not even come close to ythe requirement i need. I
need to set the textBox on form2 when i hit the apply button on Form1, not
show form3 until button1 is pressed. That is all.

I have programmed in many languages and have never seen a rediculous means
of sharing global variables like this. Insane and Why?


Chris said:
marcmc said:
frmMIS.UserName.Text is defaulted to 'sa'
I change it to 'sa1' when logged in as admin.
I hit btnApply.
I want frmMISRoutine.UserName.Text to become 'sa1' immediatly.
I do not want to show the form immediately.
I hit btnRoutines and load frmMISRoutine screen.
I want to see frmMISRoutine.UserName.Text as 'sa1'
How the hell can I do it...my code is below:
I don't mind learning how to write classes/modules but shouldn't this be a
simple enough thing to do. I still think that it is not much use beeing able
to share objects between screens if you have to load that screen straight
away. It doesn't seem very dynamis, what if you wanted to update the value on
4 screens, would you have to show them all?

UserName.Text on both forms is defaulted to 'sa'

' Apply button to set Routines.UserName.Text from 'sa' to 'sa1'
Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnApply.Click
Dim frmMISRoutine As New Routines
frmMISRoutine.UserName.Text = Me.UserName.Text

Me.ClientSize = New System.Drawing.Size(584, 435)
pnlProperties.Visible = False
btnProperties.Enabled = True
btnApply.Visible = False
btnCancel.Visible = False
sbMIS.Text = "Use buttons to navigate the application (e.g.) [Properties
sets the database and log parameters]."
PollDirectory = txtPollDirectory.Text
End Sub

' Open Routines Form. the UserName.Text should be 'sa1'.
Private Sub btnRoutines_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRoutines.Click
Dim frmMISRoutine As New Routines
frmMISRoutine.Show()
Me.Close()
' When this loads Routines UserName is still sa aaarrrrgggghhhhhh!!!
End Sub

Well your problem seem to be you are dealing with two different Routines
objects. Everytime you do Dim frmMISRoutine As New Routines it makes a
new Routines object and set everything to the default. If you only want
to deal with one object, make a class level variable called
frmMISRoutine and then only use the "new" keyword once.

Public Class XYZ
dim frmMISRoutine as Routines

Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnApply.Click
frmMISRoutine = New Routines
frmMISRoutine.UserName.Text = Me.UserName.Text

Me.ClientSize = New System.Drawing.Size(584, 435)
pnlProperties.Visible = False
btnProperties.Enabled = True
btnApply.Visible = False
btnCancel.Visible = False
sbMIS.Text = "Use buttons to navigate the application (e.g.)
[Properties sets the database and log parameters]."
PollDirectory = txtPollDirectory.Text
End Sub

' Open Routines Form. the UserName.Text should be 'sa1'.
Private Sub btnRoutines_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRoutines.Click
'Dim frmMISRoutine As New Routines
'Now the frmMISRoutine already exists, don't make a new one
frmMISRoutine.Show()
Me.Close()
' When this loads Routines UserName is still sa aarrrrgggghhhhhh!!!
End Sub
 
Marc,

Place in the load event of your mainform this

dim frm as new frmMisRoutine
frm.mypassword = "whatever"
frm.showdialog
dim myresult as string = frm.mypassword
frm.dispose

In your frmMisRoutine you create

Friend mypassword as string

In the load event of that form you set
TheTextBoxYouWant.Text = mypassword

And before you close you do
mypassword = TheTextBooxYouWant

There are easier methods however this is in my opinion well to understand
the behaviour.

You have to know that VBNet controls have no child controls direct however
VBNet controls (Form is one of those) have only control arrays. It is a
little bit confusing that so many VB6 people have written that the
controlarrays don't exist anymore in VBNet. The way the controlarray as it
was in VB6 does not exist anymore.

I hope that this gives some ideas

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top