|
Hi all
I have the following piece of code where I am checking for the status of the printer. But I am not able to figure out why even while the printer is priting Printer.PrinterStatus returns 2 which corresponds to Unknown printer status
Please let me know if the code is wrong and is there any other way to check for the status of the printer.
Code is
Private Sub btnPrinter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrinter.Click
Dim PrinterSet As Object
Dim Printer As Object
Dim DefaultPrinter As Object
PrinterSet = GetObject("winmgmts://localhost")
DefaultPrinter = PrinterSet.ExecQuery("Select * from Win32_Printer Where Default = True")
For Each Printer In DefaultPrinter
MsgBox(Printer.Name & ": " & Printer.PrinterStatus)
Next Printer
End Sub
Thanks and Regards
VanitaJ
-- modified at 19:34 Monday 7th November, 2005
|
|
|
|
|
I put the code under timer event of very small duration and it worked fine.
But I dont get any other states than IDLE,UNKNOWN,PRINTING.
How to retrieve the printer state like warmingup,paper jam,toner low etc
If anyone has idea about it please let me know
Thanks and Regards
VanitaJ
|
|
|
|
|
You can't get that information because it's not exposed to the WMI methods your using. You can only the same information you see if you open the Printers folder to see the details of all the printers installed on the system.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
So can I get the required information if I use System.Management.ManagementObject class ?
~VanitaJ
|
|
|
|
|
You can't get it if the underlying provider doesn't supply that kind of status information to WMI. You'll have to use other methods to get more granular status information. This may include P/Invoking the Win32 API GetPrinter function, communicating with its driver using DeviceIo, or getting the information directly from the printer depending on how it's connected to the machine and if it supports such methods.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Hello...
I'm new to network programming and am trying to create a simple application that will allow me to send test TCP messages to a listening windows service. Here is my send function:
<br />
Function Send(ByVal message As String) As String<br />
Dim stream As NetworkStream = Nothing<br />
Dim responseData As String = ""<br />
Dim localEP As New IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000)<br />
<br />
Try<br />
<br />
' Instantiate a TcpClient with the target server and port number<br />
Dim client As New TcpClient(localEP)<br />
<br />
' Convert the data to send into a byte array<br />
Dim data As Byte() = System.Text.Encoding.ASCII.GetBytes(message)<br />
<br />
' Get the NetworkStream for the TcpClient for sending and receiving<br />
stream = client.GetStream()<br />
<br />
' Send the message to the server. <br />
stream.Write(data, 0, data.Length)<br />
<br />
' Buffer to hold data returned from the server.<br />
data = New [Byte](256) {}<br />
<br />
' Read the response from the server up to the size of the buffer.<br />
Dim bytes As Integer = stream.Read(data, 0, data.Length)<br />
<br />
' Convert the received bytes into a string<br />
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)<br />
<br />
Catch ex As SocketException<br />
MsgBox(ex.Message)<br />
Catch ex As IOException<br />
MsgBox(ex.Message)<br />
Finally<br />
<br />
' Make sure that the NetworkStream is closed.<br />
If stream IsNot Nothing Then<br />
stream.Close()<br />
End If<br />
<br />
End Try<br />
<br />
Return responseData<br />
End Function<br />
<br />
The line of code as follows...stream = client.GetStream() causes this InvalidOperationException :
The operation is not allowed on non-connected sockets.
I'm using VS 2005 Beta 2 (.NET 2.0). I have no idea what the problem is. Any ideas?
Thanks in advance!
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
You have to get connected before to do anything!!
sockSMTP.Connect(v_Remote)
Then you can do what you want. I hope it helps
|
|
|
|
|
Could anybody help me. Im trying to work out how to use a progress bar with the browser control so i can see how much of the page is loaded etc like in internet explorer.
If anybody has any demo programs or sample code or could explain it i would be grateful.
Mo.
|
|
|
|
|
I found this page[^] that gives an example of how to use a progress bar in a web browser control (VB.NET). The example uses the DownLoadBegin, DownLoadComplete, and ProgressChange events of the browser control. I didn't try the code but it looks relevant...
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
I have two combo boxes in my datagrid.
I need to be able to select a value in one (databound) combobox and have the values in the other (on the same row) change (run a new SQL statement based on the value selected and repopulate).
Have you (the reader) done this before and/or can you point me to a resource?
Let me know if I am too cryptic.....
Thanks in advance.
|
|
|
|
|
I am not sure this will help you, but in cases where I have controls whose contents change based on other controls I find most suitable to use DataViews.
|
|
|
|
|
One of the arguments that I must pass to the Function in a DLL is a pointer to an array of a structure that has a byte array in the middle of the structure with a fixed length of 256 bytes. Here is the Structure:
<StructLayout(LayoutKind.Sequential)> _<br />
Public Structure KEYBOARDINFO <br />
Public KeyboardID As Int32<br />
Public KbdName(0 To 255) As Byte<br />
Public pKeyboard As Int32<br />
End Structure
My problem is I cannot get VB to make this structure be sequential in memory since it has the KbdName(255) in the middle of it. I have tried everything I can think of and VB always puts KbdName at the end. How can I get it to be sequential, so I can pass it to the function as an argument.
Rand
|
|
|
|
|
Try applying the following attribute to your structure...
<br />
< StructLayout(LayoutKind.Sequential) > _<br />
Public Structure KEYBOARDINFO <br />
Public KeyboardID As Int32<br />
Public KbdName(0 To 255) As Byte<br />
Public pKeyboard As Int32<br />
End Structure<br />
[Edit]
Oops. This website took out the attribute in the above code on my 1st post. It should show up for you now.
[/Edit]
-- modified at 13:09 Monday 7th November, 2005
|
|
|
|
|
Thanks, but I already did that. I had it in the code I posted, but the website took it out of my code. It does not work. It makes the structure sequential except for it puts the array at the end, not in the middle where it must be.
Any other ideas?
Rand
|
|
|
|
|
How about this?
<br />
< StructLayout(LayoutKind.Explicit) > _<br />
Public Structure KEYBOARDINFO <br />
< FieldOffset(0) > Public KeyboardID As Int32<br />
< FieldOffset(4) > Public KbdName(0 To 255) As Byte<br />
< FieldOffset(260) > Public pKeyboard As Int32<br />
End Structure<br />
-- modified at 13:43 Monday 7th November, 2005
|
|
|
|
|
Thanks, but this does not work either. Again the array is always put at the end of the structure. In VB.NET you actually cannot define a fixed size array in a structure, so what I have been trying is one of these formats:
< StructLayout(LayoutKind.Sequential) > _
Public Structure KEYBOARDINFO
Public KeyboardID As Int32
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public KbdName As Byte()
Public pKeyboard As Int32
End Structure
or else this format:
< StructLayout(LayoutKind.Sequential) > _
Public Structure KEYBOARDINFO
Public KeyboardID As Int32
Public KbdName As Byte()
Public pKeyboard As Int32
End Structure
Then redim KbdName to 256 byes
Is there another way to get a fixed length array in a structure? Doing it either of these two ways I guess that VB thinks the size of the array will change, so it always forces it to the end of the structure in memory so there is room to grow.
Any more ideas?
Rand
-- modified at 14:22 Monday 7th November, 2005
|
|
|
|
|
rand19 wrote: Is there another way to get a fixed length array in a structure?
There is the VBFixedArray attribute, but it doesn't actually allocate anything. It seems to only indicate to API calls that it should be treated as a fixed array. Might be worth a try.
The thing is, an array is a reference type, not a value type. It'll never take up 256 bytes in the structure itself (in the stack). You might have to play around with marshalling to make this work.
|
|
|
|
|
I'm creating a component in VB.NET which acts as kind of a wrapper for Ms Outlook 2003 and Ms Word 2003. There are three components which can be used seperately. Now when I want to use the Outlook component, I don't want to load the Word assemblies and vice versa, but I dot want the controls within a single assembly.
Is it possibly to create the references to the required Office Interop Assemblies at runtime (in the constructors for example) so when loading my assembly, not needed office resources will be left alone?
For example, when using the Outlook control, my assembly loads Office.Core.dll and Office.Outlook.dll and NOT Office.Word.dll
I love it when a plan comes together
|
|
|
|
|
Did you try using classes in the System.Reflection[^] namespace? They allow you to load assemblies at runtime, which is exactly what you want to do.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
The previous reply hits it on the head, but be warned that if you use Word as the Outlook email editor, it will load Word components regardless.
...Steve
|
|
|
|
|
I was hoping to be able to use multiple selection upon a dropdownlist but the only info i have found is related to a dropdownlist in a datagrid. Is it possible then just to add the multiple selection to a dropdownlist the same way as when using the datagrid. thank you
gfhg
|
|
|
|
|
Dropdownlists are meant to allow user to select a single value. What you could do is cheat a little bit by displaying a ListBox on top of your combobox. To do that, capture the combobox dropdown event then call SuspendLayout of combobox, place dropdownlist on top, and call ResumeLayout of your combobox. When user is done selecting, hide the listbox.
|
|
|
|
|
Hi, I am tejaswi and having a small doubt in VB regarding the collections class.
The following code Is not working
Dim temp as new clsParameterDetail
Dim objcoll as new collection
Temp.initializeobj()
Objcoll.add( temp)
Where as if I declare it as an array ( dim temp() as new clsParameterDetail )
And after redimensioning and initializing the temp array,
It is accepting the statement (Objcoll.add(temp) )
What is the difference between an array and normal object. In case of a single object the .add is not working( giving a message like ‘property or method is not supported’) where as in case array it is accepting.
It is not even accepting sth like objcoll.add(temp(parameterCount))
but it is accepting for strings even if it is not an array .
Please clarify my count.
And one more thing is – Is CType(obj,TypeName) a function available in visulbasic or only .net ? if in vb any references to be added , this function is not available here in vb here.here if i type vba. ,all are coking like cstr e.t.c but ctype i snot coming.
|
|
|
|
|
Hi, I am tejaswi and having a small doubt in VB regarding the collections class.
The following code Is not working
Dim temp as new clsParameterDetail
Dim objcoll as new collection
Temp.initializeobj()
Objcoll.add( temp)
Where as if I declare it as an array ( dim temp() as new clsParameterDetail )
And after redimensioning and initializing the temp array,
It is accepting the statement (Objcoll.add(temp) )
What is the difference between an array and normal object. In case of a single object the .add is not working( giving a message like ‘property or method is not supported’) where as in case array it is accepting.
It is not even accepting sth like objcoll.add(temp(parameterCount))
Please clarify my count.
And one more thing is – Is CType(obj,TypeName) a function available in visulbasic or only .net ? if in vb any references to be added , this function is not available here in vb here.here if i type vba. ,all are coking like cstr e.t.c but ctype i snot coming.
|
|
|
|