473,396 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dim scope within an IF

I have two forms both derived by inheriting the same base form. I have a
third form that needs to instantiate one of those two forms, set some
Protected properties on the two forms, display the form, test a property of
the from when it is closed and then dispose of the instantiated form.

The third form has two radio buttons used to determine wich form to
instantiate. The folllowing code fails to compile due to the scope of the
DIM statement.

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
End If

'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If

'dispose of the form
frm.Dispose()
End Sub

Because of this I have to resort to the following:

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End If
End Sub

YUCH!!!!! That is truly UGLY. But I, for the life of me, can't find any
other way to do this. Suggestions? Clue by fours?

Thanks,

Gary
Nov 20 '05 #1
5 1153
Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditTheClass.Click

Dim frm As BaseClassFormName

If RadioButton_BP.Checked Then
frm = New frmBP_Class
ElseIf RadioButton_IO.Checked Then
frm = New frmIO_Class
End If

' rest of code goes here
-Rob Teixeira [MVP]

"Gary Shell" <gs****@fuse.net> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have two forms both derived by inheriting the same base form. I have a
third form that needs to instantiate one of those two forms, set some
Protected properties on the two forms, display the form, test a property of the from when it is closed and then dispose of the instantiated form.

The third form has two radio buttons used to determine wich form to
instantiate. The folllowing code fails to compile due to the scope of the
DIM statement.

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
End If

'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If

'dispose of the form
frm.Dispose()
End Sub

Because of this I have to resort to the following:

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End If
End Sub

YUCH!!!!! That is truly UGLY. But I, for the life of me, can't find any
other way to do this. Suggestions? Clue by fours?

Thanks,

Gary

Nov 20 '05 #2
Ah, yes. A Clue By Four. Gladly accepted!

Thanks,
Gary

"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditTheClass.Click

Dim frm As BaseClassFormName

If RadioButton_BP.Checked Then
frm = New frmBP_Class
ElseIf RadioButton_IO.Checked Then
frm = New frmIO_Class
End If

' rest of code goes here
-Rob Teixeira [MVP]

"Gary Shell" <gs****@fuse.net> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have two forms both derived by inheriting the same base form. I have a third form that needs to instantiate one of those two forms, set some
Protected properties on the two forms, display the form, test a property

of
the from when it is closed and then dispose of the instantiated form.

The third form has two radio buttons used to determine wich form to
instantiate. The folllowing code fails to compile due to the scope of the DIM statement.

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e

As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
End If

'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If

'dispose of the form
frm.Dispose()
End Sub

Because of this I have to resort to the following:

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e

As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End If
End Sub

YUCH!!!!! That is truly UGLY. But I, for the life of me, can't find any
other way to do this. Suggestions? Clue by fours?

Thanks,

Gary


Nov 20 '05 #3
Put the dim statement before the IF and the instantiation within the IF

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Gary Shell" <gs****@fuse.net> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have two forms both derived by inheriting the same base form. I have a
third form that needs to instantiate one of those two forms, set some
Protected properties on the two forms, display the form, test a property of the from when it is closed and then dispose of the instantiated form.

The third form has two radio buttons used to determine wich form to
instantiate. The folllowing code fails to compile due to the scope of the
DIM statement.

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
End If

'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If

'dispose of the form
frm.Dispose()
End Sub

Because of this I have to resort to the following:

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End If
End Sub

YUCH!!!!! That is truly UGLY. But I, for the life of me, can't find any
other way to do this. Suggestions? Clue by fours?

Thanks,

Gary

Nov 20 '05 #4
Initially, I thought I couldn't do that, I tried "Dim frm as Form" but of
course that didn't work as DIM'ing as a generic form meant I wouldn't have
access to my own properties I'd added to my forms. I was in the dark until
I got Rob's "clue by four" upside my head. <grin>

I then realized I could Dim the form using the BASE class of the multiple
inherited forms. Then in the IF/END IF I could instantiate the proper
inherited form based on the radio button selection.

Now the code looks like this:
Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditTheClass.Click
Dim frm As TheClassForm.frmTheClass
If RadioButton_BP.Checked Then
frm = New frmBP_Class
ElseIf RadioButton_IO.Checked Then
frm = New frmIO_Class
End If

'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End Sub

Much "prettier" don'tcha think?

Gary
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:ON*************@TK2MSFTNGP10.phx.gbl...
Put the dim statement before the IF and the instantiation within the IF

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Gary Shell" <gs****@fuse.net> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have two forms both derived by inheriting the same base form. I have a third form that needs to instantiate one of those two forms, set some
Protected properties on the two forms, display the form, test a property

of
the from when it is closed and then dispose of the instantiated form.

The third form has two radio buttons used to determine wich form to
instantiate. The folllowing code fails to compile due to the scope of the DIM statement.

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e

As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
End If

'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If

'dispose of the form
frm.Dispose()
End Sub

Because of this I have to resort to the following:

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e

As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End If
End Sub

YUCH!!!!! That is truly UGLY. But I, for the life of me, can't find any
other way to do this. Suggestions? Clue by fours?

Thanks,

Gary


Nov 20 '05 #5
Well Done !

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Gary Shell" <gs****@fuse.net> wrote in message
news:O5*************@TK2MSFTNGP12.phx.gbl...
Initially, I thought I couldn't do that, I tried "Dim frm as Form" but of
course that didn't work as DIM'ing as a generic form meant I wouldn't have
access to my own properties I'd added to my forms. I was in the dark until I got Rob's "clue by four" upside my head. <grin>

I then realized I could Dim the form using the BASE class of the multiple
inherited forms. Then in the IF/END IF I could instantiate the proper
inherited form based on the radio button selection.

Now the code looks like this:
Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditTheClass.Click
Dim frm As TheClassForm.frmTheClass
If RadioButton_BP.Checked Then
frm = New frmBP_Class
ElseIf RadioButton_IO.Checked Then
frm = New frmIO_Class
End If

'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End Sub

Much "prettier" don'tcha think?

Gary
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:ON*************@TK2MSFTNGP10.phx.gbl...
Put the dim statement before the IF and the instantiation within the IF

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Gary Shell" <gs****@fuse.net> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have two forms both derived by inheriting the same base form. I have
a
third form that needs to instantiate one of those two forms, set some
Protected properties on the two forms, display the form, test a
property
of
the from when it is closed and then dispose of the instantiated form.

The third form has two radio buttons used to determine wich form to
instantiate. The folllowing code fails to compile due to the scope of the DIM statement.

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal

e As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
End If

'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If

'dispose of the form
frm.Dispose()
End Sub

Because of this I have to resort to the following:

Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal
e As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End If
End Sub

YUCH!!!!! That is truly UGLY. But I, for the life of me, can't find

any other way to do this. Suggestions? Clue by fours?

Thanks,

Gary



Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hal Vaughan | last post by:
Being self taught, this is one thing I've always had trouble with -- I finally get it straight in one situation and I find I'm not sure about another. I have a class that keeps calling an...
3
by: Anonymous | last post by:
Is namespace the same thing as scope? While reading the book "Thinking in C++", I was under the impression that namespace is, well, a namespace--a feature to create a hiearchy for identifiers...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
2
by: bughunter | last post by:
This is partly 'for the record' and partly a query about whether the following is a bug somewhere in .Net (whether it be the CLR, JITter, C# compiler). This is all in the context of .Net 1.1 SP1. ...
39
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the...
26
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null);...
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
2
by: ray | last post by:
Hi, all, foreach($array as $k =$v) { $foo = ...; } echo $foo; Is it allowed to access the $foo variable that is created within the loop from outside of the loop? I think it isn't allowed,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.