473,396 Members | 1,907 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.

Object OnChange

29
Hey I have class and I was wondering if I can do an OnChange event with the class. Basically if someone tries closing the program without saving the object I went a warning to pop up. The OnChange event will switch a changed property in the class.

Thanks
Apr 8 '08 #1
7 1334
Plater
7,872 Expert 4TB
If you have your own custom class, add a private boolean to determine if anything about the class has changed.
Then all all the function/properties of the class that would change it, be sure to set that boolean to true and trigger that onchange event?
Apr 8 '08 #2
cday119
29
If you have your own custom class, add a private boolean to determine if anything about the class has changed.
Then all all the function/properties of the class that would change it, be sure to set that boolean to true and trigger that onchange event?
I am trying this to handle the onchange event but it comes up with an error
for Me.OnChange - Event OnChange not found. How do I add an onchange event?

Expand|Select|Wrap|Line Numbers
  1.  Public Sub OnChange() Handles Me.OnChange
  2.         ProfileChanged = True
  3.     End Sub

And here is the entire Class code

Expand|Select|Wrap|Line Numbers
  1. Public Class Profile
  2.  
  3.     Private ProfileFileName As String
  4.     Private ProfileDescription As String
  5.     Private ProfileVersion As Integer
  6.     Private ProfileNumAutoReduction As Integer
  7.     Private ProfileNumberLines As Integer
  8.     Private ProfilePrinterName As String
  9.     Private ProfilePrintOrientation As String
  10.     Private ProfilePaperSize As Integer
  11.     Private ProfileColumnsPerPage As Integer
  12.     Private ProfileRowsPerPage As Integer
  13.     Private ProfileHorizontalDisplacement As Integer
  14.     Private ProfileVerticalDisplacement As Integer
  15.     Private ProfileHorizontalSeperation As Integer
  16.     Private ProfileVerticalSeperation As Integer
  17.     Private ProfileLines As New Collection
  18.     Private ProfileChanged As Boolean = False
  19.  
  20.  
  21.     Public Sub OnChange() Handles Me.OnChange
  22.         ProfileChanged = True
  23.     End Sub
  24.     Public Sub New()
  25.         'This sub sets the defaults of the default Profile.
  26.         Me.Description = "New Profile"
  27.         Me.Version = 2
  28.         Me.NumAutoReduction = 4
  29.         Me.NumberLines = 4
  30.         Me.PrintOrientation = 2
  31.         Me.PaperSize = 260
  32.         Me.ColumnsPerPage = 1
  33.         Me.RowsPerPage = 1
  34.         Me.HorizontalDisplacement = 0
  35.         Me.VerticalDisplacement = 0
  36.         Me.HorizontalSeperation = 0
  37.         Me.VerticalSeperation = 0
  38.         Me.Changed = False
  39.  
  40.         Dim Line As Collection = New Collection
  41.         Dim Line2 As Collection = New Collection
  42.         Dim Line3 As Collection = New Collection
  43.         Dim Line4 As Collection = New Collection
  44.         Dim Reduction As Collection = New Collection
  45.         Dim Reduction2 As Collection = New Collection
  46.         Dim Reduction3 As Collection = New Collection
  47.         Dim Reduction4 As Collection = New Collection
  48.         Dim Reduction5 As Collection = New Collection
  49.  
  50.         Dim i As Integer = 1
  51.  
  52.         Reduction.Add("True", "Enabled")
  53.         Reduction.Add("24", "Size")
  54.         Reduction.Add("Arial", "Font")
  55.         Reduction.Add("False", "Bold")
  56.         Reduction.Add("False", "Caps")
  57.         Reduction.Add("False", "Italic")
  58.         Reduction.Add("610", "HorizontalDisplacement")
  59.         Reduction.Add("-50", "VerticalDisplacement")
  60.         Reduction.Add("3960", "Width")
  61.         Reduction2.Add("18", "Size")
  62.         Reduction2.Add("Arial", "Font")
  63.         Reduction2.Add("False", "Bold")
  64.         Reduction2.Add("False", "Caps")
  65.         Reduction2.Add("False", "Italic")
  66.         Reduction2.Add("610", "HorizontalDisplacement")
  67.         Reduction2.Add("300", "VerticalDisplacement")
  68.         Reduction2.Add("3960", "Width")
  69.         Reduction3.Add("16", "Size")
  70.         Reduction3.Add("Arial Narrow", "Font")
  71.         Reduction3.Add("False", "Bold")
  72.         Reduction3.Add("False", "Caps")
  73.         Reduction3.Add("False", "Italic")
  74.         Reduction3.Add("610", "HorizontalDisplacement")
  75.         Reduction3.Add("500", "VerticalDisplacement")
  76.         Reduction3.Add("3960", "Width")
  77.         Reduction4.Add("14", "Size")
  78.         Reduction4.Add("Arial Narrow", "Font")
  79.         Reduction4.Add("610", "HorizontalDisplacement")
  80.         Reduction4.Add("-50", "VerticalDisplacement")
  81.         Reduction4.Add("3960", "Width")
  82.         Reduction4.Add("False", "Bold")
  83.         Reduction4.Add("False", "Caps")
  84.         Reduction4.Add("False", "Italic")
  85.         Reduction5.Add("12", "Size")
  86.         Reduction5.Add("Arial Narrow", "Font")
  87.         Reduction5.Add("False", "Bold")
  88.         Reduction5.Add("False", "Caps")
  89.         Reduction5.Add("False", "Italic")
  90.         Reduction5.Add("610", "HorizontalDisplacement")
  91.         Reduction5.Add("-50", "VerticalDisplacement")
  92.         Reduction5.Add("3960", "Width")
  93.  
  94.         Line.Add(Reduction, "Reduction1")
  95.         Line.Add(Reduction2, "Reduction2")
  96.         Line.Add(Reduction3, "Reduction3")
  97.         Line.Add(Reduction4, "Reduction4")
  98.         Line2.Add(Reduction2, "Reduction1")
  99.         Line2.Add(Reduction3, "Reduction2")
  100.         Line2.Add(Reduction4, "Reduction3")
  101.         Line2.Add(Reduction5, "Reduction4")
  102.         Line3.Add(Reduction3, "Reduction1")
  103.         Line3.Add(Reduction4, "Reduction2")
  104.         Line3.Add(Reduction5, "Reduction3")
  105.         Line3.Add(Reduction5, "Reduction4")
  106.         Line4.Add(Reduction4, "Reduction1")
  107.         Line4.Add(Reduction5, "Reduction2")
  108.         Line4.Add(Reduction5, "Reduction3")
  109.         Line4.Add(Reduction5, "Reduction4")
  110.  
  111.         Me.Lines.Add(Line, "Line1")
  112.         Me.Lines.Add(Line2, "Line2")
  113.         Me.Lines.Add(Line3, "Line3")
  114.         Me.Lines.Add(Line4, "Line4")
  115.  
  116.     End Sub
  117.  
  118.     Property Description() As String
  119.         Get
  120.             Return ProfileDescription
  121.         End Get
  122.         Set(ByVal value As String)
  123.             ProfileDescription = value
  124.         End Set
  125.     End Property
  126.  
  127.     Property FileName() As String
  128.         Get
  129.             Return ProfileFileName
  130.         End Get
  131.         Set(ByVal value As String)
  132.             ProfileFileName = value
  133.         End Set
  134.     End Property
  135.  
  136.     Property Version() As Integer
  137.         Get
  138.             Return ProfileVersion
  139.         End Get
  140.         Set(ByVal value As Integer)
  141.             ProfileVersion = value
  142.         End Set
  143.     End Property
  144.  
  145.     Property NumAutoReduction() As Integer
  146.         Get
  147.             Return ProfileNumAutoReduction
  148.         End Get
  149.         Set(ByVal value As Integer)
  150.             ProfileNumAutoReduction = value
  151.         End Set
  152.     End Property
  153.  
  154.     Property PrinterName() As String
  155.         Get
  156.             Return ProfilePrinterName
  157.         End Get
  158.         Set(ByVal value As String)
  159.             ProfilePrinterName = value
  160.         End Set
  161.     End Property
  162.  
  163.     Property PrintOrientation() As String
  164.         Get
  165.             Return ProfilePrintOrientation
  166.         End Get
  167.         Set(ByVal value As String)
  168.             ProfilePrintOrientation = value
  169.         End Set
  170.     End Property
  171.  
  172.     Property PaperSize() As Integer
  173.         Get
  174.             Return ProfilePaperSize
  175.         End Get
  176.         Set(ByVal value As Integer)
  177.             ProfilePaperSize = value
  178.         End Set
  179.     End Property
  180.  
  181.     Property ColumnsPerPage() As Integer
  182.         Get
  183.             Return ProfileColumnsPerPage
  184.         End Get
  185.         Set(ByVal value As Integer)
  186.             ProfileColumnsPerPage = value
  187.         End Set
  188.     End Property
  189.  
  190.     Property RowsPerPage() As Integer
  191.         Get
  192.             Return ProfileRowsPerPage
  193.         End Get
  194.         Set(ByVal value As Integer)
  195.             ProfileRowsPerPage = value
  196.         End Set
  197.     End Property
  198.  
  199.     Property HorizontalDisplacement() As Integer
  200.         Get
  201.             Return ProfileHorizontalDisplacement
  202.         End Get
  203.         Set(ByVal value As Integer)
  204.             ProfileHorizontalDisplacement = value
  205.         End Set
  206.     End Property
  207.  
  208.     Property VerticalDisplacement() As Integer
  209.         Get
  210.             Return ProfileVerticalDisplacement
  211.         End Get
  212.         Set(ByVal value As Integer)
  213.             ProfileVerticalDisplacement = value
  214.         End Set
  215.     End Property
  216.  
  217.     Property HorizontalSeperation() As Integer
  218.         Get
  219.             Return ProfileHorizontalSeperation
  220.         End Get
  221.         Set(ByVal value As Integer)
  222.             ProfileHorizontalSeperation = value
  223.         End Set
  224.     End Property
  225.  
  226.     Property VerticalSeperation() As Integer
  227.         Get
  228.             Return ProfileVerticalSeperation
  229.         End Get
  230.         Set(ByVal value As Integer)
  231.             ProfileVerticalSeperation = value
  232.         End Set
  233.     End Property
  234.  
  235.     Public Property Lines() As Collection
  236.         Get
  237.             Return ProfileLines
  238.         End Get
  239.         Set(ByVal value As Collection)
  240.             ProfileLines = value
  241.         End Set
  242.     End Property
  243.  
  244.     Property NumberLines() As Integer
  245.         Get
  246.             Return ProfileNumberLines
  247.         End Get
  248.         Set(ByVal value As Integer)
  249.             ProfileNumberLines = value
  250.         End Set
  251.     End Property
  252.  
  253.     Property Changed() As Boolean
  254.         Get
  255.             Return ProfileChanged
  256.         End Get
  257.         Set(ByVal value As Boolean)
  258.             ProfileChanged = value
  259.         End Set
  260.     End Property
  261.  
  262. End Class
  263.  
