473,320 Members | 2,029 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,320 software developers and data experts.

Set Statement vs Function

I have an mObj class to represent MS Access database tables in my
VB.net project. It handles all table schema stuff like adding columns,

setting properties of columns etc. For example, I have a property in
mObj called AllowBlanks. This is mapped to the 'Required' property of
a MS Access db column.

I have code in the 'Set' statement of the AllowBlanks property to
change the Access column's 'Required property' to whatever the user
submits as 'value' I am using ADOX to work with Access, example:

Private _BlanksAllowed As Boolean
Public Property AllowBlanks() As Boolean
Get
Return _BlanksAllowed
End Get
Set(ByVal value As Boolean)
Dim con As ADODB.Connection = DAL.GetADODBCon
Dim db As New ADOX.Catalog

con.Open()
db.ActiveConnection = con

db.Tables(_ParentMobj.Name).Columns(_Name).Propert ies("Nullable").Value

= value
con.Close()
_AllowBlanks = false
End Set

Should I have this code here or in a separate function? If I keep it
in the Set statement, how will I know if the code failed or succeeded
when I set the value from a form later on? If it was in a function, I
could have it return false if the code failed.
Keeping the code in the Set statement makes my form code easier to read

mObj.AllowBlanks = True. But I don't understand how I can test if this

is succsesful in my code.
Having the code in a function would be more code in my forms:
SetAllowBlanks(mObj, True), but I could handle a failure if the
function returned false.

How have you all handled Set statements that could provoke an error?

Oct 2 '06 #1
3 1341
Bryan,

You can throw an exception and set a catch on that.

I could not find a link on MSDN about exceptions although I have searched 15
minutes.
But it should be there, so maybe can you try it yourself.

I hope this gives an idea,

Cor

"Bryan" <br*******@gmail.comschreef in bericht
news:11**********************@i3g2000cwc.googlegro ups.com...
>I have an mObj class to represent MS Access database tables in my
VB.net project. It handles all table schema stuff like adding columns,

setting properties of columns etc. For example, I have a property in
mObj called AllowBlanks. This is mapped to the 'Required' property of
a MS Access db column.

I have code in the 'Set' statement of the AllowBlanks property to
change the Access column's 'Required property' to whatever the user
submits as 'value' I am using ADOX to work with Access, example:

Private _BlanksAllowed As Boolean
Public Property AllowBlanks() As Boolean
Get
Return _BlanksAllowed
End Get
Set(ByVal value As Boolean)
Dim con As ADODB.Connection = DAL.GetADODBCon
Dim db As New ADOX.Catalog

con.Open()
db.ActiveConnection = con

db.Tables(_ParentMobj.Name).Columns(_Name).Propert ies("Nullable").Value

= value
con.Close()
_AllowBlanks = false
End Set

Should I have this code here or in a separate function? If I keep it
in the Set statement, how will I know if the code failed or succeeded
when I set the value from a form later on? If it was in a function, I
could have it return false if the code failed.
Keeping the code in the Set statement makes my form code easier to read

mObj.AllowBlanks = True. But I don't understand how I can test if this

is succsesful in my code.
Having the code in a function would be more code in my forms:
SetAllowBlanks(mObj, True), but I could handle a failure if the
function returned false.

How have you all handled Set statements that could provoke an error?

Oct 2 '06 #2
Thanks for the idea. So I guess I could create and throw a custom
exception object in my Set statement, then catch it at the form level.

Oct 2 '06 #3
yes

"Bryan" <br*******@gmail.comschreef in bericht
news:11**********************@e3g2000cwe.googlegro ups.com...
Thanks for the idea. So I guess I could create and throw a custom
exception object in my Set statement, then catch it at the form level.

Oct 2 '06 #4

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

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
6
by: lovecreatesbeauty | last post by:
I ever missed a `return' statement when write a function `int HighDigit(Num)' to get the highest digit of an integer. But even if the `return' statement is ignored the function still can obtain...
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.