|
Colin Angus Mackay wrote: Enumerators are just objects, just like normal variables are objects.
Hi Colin, well, actually not all normal variables are objects. An integral type (Int16, Int32, etc.. ) is a value type, and it is not stored as an object (reference type) UNLESS it is needed to. It all depends on your code's syntax.
This automatic conversion between value types and reference types is managed transparently by the .net platform by means of two behind-the-scenes processes known as "boxing" and "unboxing" respectively.
Boxing implies first creating on the heap a new instance of an object "compatible" with the original value type (involving dynamic memory allocation) then the actual variable's value must be copied to this new instance.
Unboxing implies dereferencing the value stored in an object instance and convert it back to a value-type.
Dim o as Object
Dim n as Integer
Dim m as Integer
Dim al as New ArrayList
o = 5 ' the value 5 is converted to an object (boxing) before being assigned
n = 0 ' the object's value 5 is dereferenced and stored back in n as a type value (unboxing)
' This means that n holds a copy of the value stored in o (5) not an extra reference to the same object refered by o
m = 10 ' The value 10 is directly stored in variable m as a value type, no heap memory allocation has taken place
al.Add(m) ' The variable m is converted to an object (boxed) before being added to the collection
Some languages like C++ can't treat integral types as objects for the sake of efficiency, other languages like Smalltalk effectively treat every variable (even integral types) as objects, which results in memory allocation/deallocation overhead for every single variable. The .net platform gives you the best of both worlds: on most cases, integral variables will be treated as efficiently as C++'s integral variables, but if needed to, they will be *transparently* converted to an object by the automatic "boxing-unboxing" process, giving you the full benefits of object orientation.
Cheers,
Gerardo
An interesting form of object-oriented programming:
You suggest a novel algorithm, and watch as the rest of your team objects!
|
|
|
|
|
Hi Erica
It's not clear in your post if you are asking about enumerations or enumerators.
They sound similar, but are totally different concepts. However, since you are asking about the difference between them and "normal variables" I assume you mean enumerations.
Talking about Visual Basic (at least with version 2003), their purpose varies depending whether you are compiling with Option Strict On .
With Option Strict Off , there is little difference between an enumeration and and integral variable. The enumeration simply helps the editor's Code Completion engine to suggest possible values for a variable (something really helpful). However, with Option Strict On , they allow you to program more robust applications since you will be creating a new data type that will have a restricted number of possible valid values.
To illustrate the enumeration's superiority *when used in an Option Strict On context*, imagine you are writing some sort of media player application. Most probably you need to control the player's state (playing, stopped, recording, etc). One valid way of doing it using normal integral variables as you suggest would be the following:
<code>
Const psStopped As Integer = 1
Const psPlaying As Integer = 2
Const psPaused As Integer = 3
Const psRecording As Integer = 4</code>
Then, you could somewhere in the code have a variable for controlling the state
<code>
Dim state as Integer
...
...
' Set the player's state to Playing
state = psPlaying</code>
This works, however, since the state value is held on a variable of type Integer, you might inadvertently add the following code
state = 5 ' oops this is an undefined player state
This is valid code and will compile without a fuzz, yet you might put your application in an invalid state and get unwanted results since the value 5 is a valid Integer value, but it is not an expected player state in your app's logic.
However, if you rewrite your application using an enumeration AND compile with Option Strict On:
<code>
Option Strict On
...
Public Enum PlayerStates
Stopped = 1
Playing = 2
Paused = 3
Recording = 4
End Enum
...
Dim state as PlayerStates
...
...
...
state = PlayerStates.Playing;
...
state = 5 ' This will give a compiler error, but ONLY IF compiling with
' Option Strict On
</code>
In this case, the compiler helped you avoid a possible programming error by disallowing assigning an invalid player state, according to the values defined in the PlayerStates enumeration.
This and other "defensive programming" options are available when compiling with Option Strict On, which is something I would recommend in the long run.
Hope I have clarified your doubt.
Cheers,
Gerardo
|
|
|
|
|
Hi Everybody,
Am sameer Pandurangi, a S/W Engineer and trying to build a small application.
Am working on VB.NET on windows application and using SQLSERVER Compact Edition.
I need a code to ZIP the database files and take the backup of it,and vice-versa need to UNZIP them before restoring.
If anyone out there know any thing about Zipping and Un-Zipping of files Please send me the note.
Thankyou
|
|
|
|
|
Have you tried to search Google[^]?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
|
That is a good one.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi
All
My Problem
Save click i am saving my supplier
SearchuniquesupplierID() in this proc actually i am inserting my supplier.
In the checkfortheSupplier() proc i am checking whether
the supplier is already exista or not
For the Forex supplier i can select the multiple
currency . I used listbox.
I got problem in my checkfortheSupplier()
for ex. if i add abc supplier For Europe Country For
two currency EUR and AUD.
Then in my table two rows are created.
but when i try to add same supplier for say EUR and and usd then it creates the proble actually it add
both which should not happen .
Pl update me.
Thanks
<br />
Private Sub ButSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButSave.Click<br />
checkfortheSupplier()<br />
'updateSupplierID()<br />
If (Supplier = True) Then<br />
If Not IsClientScriptBlockRegistered("alert") Then<br />
Page.RegisterClientScriptBlock("alert", "<script language = 'javascript'>alert('Supplier Already Added!');</script>")<br />
End If<br />
Exit Sub<br />
' End If<br />
Else<br />
<br />
If (RdINR.Checked = True) Then<br />
'inserttheSupplierINR()<br />
SearchuniquesupplierID()<br />
If Not IsClientScriptBlockRegistered("alert") Then<br />
Page.RegisterClientScriptBlock("alert", "<script language = 'javascript'>alert('Supplier Information Added Successfully!');</script>")<br />
End If<br />
ElseIf (RDForex.Checked = True) Then<br />
'inserttheSupplierForex()<br />
SearchuniquesupplierID()<br />
If Not IsClientScriptBlockRegistered("alert") Then<br />
Page.RegisterClientScriptBlock("alert", "<script language = 'javascript'>alert('Supplier Information Added Successfully!');</script>")<br />
End If<br />
<br />
End If 'RDINR if is closed <br />
End If<br />
End Sub<br />
<br />
<br />
#Region "Check Wheather Supplier already added or not"<br />
Public Sub checkfortheSupplier()<br />
Try<br />
connection.Open()<br />
strSql = ""<br />
<br />
For co = 0 To LstCurr.Items.Count - 1<br />
If LstCurr.Items(co).Selected Then<br />
strSql = "select supplier_name,country_id,currency from supplier_mst where supplier_name = '" & Trim(TxtSupplierName.Text) & "' and country_id='" & Trim(DpCountry.SelectedItem.Value) & "' and currency='" & Trim(LstCurr.Items(co).Text) & "'"<br />
command.CommandText = strSql<br />
command.Connection = connection<br />
dataReader = command.ExecuteReader<br />
End If<br />
Next<br />
While (dataReader.Read())<br />
Supplier = True<br />
End While<br />
<br />
<br />
Catch ex As Exception<br />
Finally<br />
dataReader.Close()<br />
connection.Close()<br />
End Try<br />
End Sub<br />
#End Region<br />
<br />
|
|
|
|
|
You didn't listen to anything Colin told you[^] when you posted this question yesterday. I hate repeating myself, let alone repeating what other people say.
But, I will add that this code shows you don't know the basics of VB.NET, such as how subs and functions work. You're using "global" variables all over the place. I seriously recommend you pick up a beginners book on VB.NET and work through it. What you've posted here so far is in desperate need of a rewrite - desperate.
|
|
|
|
|
Dave Kreskowiak wrote: You didn't listen to anything Colin told you
And there was nothing wrong with the post, either.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi,
I am using .Net 2003 with C#.
Pls provide me sytax of C# for Sending Mail throug Crystal Report.
I am using following code for generation report.
cRpt.ReportFileName = Application.StartupPath + @"\Reports\ABCReport.rpt";
cRpt.WindowState = Crystal.WindowStateConstants.crptMaximized ;
cRpt.Connect = "PROVIDER = Microsoft.Jet.OLEDB.4.0;Data Source = " + Application.StartupPath + @"\Database\DB123.mdb;Persist Security Info=True";
cRpt.Refresh();
cRpt.Action = 1;
Thanks & Regards Ketan K.
|
|
|
|
|
I suggest that you post this question in the C# forum
DO NOT DELETE the post here (makes for very messy forums) but you might want to put a message in the subject (something like 'wrong forum','moved','deleted',...)
that said I don't know if its possible to send mail with crystal report (I know it isn't possible with the crystal reports deliverd with visual studio maybe with a newer version it is).
What is possible is to export you report to a file and then attach that file to the mail message.
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
how to pop up a window in windows application?
|
|
|
|
|
hi
before you post, you need to think and plan and ask your self if people will understand what you going to ask.
Number one, this is the way understand your unclear question.
you want to Display a form when something happened in you other form lets say you MDI, e.g when a button is clicked then you want to popup a form(Window). if so you need to understand that in .NET we are now OOPs orientated, so you have to create an object of the form that you want to display and use the show method to diplay your form. it seems you have not learned the Basic's of vb.net, i suggest you buy a book, or here is an E-book that will help.
http://www.ebooknetworking.com[^]
Hope it helps
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
may I suggest using the 'showdialog' method (at least if I understand the OP correct)
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
You relaly need to pickup a book on VB.NET for Beginners. The ability to show another form is a very basic skill you must have in order to be successful in developing code in ANY language.
Here's the documentation on two methods of showing a form, complete with examples:
Form.Show method[^]
Form.ShowDialog method[^]
|
|
|
|
|
Seems like alot of people around here lately trying to do things beyond their apparent capabilities.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Use the Show or ShowDialog method. But, you really should get a book first.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I've added the following code to a test project trying to list the current instances of Windows Explorer that are running.
The response I get in a message box is:
System__ComObject, not the window title.
Thanks again
Graeme Guildford
I am always greteful for any help!
|
|
|
|
|
GuildfordG wrote: I've added the following code to a test project
What code?
|
|
|
|
|
sorry here is the code...
Dim objShellWindow As Shell
objShellWindow = New Shell
objShellWindow = CreateObject("Shell.Application")
MsgBox(objShellWindow.Windows.ToString)
I am always greteful for any help!
|
|
|
|
|
i want to give color of perticular item in menu bar when it got focus in vb6
can any one suggest me how to do it
|
|
|
|
|
This would involve ownerdrawing the menu since VB6 doesn't expose any properties to do this for you.
This[^] is about the only example I could find. VB6 examples are getting harder and harder to come by since it's been a dead language for some time now.
|
|
|
|
|
--> How to change Windows XP theme from vb.net application...?
J A Nasir K
|
|
|
|
|
Go to project properties in the IDE
In application tab u will find "Windows application framework properties"
There you have a option for Enable Xp visual style
Hope that this is what you exactly was asking
Good Luck
|
|
|
|
|
I think he was wanting to change the actual theme that windows is using.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|