Apr 8 '08 #3
Plater
7,872 Expert 4TB
I think I have got something confused here.
I no longer understand why you want an event.
If at every function/property of your class that changes something, you ensure the boolean to be true. Then when you save, set the boolean to false. Simply checking that the boolean is false before closing would tell you if something has been changed?
Apr 8 '08 #4
cday119
29
I think I have got something confused here.
I no longer understand why you want an event.
If at every function/property of your class that changes something, you ensure the boolean to be true. Then when you save, set the boolean to false. Simply checking that the boolean is false before closing would tell you if something has been changed?
The thing is I don't want to write in every place I change the class that the class has chenged. This is why I want an onchange event. I just don't know how or if you can add an onchange event to a class.
Apr 9 '08 #5
Plater
7,872 Expert 4TB
If you want an onchange event, you would have to have to create it.
Which would entail coding it into every palce the object was changed.
OR have a background thread running that constantly compares the object to another instance of itself.
It might also be possible to do some unsafe code and watch the memory address to see if it has changed (Or possibly with serialization..checking to see if the serializaed version is different)

This is where good solid design before creating your objects come in to play.
Apr 9 '08 #6
cday119
29
If you want an onchange event, you would have to have to create it.
Which would entail coding it into every palce the object was changed.
OR have a background thread running that constantly compares the object to another instance of itself.
It might also be possible to do some unsafe code and watch the memory address to see if it has changed (Or possibly with serialization..checking to see if the serializaed version is different)

