|
On the memory side of things, is it better to use the second example versus the first one, or does it not really matter in the end?
How is memory allocated in the two situations? Will the first one create a ton of objects that get cleaned up after they drop out of scope? Will this affect memory and garbage collection?
For i As Integer = 0 To costTable.Rows.Count - 1
Dim row As DataRow = costTable.Rows(i)
'use the data in the row
Next
Dim row As DataRow = Nothing
For i As Integer = 0 To costTable.Rows.Count - 1
row = costTable.Rows(i)
'use the data in the row
Next
modified on Saturday, August 23, 2008 2:08 PM
|
|
|
|
|
I'm not sure, but I think that it doesn't matter ... That they're the same ...
|
|
|
|
|
The generated code for the both examples will be exactly the same, except that the variable will be assigned a null value before the loop in the second example.
The variable is allocated on the stack, which is very cheap. No objects are created, so there is no garbage collection involved at all. The scope of the variable differs between the examples, but that only matters to the compiler. All local variables are always allocated when the stack frame for the method is created, regardless of where in the method the variables are declared.
Unless you need the counter variable for something else, I would recommend that you use ForEach instead:
ForEach row As DataRow in costTable.Rows
'use the data in the row
Next
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the excellent explanation.
I understand there are certain precautions to using a foreach, sometimes it can create overhead from an enumerator. Is there an easy way to know the difference?
|
|
|
|
|
The ForEach loop uses an enumerator, however the enumerator is usually a struct so it's allocated on the stack.
The performance difference between a ForEach loop and using a counter is quite small, and it depends on the situation whichever is faster. Unless you have an actual performace problem, you should just use the one that best fits your needs.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Monday, August 25, 2008 6:21 PM
|
|
|
|
|
Hey,
I'm trying to get my program to launch from a file with an associated extension and have the program immediately load that file.
I've already figured out how to register the extensions thanks to the article at http://www.codeproject.com/KB/vb/VBFileAssociation.aspx[^]. If I doubleclick the external file, my app does successfully launch, but I'm having difficulty getting it to actually load the external file.
So far I think my best bet is to use Application.CommandLineArgs, but I'm not having any luck implementing it. I've tried using the following code, but haven't had any success:
Friend myArgument As String = ""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
myArgument = My.Application.CommandLineArgs(0)
Catch ex As Exception
If myArgument <> "" Then
InputFile(myArgument)
End If
End Try
...
Does anyone have any ideas? Thanks a bunch!
|
|
|
|
|
Why do you have the InputFile() in the Catch block? Just check to see if there is an argument, and if there is get it:
If My.Application.CommandLineArgs.Count > 0 Then
Dim file As String = My.Application.CommandLineArgs(0)
MsgBox(file)
End If
Then you can do whatever you want with it.
|
|
|
|
|
Hello,
How can I avoid connecting to a database through a connection string? Because everytime I change the database location I should set a new connection string with the new location.
Is there a way to avoid this and save the database within the project itself? And keep the connection there no matter where I install the database? Can I still select, update, delete ... from the database?
John,
|
|
|
|
|
you can set connection string in ur web config file
|
|
|
|
|
If only this was for ASP.NET...
|
|
|
|
|
John,
Maybe you should check out SQL Server Compact Edition[^]. "SQL Server Compact is a free, easy-to-use embedded database engine that lets developers build robust Windows Desktop and mobile applications that run on all Windows platforms including Windows XP, Vista, Pocket PC, and Smartphone."
You can also use SQL Server Express Edition (on localhost) and use a connection string that attaches the database each time you want to connect:
Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
|
|
|
|
|
Check the following link out it would be helpful for you:
Secure Connection and Easy transaction Handling^
In the above link the connection string is read through DBConfig.ini and when you change the database location just change it in the ini file and would work perfectly for your web or desktop applications.
|
|
|
|
|
I'd do something different from the other suggestions listed. I'd create a UDL file within your application directory. Your program will read the UDL for the connect string. If you run your app on another computer/domain, you can easily update the connect string through the UDL's GUI (eliminates the possibility of manually entering in the connectstring in a file and making a mistake).
Right click on your desktop and create a .txt file. Rename the file to something like test.udl. Double click it and you'll see what I'm getting at.
There's numerous articles on how to read a udl if you need help.
Cheers!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
|
|
|
|
|
Store your connection string in the application settings and set all connection objects to the application setting
To store an app setting:
Right click your project > properties > settings > add your connection string
Alexei Rodriguez
|
|
|
|
|
Under is some code of C#, i would like all of you to show me how can to VB.net because i don't know C# at all and i don't know this code as well.
Thanks for your help...
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
allStands = new List[] { Stand1plates, Stand2plates, Stand3plates };
// Stand2plates.Add(3);
}
List[] allStands;
List Stand1plates = new List();
List Stand2plates = new List();
List Stand3plates = new List();
private void MoveFromTo(int source, int dest)
{
int top = allStands[source-1][allStands[source-1].Count - 1];
allStands[source - 1].Remove(top);
allStands[dest-1].Add(top);
RedrawPanels();
}
=================================
I change it to VB.net as bellow:
Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
' Stand2plates.Add(3);
allStands = New List() {Stand1plates, Stand2plates, Stand3plates}
End Sub
Private allStands As List(Of Integer)
Private Stand1plates As New List(Of Integer)
Private Stand2plates As New List(Of Integer)
Private Stand3plates As New List(Of Integer)
Private Sub MoveFromTo(ByVal source As Integer, ByVal dest As Integer)
Dim top As Integer = allStands(source - 1)(allStands(source - 1).Count - 1)
allStands(source - 1).Remove(top)
allStands(dest - 1).Add(top)
RedrawPanels()
End Sub
End Sub
but it has error where underline. what's problem ? How do i change it ?
VB.Net
|
|
|
|
|
Sovann wrote: error where underline
What underline?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
sorry it's not show the underline i put tag but it not show.
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
allStands = new List[] { Stand1plates, Stand2plates, Stand3plates };
// Stand2plates.Add(3);
}
List[] allStands;
List Stand1plates = new List();
List Stand2plates = new List();
List Stand3plates = new List();
private void MoveFromTo(int source, int dest)
{
int top = allStands[source-1][allStands[source-1].Count - 1];
allStands[source - 1].Remove(top);
allStands[dest-1].Add(top);
RedrawPanels();
}
=================================
I change it to VB.net as bellow:
Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
' Stand2plates.Add(3);
allStands = New List() {Stand1plates, Stand2plates, Stand3plates}
End Sub
Private allStands As List(Of Integer)
Private Stand1plates As New List(Of Integer)
Private Stand2plates As New List(Of Integer)
Private Stand3plates As New List(Of Integer)
Private Sub MoveFromTo(ByVal source As Integer, ByVal dest As Integer)
Dim top As Integer = allStands(source - 1)(allStands(source - 1).Count - 1)
allStands(source - 1).Remove(top)
allStands(dest - 1).Add(top)
RedrawPanels()
End Sub
End Sub
VB.Net
|
|
|
|
|
I am trying to develop a ambitious program, that moves a telescope and much more. I need to access the ascom interface. It is accessible with vbscript 5. I understand I need to call a vbscript from within my vb2005 program and have the control return back to the program. I understand this is done using a thread.
Can someone point me in the right direction?
modified on Friday, August 22, 2008 11:15 PM
|
|
|
|
|
Do you have the script to run as a .vbs file? You can run the .vbs file by executing cscript.exe and passing the name of the .vbs file as an argument. Check out the System.Diagnostics.Process class. Also, that class has a WaitForExit() method which will allow the .vbs script to finish executing before returning control to your VB program.
|
|
|
|
|
I am working with VB.Net 2005 and I am re-writing a small program that was in VB6 format. I currently have a Dataset looking at my Access database. In the old code it used these statements to look at the database.
Public dbComp As DAO.Database
Dim qdf As DAO.QueryDef
Dim tdf As DAO.TableDef
The routine that I am working with looks at the database (dbComp) and it deletes quries and creates them and then populates them.
I am hoping that I can use my existing Dataset that I created instead of using these DAO connections. Can anyone help me out with this? I just need to know what I can use in .Net in place of those commands above.
Thank you in advance for any help you can provide!
|
|
|
|
|
You can certainly use ADO.Net and OLEDB via DataSets and DataViews to retrieve, update, insert or delete records in an Access database from .Net.
However, you can not use ADO.Net to create an Access database, or any of the objects (tables, queries, etc.) in an Access database. One way to create an Access database and table objects from .Net would be to first create references to, and corresponding InterOps for, Microsoft ActiveX Data Objects. I imagine that a google will turn up lots of examples on creating Access databases and tables from .Net after making the proper references to ActiveX Data Objects.
Good luck with your project.
|
|
|
|
|
Another way to create an Access database without all of that hassle:
If you know the basic structure of the Access Database, then you create the basic 'template' in Access and then embed the database into your application. Then through the use of File.IO and Reflection you can stream the template to a local file for alteration. (It is simpler than it may sound).
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
hi evryone
i am developping a window application and i need to use the crystal report to generate reports
i have 2 databases named : Butterfly and Butterfly_Test
Butterfly is used to real Data
Butterfly_Test is used for testing
i am using this code to load the report
Dim myDbConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
With myDbConnectionInfo
.ServerName = Glbl_Conn_Config.Server_Name
.DatabaseName = Glbl_Conn_Config.Database_Name
.Password = Glbl_Conn_Config.Password
.UserID = Glbl_Conn_Config.Login
End With
Dim myTableLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim myDatabase As CrystalDecisions.CrystalReports.Engine.Database = My_Report.Database
Dim myTables As CrystalDecisions.CrystalReports.Engine.Tables = myDatabase.Tables
Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
For Each myTable In myTables
myTableLogonInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myDbConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
'
' Get the report parameters collection.
'
crParameterFieldDefinitions = My_Report.DataDefinition.ParameterFields
' Add a parameter value - START
crParameterFieldLocation = crParameterFieldDefinitions.Item("@Language")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterValues.Clear()
crParameterDiscreteValue.Value = 1
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
Me.CrystalReportViewer1.ReportSource = My_Report
Me.CrystalReportViewer1.PrintReport()
evrything work fine when Glbl_Conn_Config.Database_Name = Butterfly_Test
once i changed into Butterfly i have an error on loading report:
Procedure or function SP_Select_All_User Expect Parameter @Language
Can please any one help me
waelhawari
|
|
|
|
|
Waoula,
Check the connection type your report uses internally when you designed it. Crystal likes to flake out when using certain connections. Try using the OLE DB (ADO) connection as a datasource when designing the report. Easiest way to change the datasource internally is by using the Set Datasource Location function, otherwise you will have to recreate some of the report.
Let me know if that helps at all.
|
|
|
|
|
Is there away for us consumers to take back control of our mice? What I am referring too is the middle "scroll wheel." I am totally fed up when viewing a web page and trying to scroll down, where suddenly my mouse becomes stuck in quick sand and "recovery is futile." I have to move the mouse out of the little advertising window before my scroll wheel will work again. This is hijacking plain and simple and I would like full control of my mouse at all times. HELP!
PS: I think the feature is something to do with "disabling flyouts" but I am not positive.
Dennis
|
|
|
|