|
Hi I have written code to check whether Cd inserted or not in drive using WMI wuery and VB6.
But while executing the code it throwing an error in while entering into 'For each' loop i.e <b>Runtime error '-21456793':Automation error.</b>
Can any one please help me to find out the solution for this.
Private Sub Command1_Click()
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from __InstanceModificationEvent Within 1 Where TargetInstance ISA 'Win32_CDROMDrive' and TargetInstance.MediaLoaded = True and PreviousInstance.MediaLoaded = False ")
For Each objItem In colItems
MsgBox "Device ID: " & objItem.DeviceID
MsgBox "Media Loaded: " & objItem.MediaLoaded
Next
End Sub
Thanks in advance
|
|
|
|
|
Please help! I'm not a script wrriter, I used skript form "scripting Guys" to extract text marked in certain color from Word document, and it works great for any color. Then I got Word 2007 and now same script works only with color "Red", none of other font colors does work. If I use "brush tool" and apply, let say color "blue" or, any other, from my old document made in Word 2003, script works, but when I use colors from Word 2007 manu it does not. Below is the script (this one for Red and the only one that works):
Const wdColorRed = 255
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open("C:\Scripts\Form name for test.doc")
Set objSelection = objWord.Selection
Set objDoc2 = objWord.Documents.Add()
Set objSelection2 = objWord.Selection
objSelection.Find.Forward = True
objSelection.Find.Format = True
objSelection.Find.Font.Color = wdColorRed
Do While True
objSelection.Find.Execute
If objSelection.Find.Found Then
strText = strText & objSelection.Text & vbCrLf
Else
Exit Do
End If
Loop
objSelection2.TypeText strText
Thanks!
|
|
|
|
|
Apparently you have to specify a new color value to search for. 255 would indicate Red. This value has to be changed to the color value you need.
That first line could be rewritten as:
Const wdColorRed = RGB(255, 0, 0)
You need to specify either the integer value for the color you want, or the three integers inside the RGB function to build the color value for you. Each component of those would be in the range 0 to 255.
|
|
|
|
|
Hi,
I'm doing a project on generating a Crystalreport and viewing it in a pdf format. I'm using vb.net and sql server (2008).
I have managed to create the crystalreport, save it in local directory then view it. I would also like to save the pdf file into my sql database. This, for me, is the difficult part and also the part which i'm stuck now.
Hope there will be someone who can help me!
Thanks in advance.
|
|
|
|
|
The image datatype in SQL Server allows you to store files. Google 'store files in SQL Server database' and you should see lot of examples describing how to do this.
|
|
|
|
|
i want to create report using datareport in vb6 which is the result of a query. i have a text box in one of my form and in this a have made a command button "generate report". when the user enter a value in this text box say it is name of a student, the rows which match to this value will be displayed in the report when the user click the command button.please help me urgently....
|
|
|
|
|
Could someone explain how to properly use the .contains and .find methods on generic list? For example, I created a list(of reportparameter) below and fill it with some dummy test values. I can't get either the .contains or find methods to work.
Dim params As New List(Of Microsoft.Reporting.WinForms.ReportParameter)
params.Add(New Microsoft.Reporting.WinForms.ReportParameter("Param1", "ParamValue1", False))
params.Add(New Microsoft.Reporting.WinForms.ReportParameter("Param2", "ParamValue2", False))
params.Add(New Microsoft.Reporting.WinForms.ReportParameter("Param3", "ParamValue3", False))
'Compiles, but never returns true. Is it correct to create a new param to execute .contains?
If params.Contains(New Microsoft.Reporting.WinForms.ReportParameter("Param1")) Then
Debug.Print("")
End If
'This doesn't compile, not sure of the correct way to perform a find
If params.Find(New Microsoft.Reporting.WinForms.ReportParameter("Param1")) Then
Debug.Print("")
End If
Sorry if this is a dumb question - having a blonde moment today.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Your problem is that you have to use the same object reference, but in your example you are creating two different objects.
The way you are doing it can only work if the Equal method is so defined that it compares the components the class with one another.
Best Regards,
-MRB
|
|
|
|
|
I don't think ReportParameter is IEquatable, so you must use your own predicate to find the item (see below code). Also, even if it were IEquatable, your code uses two different constructors (a 3-parameter constructor and a 1-parameter constructor), which would set different variables in the object, so they wouldn't be equal anyway.
Dim params As New List(Of ReportParameter)
params.Add(New ReportParameter("Param1", "Value1", False))
Dim foundParam As ReportParameter =
params.Find(New Predicate(Of ReportParameter)(Function(rp As ReportParameter) rp.Name = "Param1"))
If foundParam Is Nothing Then
Debug.Print("Doesn't contain.")
Else
Debug.Print("Does contain.")
End If
S<T>::f(U)
modified on Friday, May 6, 2011 11:30 AM
|
|
|
|
|
Outstanding. Thanks for the clear explanation and example.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Excellent answer.
The more anger towards the past you carry in your heart, the less capable you are of loving in the present.
My Blog![ ^]
|
|
|
|
|
Hi, I am trying to bind data to a combo box but it is not coming. I have two tables one for student and another for gender. The gender table has GenderID As a primary key. The values for GenderID are 1, 2, and for Gender are Male and Female. The Student table has gender which is a foreign key to table gender. I I have designed a form with gender which is a combo box. I want when I click gender on student form, I am able to pick the values in Male and Female in the drop down. I have tried using the datatable adapter but when i click the items in the list, the form freeses.
What could be wrong?
|
|
|
|
|
this example is taken from this article Database Binding a combobox[^]
ComboBox1.DataSource = objDataTable
ComboBox1.DisplayMember = "FirstName"
ComboBox1.ValueMember = "ID"
Nagy Vilmos wrote: And eat bacon. Bacon's real important for 'puters.
|
|
|
|
|
Hi All,
I have written a code to check whether the 'Removable' or 'CDRom' is ready or not.
Below is the code .
But while executing the code ,for the 'removable' its working fine means "Removable disk is ready".
When coming to CDRom its showing that "Disk is not ready" even though i have a blank CD in my Cd Drive.
loDrive.IsReady returning false for "blank CD"
loDrive.IsReady returning true for "Already data contained CD",But this is not needed in my case.
Dim loFileSystem As FileSystemObject
Dim loDrive As drive
Set loFileSystem = New FileSystemObject
For Each loDrive In loFileSystem.Drives
If loDrive.drivetype = Removable Or loDrive.drivetype = CDRom Then
If loDrive.IsReady = True Then
If loDrive.FreeSpace = 0 Then
MsgBox "There is no free space"
End If
If loDrive.FreeSpace > 1457664 Then
MsgBox "Space more then 1457664"
WriteToCDDVD ("C:\testdir\test2.txt")
End If
End If
End If
Next
Please help me in this.
|
|
|
|
|
The FileSystemObject isn't going to work for you. If will only return IsReady=Ture if there is a mounted filesystem on the disk. Since the CD is blank, there's no filesystem, hence, not ready.
You would have to use the IMAPI API[^] to do what you want.
|
|
|
|
|
What happens if you have no CD in the drive?
Nagy Vilmos wrote: And eat bacon. Bacon's real important for 'puters.
|
|
|
|
|
I have a single-thread project that's been working fine until tonight. Everything goes well until I try to close it. No error msg, it doesn't freeze. But it won't close. In VS I have to hit the Stop Debugging button. If I run it from a shortcut, I have to use Task Manager to close it (and I get a Not Responding msg).
The only changes I've made tonight was to add a tab control, one page with a WebBrowser and one with a ScintillaNet control. The ScintillaNet control was already in use and I simply moved it to a tabpage. I undid all this but the problem still exists. Closed and restarted VS and that didn't help. Commented out everything in the FormClosing sub - no effect. Other projects close without issue.
Suggestions?
If Barney Frank eats a fruitcake, is it cannibalism?
|
|
|
|
|
Open Task Manager and watch CPU load. Either your app is in an eternal loop (total CPU load = 100% divided by number of cores), or it is deadlocked (two threads waiting for a resource/lock the other is holding).
BTW: are you absolutely sure your app is single-threaded? that requires you don't use any callbacks, no timers, no asynchronous operations, no ...
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: Open Task Manager and watch CPU load. Either your app is in an eternal loop (total CPU load = 100% divided by number of cores), or it is deadlocked (two threads waiting for a resource/lock the other is holding).
CPU load stays at 4 to 8 percent.
Luc Pattyn wrote: BTW: are you absolutely sure your app is single-threaded? that requires you don't use any callbacks, no timers, no asynchronous operations, no ...
None of that stuff. I just wanted a super-simple PHP/HTML editor. Just opens, edits and saves php/html files.
It's just a temp workaround, but I added Me.Dispose at the end of the Me.Close sub and it closes without issue. That of course doesn't explain (at least not to me) why it suddenly quit closing properly. I removed this before looking at the cpu load, btw.
If Barney Frank eats a fruitcake, is it cannibalism?
|
|
|
|
|
Alan Burkhart wrote: CPU load stays at 4 to 8 percent.
Not a busy loop then.
Sounds strange.
Where are Me.Close and Me.Dispose located in your source? in some event handler?
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: Where are Me.Close and Me.Dispose located in your source? in some event handler?
The "Exit" menu item's click event:
Private Sub CloseApp() Handles menuFile_Exit.Click
Try
Me.Close()
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Exclamation, title)
End Try
End Sub
I added Me.Dispose to the end of the FormClosing event handler. Too much code to list here, but all FormClosing does is save preferences, recently used docs and open tabs. Nothing complicated. I disabled (commented) all the code in the FormClosing sub to see if something there was causing the problem. No change.
Weird, huh?
If Barney Frank eats a fruitcake, is it cannibalism?
|
|
|
|
|
weird indeed.
Here is some info you probably already know, and some suggestions:
- Closing and Closed events are obsolete, use FormClosing and FormClosed instead;
- there could be more than one handler associated with form closing;
- if form disposing at the end of FormClosing solves the problem, seems like something goes wrong inside FormClosed handler;
- you could consider calling Application.Exit() instead of Me.Close()
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Tried Application.Exit() but it didn't change anything.
I'm using FormClosing , but not FormClosed .
Only one eventhandler for FormClosing .
I gotta get off of here for tonight. Early start / long day tomorrow. I'll work on it again tomorrow. As always, thanks for your help.
If Barney Frank eats a fruitcake, is it cannibalism?
|
|
|
|
|
New ideas:
1.
any chance the ScintillaNet creates a non-background thread? does it offer methods to terminate itself, a close/dispose/whatever? if so, consider calling them in FormClosing.
2.
the change you introduced by moving the ScintillaNet from your Form to a TabPage could be this: on the Form it starts in a visible state, on any non-first TabPage it initially is invisible, therefore it might work a little differently. Experiment: change the order of the TabPages, so ScintillaNet is visible right away.
If #1 does not help and #2 does, time to contact the ScintillaNet provider.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: any chance the ScintillaNet creates a non-background thread? does it offer methods to terminate itself, a close/dispose/whatever? if so, consider calling them in FormClosing.
Never needed to do this before but tried it nonetheless. Didn't help. I disposed each ScintillaNet object individually.
Luc Pattyn wrote: the change you introduced by moving the ScintillaNet from your Form to a TabPage could be this: on the Form it starts in a visible state, on any non-first TabPage it initially is invisible, therefore it might work a little differently. Experiment: change the order of the TabPages, so ScintillaNet is visible right away.
The ScintillaNet control is on the first tabpage. I also removed the new tabcontrol so that the program was like it was before the problem appeared (ScintillaNet docked in the form). No change.
I've been using ScintillaNet in place of a TextBox for a couple of years and never encountered this before. I've swapped the StartUp form to a couple of others and they close fine. I may try creating a new form and piece meal the existing code onto it to see if I can track down the cause. Who knows? It may be that the form itself is corrupt.
If Barney Frank eats a fruitcake, is it cannibalism?
|
|
|
|