This is where good solid design before creating your objects come in to play.
So I can't do an onChange event like say a text box has a TextChanged event?
Where everytime a textbox changes text an event is triggered but you don't have to code an event everywhere you change a textbox's text.
Apr 9 '08 #7
Plater
7,872 Expert 4TB
So I can't do an onChange event like say a text box has a TextChanged event?
Where everytime a textbox changes text an event is triggered but you don't have to code an event everywhere you change a textbox's text.
Not unless you make it yourself.
Apr 9 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Joe Kelsey | last post by:
When you use addEventListener (or addEvent in IE) to call an object method, does it call it with the correct this parameter? The ECMAScript reference has a lot to say about the caller using...
16
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not...
1
by: fig000 | last post by:
Hi, I want to use a select object in asp and have the user pick something from this select and have javascript open a window fired by an event. Once the new window is open it displays another...
3
by: news.onetel.net.uk | last post by:
I and my friend Karl have spent literally all day trying to find out what is causing my error but we are zapped of any further functionality :) I have a form that adds news records. You select...
2
by: Abby Lee | last post by:
I want to use the same function for a number of fields. <input name="taxi1" type="text" id="taxi1" size="8" onChange="myFunction (this,1)"> function myFunction(val, itm) { } What can I do...
7
by: Joakim Braun | last post by:
Why doesn't the below code work? I'm trying to create a global object and set an event handler to one of its methods. The function is called, but the object's mTest property is undefined. ...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
8
by: George | last post by:
I need help with the code listed below. See the line below the comment-// *** This displays the error *** I want to be able to have the event handler call the function based on the reference...
0
by: David C | last post by:
I am getting this error in the Databound event of a GridView and I am having a difficult time debugging. I do not get the error on every record that I edit in the GridView. The error is occurring...
11
by: CreativeMind | last post by:
hi all, my dropdownlist 'cboUnitTypes' is populating on the base of another dropdownlist1, i have to apply a check on 'cboUnitTypes' like if(cboUnitTypes.value==0)return false; now problem is;...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.