|
In VB6 when you do
set frm2 = new Form2
frm2.show()
do you have to delete memory etc like in c++
|
|
|
|
|
yes.its good if you do.
set frm2=nothing
Kanchana
|
|
|
|
|
|
Setting the object to Nothing when you're done with it is good practicec, but not mandatory. The VB runtime will clean up objects that fall out of scope for you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
VB6 is a memory managed language. There is no "delete".
The object will be deleted as soon as it's no longer referenced. This can occur when the last reference goes out of scope or is set to Nothing. And, unlike Java and .NET, the class' destructor will immediately be called just like how it is in C++.
Forms are treated a little differently in VB6. You can "mostly" force them out of memory by calling Unload like this...
Unload frm2
Once you do this, you can't use frm2 again. So in this case, you might as well as set it to Nothing, replace it with a new form reference, or just let the variable go out of scope.
|
|
|
|
|
how about connection and recordset object? Do we need to call the close method and set the object to nothing?
When to call open and close method of connection and recordset object in a procedure/function with try catch? Is it ok to put in "finally" ?
Thanks
WiL
|
|
|
|
|
shiroamachi wrote: how about connection and recordset object? Do we need to call the close method and set the object to nothing?
You absolutely must Close them. You do not have to set them to Nothing. They'll be removed from memory as soon as they go out of scope.
shiroamachi wrote: When to call open and close method of connection and recordset object in a procedure/function with try catch? Is it ok to put in "finally" ?
Uhhh... VB6 doesn't have try/catch functionality. Sounds like you're talking about VB.NET. If you are, then Finally is a good place to call Close.
|
|
|
|
|
my bad. topic starter talking about VB6. I'm asking about VB.Net
is there a way to check a recordset is open or not ?
here's a case
try<br />
dim con as connection<br />
dim rs as recordset<br />
con.open()<br />
rs = con.execute(sqlstring)<br />
<br />
catch ex as Exception<br />
<br />
msgbox "error"<br />
exit sub<br />
<br />
finally<br />
<br />
rs.close()<br />
con.close()<br />
<br />
end try
assume there's error in con.open() and the error was catch and then do finally. in finally, because of rs is not yet open, will cause error cant close object that isnt open. How to resolve this problem?
Thank
WiL
|
|
|
|
|
shiroamachi wrote: assume there's error in con.open() and the error was catch and then do finally. in finally, because of rs is not yet open, will cause error cant close object that isnt open. How to resolve this problem?
First, put the DIM statements before the Try since the variables won't have scope outside the Try block.
Second, in the Catch block determine whether or not the Connection object is open by using something like this:
if con.State = adStateOpen then
con.Close()
end if
I did this from memory so you'll need to check the exact syntax.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
I believe the "adStateOpen" constant is from VB6's ADO.
In ADO.NET it should be like this...
If (con.State <> ConnectionState.Closed) Then
con.Close()
End If
|
|
|
|
|
I am using a windows form datagrid and a datatable is used as the datasource.I want to prevent deletion of the first row.I tried with datatable's rowdeleting event.But i was not able to reject the changes.Can any one help.I'm pasting the code that i tried
Private Sub DataTable_RowDeleting(ByVal sender As System.Object, ByVal e As System.Data.DataRowChangeEventArgs)
If e.Action = DataRowAction.Delete Then
If dgGrid.CurrentCell.RowNumber = 0 Then
e.Row.RejectChanges()
CType(sender, DataTable).AcceptChanges()
End If
Else
e.Row.AcceptChanges()
End If
End Sub
Anup
|
|
|
|
|
can I upload data to a server from a vb.net windows-app? I know how to upload but I don't know how to LOG into my ftp server to upload file. please it's important
|
|
|
|
|
ok.I found the solution.bye
|
|
|
|
|
Hello All
I want to manually enter items in the combox as:
cbo.Items.Add("Item1")
cbo.Items.Add("Item2")
How i can add ValueMember Field data manually? As we have an option in VB6 as:
cbo.AddItem ("Item1")
cbo.ItemData(cbo.NewIndex) = 1 'How this can be done in VB.Net?
cbo.AddItem ("Item2")
cbo.ItemData(cbo.NewIndex) = 2 'How this can be done in VB.Net?
Regards
|
|
|
|
|
How to open the start menu on the desktop and the windows task manager.
|
|
|
|
|
confusing,
make your question clear.
openning with vb or not.
to open taskmgr you can use shell("taskmgr.exe") otherwise press CTRL+ALT+DEL
Kanchana
|
|
|
|
|
You're looking for the Shell Automation object. Add a reference to the Shell32.dll, usually found in C:\Windows\System32. In your code, you do something like this:
Imports Shell32
.
.
.
Public Class Form1
Private Sub Button1_Click(blah, blah) Handles Button1.Click
Dim myShellObject As New Shell32.Shell
myShellObject.Open(ShellSpecialFolderConstants.ssfDRIVES)
End Sub
End Class
You can find out what all the special folder constants refer to here[^] on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I want to integrate my webbased or VB applications to a Label Printer for printing the Employees Address alone. Pls Can anyone help me to how to acheive this..Pls help
Thanks In Advance
Ram
|
|
|
|
|
A label printer is no different than an inkjet or laser printer. The paper is just a lot smaller. What part of this are you having a problem with?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i want to connect a lamp to my pc via com1 or any ports and write a simple code using vb.net to control on/off???
|
|
|
|
|
|
I assume your talking about an LED and not a 110/220V light bulb!
First, the serial port is a bad choice to connect an LED to. It's cumbersome to control since most signals only last a fraction of a second on the serial port and there are only a few lines that will actually hold a signal up or down. The better choice for this would be the Parallel port. You can find many exmaples of this on the web.
A good example, complete with LED's and switch inputs, can be found at http://www.logix4u.net[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
<br />
Friend Sub renderPicture()<br />
Dim previewFile, tempPreviewFile As String<br />
Dim numberOfSelectedItem As Integer<br />
Dim bitmapSource As Bitmap<br />
Dim graphicDestination As Graphics<br />
Dim selectedFileName As String<br />
Dim scale As Single<br />
<br />
If Not picPreview.Image Is Nothing Then<br />
picPreview.Image.Dispose()<br />
End If<br />
<br />
If Not bitmapDestination Is Nothing Then<br />
bitmapDestination.Dispose()<br />
End If<br />
<br />
numberOfSelectedItem = lstFiles.SelectedItems.Count<br />
<br />
If numberOfSelectedItem > 0 Then<br />
Dim dummy = lstFiles.SelectedItems.Item(numberOfSelectedItem - 1)<br />
previewFile = UCase(previewCachePath).Replace("SCANNED FILES", "SCANNE~1") & Mid(dummy, 1, Len(dummy) - 4) & "001.png"<br />
tempPreviewFile = UCase(previewCachePath).Replace("SCANNED FILES", "SCANNE~1") & Mid(dummy, 1, Len(dummy) - 4) & "[t].png"<br />
If System.IO.File.Exists(previewFile) Then<br />
If Not System.IO.File.Exists(tempPreviewFile) Then<br />
System.IO.File.Copy(previewFile, tempPreviewFile)<br />
End If<br />
End If<br />
<br />
Try<br />
bitmapSource = New Bitmap(Bitmap.FromFile(tempPreviewFile))<br />
Catch ex As Exception<br />
Module1.setErrMsg(ex.Message)<br />
Exit Sub<br />
End Try<br />
Select Case cmbZoom.Text<br />
Case "150%"<br />
scale = CSng(1.5)<br />
Case "125%"<br />
scale = CSng(1.25)<br />
Case "100%"<br />
scale = CSng(1.0)<br />
Case "75%"<br />
scale = CSng(0.75)<br />
Case "50%"<br />
scale = CSng(0.5)<br />
Case "25%"<br />
scale = CSng(0.25)<br />
Case "Fit Width"<br />
scale = CSng((panPreview.Width - 17) / bitmapSource.Width)<br />
Case Else<br />
Module1.setErrMsg("Error on Wrong Zoom Scale")<br />
Exit Sub<br />
End Select<br />
<br />
'If scale = CSng(9.9) Then<br />
' scale = CSng((picPreview.Width) / bitmapSource.Width)<br />
'End If<br />
bitmapDestination = New Bitmap(CInt(bitmapSource.Width * scale), CInt(bitmapSource.Height * scale))<br />
graphicDestination = Graphics.FromImage(bitmapDestination)<br />
graphicDestination.DrawImage(bitmapSource, 0, 0, bitmapDestination.Width + 1, bitmapDestination.Height + 1)<br />
picPreview.Width = bitmapDestination.Width<br />
picPreview.Height = bitmapDestination.Height<br />
picPreview.Image = bitmapDestination<br />
bitmapSource.Dispose()<br />
graphicDestination.Dispose()<br />
Else<br />
picPreview.Image = Nothing<br />
End If<br />
End Sub<br />
When I go thorugh this function to repeat the same picture Time by time,
The memory accumulate 3MB each time!!
Anyone can help me to see what the problem is??
How can I improve it?
|
|
|
|
|
|
And stop looking at TaskManager to see how much memory your using. You're actually seeing how much memory the CLR's virtual machine is holding onto, NOT much much memory your app is actually using. Use the Performance Monitor and the .NET CLR Memory counters if you want to see how much memory your app is using.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|