|
Hi,
you shouldn't worry about having classes around; classes are just code (and some static data).
It is when you create one or more instances of a class, that objects get created; these may or may not hold lots of data, up to the point of being relevant. However, as soon as the last reference to such object has disappeared (when the object is no longer considered "alive"), the garbage collector can (and will) destroy it the next time the GC runs.
If you insist on worrying about it, you could:
- pass the parameters (URL and imageName) to the GetFile() method, so it does not need any class members; that allows you to make it static/shared, and hence you no longer need to instantiate that class;
- move the GetFile method to the BackgroundRetrieveProcess class; there is no real need to have it in a separate class!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thanks Luc
|
|
|
|
|
Hi everyone,
I've written a visual basic gui program (using visual studio 2008 (.net)) and simply placed a button on it which, when pressed, activates the print screen of the active window and it then opens powerpoint, adds a slide, and it's then suppose to paste the image. A new slide gets created each time the button is pressed, and the image is supposed to be pasted to the new slide.
The first iteration seems to work fine, but subsequent presses of the button yields the following error:
"System.Runtime.InteropServices.COMException (0x80048240): Shapes (unknown member) : Invalid request. Clipboard is empty or contains data which may not be pasted here. at Microsoft.Office.Interop.PowerPoint.Shapes.Paste()"
Other times the code goes an unlimited amount of button presses with no error, but when this occurs, the image is only updated every other button press. Any ideas?
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Core
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Public Class Form1
' Start PowerPoint.
Public ppApp As PowerPoint.Application
' Start counting number of times the take image button has been pressed by the user.
Public num_times_pressed = 0
' Add a new presentation.
Public ppPres As PowerPoint.Presentation
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
num_times_pressed = num_times_pressed + 1
If num_times_pressed = 1 Then
ppApp = CreateObject("Powerpoint.Application")
' Make it visible.
ppApp.Visible = True
ppPres = ppApp.Presentations.Add(MsoTriState.msoTrue)
ppApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
End If
' Add a new slide.
Dim ppSlide1 As PowerPoint.Slide
Dim SlideCount As Long
SlideCount = ppPres.Slides.Count
ppSlide1 = ppPres.Slides.Add(SlideCount + 1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank)
Me.Hide()
SendKeys.SendWait("%{Prtsc}")
ppSlide1.Select()
ppSlide1.Shapes.Paste()
Me.Show()
End Sub
End Class
Thanks!
|
|
|
|
|
If the error says Clipboard is empty, then most likely SendKeys.SendWait("%{Prtsc}") does not always correctly do what is supposed to.
After the SendKeys bit, you could try checking the contents of the clip board first (My.Computer.Clipboard ), to see if the print screen was actually performed, and there is a picture to be pasted. If there isn't you just perform the SendKeys again, until the clipboard contains a picture.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi John,
Thanks for replying. The image is there because I can go to paint and paste it.
|
|
|
|
|
Hi, dear all,
I am using VB6. I am running a program created years ago. when I open a form, I got the following error:
Line 75: Property OleObjectBlob in dirDDBox could not be set.
Line 75: Cannot load control dirDDBox; license not found.
Line 83: Property OleObjectBlob in dirListBox could not be set.
Line 83: Cannot load control dirListBox; license not found.
Are dirDDBox and dirListBox shipped with VB6? or belong some other control that need register?
After I run VB6Cli.exe utility, still got the same error.
Can anybody help me. Thanks a lot.
|
|
|
|
|
Are those the names of the variables for instances of those controls? They don't look like the standard controls that ship with VB6. Neither expose a OleObjectBlob property.
|
|
|
|
|
Dave,
I look at the codes again, they should be variables, but I cannot make sure what are the control type of them since I cannot open the form, whenever I open the form, I got the error message.
What should I do in this case?
Thanks!
|
|
|
|
|
Open the file for the form in Notepad. It's just a text file.
|
|
|
|
|
Dave,
Thanks.
the dirDDBox variable is with PTxSCP.PTxShCombo type, and dirListBox is with PTxSCP.PTxShList.
The PTxSCP is third party contril from Plasmatech Software.
I register PTxSCP.ocx, but when I compile the program I got error, Permission denied.
Do you have any idea about this control?
|
|
|
|
|
Never heard of it.
You can reregister the control all you want. What's missing is some license data from the registry that gives you a design-time license so you can create your own apps with it in Visual Studio. I'd dig up the old installers if you can. Otherwise, it's going to be a trip to the vendor to get the fix.
|
|
|
|
|
Dave,
I already reregister the .ocx file, but still has error. I will register the vender's forum to see if I can get any help.
If you have any idea about my question, please tell me.
Thank you very much.
|
|
|
|
|
Dave,
My problem is solved now. I need to run a setup.exe file from Plasmatech to access their control.
Thank you very much for your help.
|
|
|
|
|
I have attached below the code I am using, it works... for the most part, there are 4 drop downs that drive the data, one is independent the "store" drop down, it works fantastically, however the other three dropdowns, are from the same table, it will allow the user to select UPC, SKU, or title, and populate the remaining data. The problem is I want to have the other 2 of the 3 also populate to the selected item. I get an error, if I try to change it after the first time I get the following error.
Column 'TITLE' is constrained to be unique. Value 'System.Data.DataRowView' is already present.
Any help would be greatly appreciated, it has to be something simple, this coded is all in VB 2010.
Thanks
Andrew
'populates store data from store table
Private Sub StoreList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StoreList1.SelectedIndexChanged
Dim ItemSelected As String
ItemSelected = StoreList1.SelectedValue
Dim stdv As DataView
Dim i As Integer
Dim val(0) As String
Dim st As New bL_vmi_calculatorDataSet._Master___StoreDataTable
stdv = New DataView(st)
stdv.Sort = "Store"
val(0) = ItemSelected
i = stdv.Find(val(0))
RegionTextBox.Text = DataTableReader.Equals(i, 1)
End Sub
'populates titles info from master title list table with TITLE
Private Sub TitleBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TitleBox1.SelectedIndexChanged, TitleBox1.SelectedValueChanged
Dim ItemSelected As String
ItemSelected = TitleBox1.SelectedValue
Dim tldv As DataView
Dim j As Integer
Dim val(1) As String
Dim tl As New bL_vmi_calculatorDataSet.Master_title_listDataTable
tldv = New DataView(tl)
tldv.Sort = "TITLE"
val(1) = ItemSelected
j = tldv.Find(val(1))
PUBLISHERTextBox.Text = DataTableReader.Equals(j, 0)
'UPCbox1.Enabled = False
'SKUBox1.Enabled = False
End Sub
'populates titles info from master title list table with UPC
Private Sub UPCbox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UPCbox1.SelectedIndexChanged
Dim ItemSelected As String
ItemSelected = TitleBox1.SelectedValue
Dim tldv As DataView
Dim j As Integer
Dim val(0) As String
Dim tl As New bL_vmi_calculatorDataSet.Master_title_listDataTable
tldv = New DataView(tl)
tldv.Sort = "UPC (12 Digit)"
val(0) = ItemSelected
j = tldv.Find(val(0))
PUBLISHERTextBox.Text = DataTableReader.Equals(j, 3)
'TitleBox1.Enabled = False
'SKUBox1.Enabled = False
End Sub
'populates titles info from master title list table with SKU
Private Sub SKUBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SKUBox1.SelectedIndexChanged
Dim ItemSelected As String
ItemSelected = TitleBox1.SelectedValue
Dim tldv As DataView
Dim j As Integer
Dim val(2) As String
Dim tl As New bL_vmi_calculatorDataSet.Master_title_listDataTable
tldv = New DataView(tl)
tldv.Sort = "BL SKU"
val(2) = ItemSelected
j = tldv.Find(val(2))
PUBLISHERTextBox.Text = DataTableReader.Equals(j, 1)
'UPCbox1.Enabled = False
'TitleBox1.Enabled = False
End Sub
modified on Tuesday, May 11, 2010 12:14 PM
|
|
|
|
|
Which line exactly produces the error? Is the actual code inside a try catch block?
By the look of the error, it does not happen anywhere in the code that you posted here. More likely in the piece of code that updates the dataview, or adds new rows, or something like that.
My advice is free, and you may get what you paid for.
|
|
|
|
|
It is on the second select, If I select the title, it populates just fine, but when I select another title or UPC or SKU I get the error.
I am fairly positive that its an update issue, so update the data on select?
|
|
|
|
|
The first thing you need to do is move all the code away from the event handlers. In other words, when a selected index changes or something all you want to do is pass the selected value to a global variable.
Create a separate sub with the code (that way you only need to check it one place), and call that sub in the event handlers.
I am not entirely sure, but I have a feeling that the error is caused by creating new datatables and dataviews all the time, instead of adapting a single on.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Works like a champ thanks, I also had to rebind all my fields
|
|
|
|
|
First issue I see...you handled both the SelectedIndexChanged and SelectedValueChanged event for the TitleBox1 control. That means that event will actually fire twice.
Second, you're wasting memory with your array declarations...as in
Dim val(2) As String
That actually creates an array with 3 values, when all you need is one. I understand that you used 0 for one item, 1 for another and 2 for the other, but that's completely unnecessary.
Actually, it's completely unnecessary to have val or ItemSelected. It's a waste of memory. You could just do:
j = tldv.Find(TitleBox1.SelectedValue)
I also don't understand what you're trying to populate PUBLISHERTextBox with. Your comments at the beginning say
for all of the last three methods, but you actually populate it with different columns.
And, I agree with the other responder...you shouldn't be creating new DataViews and repopulating each time.
And his question about where does it occur, meant on which line does the error occur? Yes, you've said it's the second time you do it, but on which line do you get an error the second time?
Also, do you realize that in your SKU and UPC methods, you get your ItemSelected from TitleBox1?
Private Sub SKUBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SKUBox1.SelectedIndexChanged
Dim ItemSelected As String
ItemSelected = TitleBox1.SelectedValue
Is that what you meant to do? Because if you didn't select anything from TitleBox1 the before the others, there will be no value in TitleBox1.
|
|
|
|
|
It works; I will look into streamlining the "memory" used. I have the publisher text, driving everything else as the data is coming from the same source, I don’t want it to look and populate off of another “combo box” field.
My utility is controlled by two tables, the store table that has only the store to select, the other “input” is the title table, and the user can select the SKU, UPC or title to drive that portion.
The next step the program references the sales and inventory data for the store, moth on the selected item and for the total departments QTY or the same category of goods.
I am trying to make this as user friendly and “fool” proof as most of the people using this might have a partial high school education at best.
|
|
|
|
|
Hi everyone,
I have a batch file same as below
SET INSTANCE=%1<br />
SET DatabaseName=%2<br />
SET USR_ID=%3<br />
SET USR_PWD=%4<br />
SET ScriptName=%5<br />
SET OutFile="C:\Output.out"<br />
SQLCMD -S %INSTANCE% -d %DatabaseName% -U %USR_ID% -P %USR_PWD% -i %ScriptName% -o %OutFile&
I would like to run this batch file in my vb application.
Could you please advise me how can I run and pass the arguments to this batch file?
Best Regards,
Orchid
|
|
|
|
|
Load path to bat file and then open this file as a new process.
Dim Location as New Process
Dim myProcess as new Process;
myProcess.Start(Path & ".BAT")
|
|
|
|
|
There are two ways to do this (that I know of):
1. Open the batch file, read through it, edit the text as needed (most elegant solution)
2. Create a new batch file each time and run it (most practical solution)
Finally use Abhinav's trick to launch the bat file.
My advice is free, and you may get what you paid for.
|
|
|
|
|
try this one first:
Process.Start("batchFile.bat", "all the parameters");
and if that does not work, try:
Process.Start("cmd.exe", "/C batchFile.bat all the parameters");
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thanks a lot for the all answers,
I wrote below codes in my application:
<br />
<code> Dim BatchFile as string ="C:\RunScript.bat"
Dim StrView As String = "C:\Myview.sql"
Dim psi As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo(BatchFile, String.Format("-S {0} -d {1} -U {2} -P {3} -i {4}", txtMachineName.Text, txtSourceDB.Text, txtUserName.Text,txtPassword.Text, StrView ))
Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()
proc.StartInfo = psi
proc.Start()
When I run the application, all the above codes are executed but when I check the result, it seems that the batch file does not run.
Is there any problem in my code?
Could you please give me an example.
To Luc:
Thanks for reply, but I do not understand exactly what does below code mean?
Process.Start("cmd.exe", "/C batchFile.bat all the parameters");
Could you please give me an example.
Many thanks,
Orchid
|
|
|
|
|