|
Hi,
How to read from USB (Pendrive) content and information using vb.net???
|
|
|
|
|
You don't read from "USB". It's not a port, but is in fact, an expansion bus. You treat it just like the expansion slots on the motherboard.
You talk directly to the device attached to it, using whatever methods the device driver for the device expects. In the case of a "Pendrive", I'm assuming you mean a storage device, so, it'll show up as a disk volume. In that case, you use file system methods...
|
|
|
|
|
hi.
is there a way to query the print copy so that i can label one print to say for example. ORIGINAL and the second copy to print DUPLICATE on the header somewhere.
I've googled and can't seem to find anything like that. i can't see a routine where vb can query for COPIES . i can only see PAGEQUERY.
any help or advice would be much appreciated.
Thanks
Robbo
|
|
|
|
|
If you are printing copies, I don't think that your code will be called for each page. If you want the pages to have different headers, they are not really copies and you probably have to print them separately.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
thanks for that guffa. is there a way i can just recall the print events twice instead of setting printersetting.copies =2 ?
|
|
|
|
|
|
I have a windows a service that periodically checks the tcp/ip connection of device by pinging it and returning the status.
So for this i have used a timer.At first i tried to to dynamically create a timer using System.Timers.Timer and using the 'Elapsed'event.But the when i tried to start the service it wouldn't start.
Then I used a timer from the toolbox and seemed to start fine,the code in onstop and onstart subs is executing.However the code in timer_tick event isn't.I don't know why.I start the timer in the onstart and stop it onstop.
Below is code for the timer event.
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim api As New RfidApiLib.RfidApi
Dim status1 As Integer
Dim StrCon As String
Dim conn As SqlConnection
Dim host As String
'Dim status1 As Integer
test.WriteByDate("e:\temp", "log", "service", "reader timer this connected") ' Writes to log file
'mylog.WriteEntry("Connected", EventLogEntryType.Information)
StrCon = "data source=XXX;initial catalog=XXX; uid=XXX; pwd=XXX;"
conn = New SqlConnection(StrCon)
conn.Open()
Dim outadapter1 As New SqlDataAdapter("select * from dbo.ReaderInfo where dbo.ReaderInfo.Reader_location in (Select Reader_location from dbo.Reader_Status )", conn)
Dim ds1 As New DataSet()
outadapter1.Fill(ds1, "dbo.ReaderInfo")
Dim outadapter2 As New SqlDataAdapter("Select * from dbo.Reader_Status where Remarks = 'C'", conn)
Dim ds2 As New DataSet()
outadapter1.Fill(ds2, "dbo.ReaderInfo")
For i As Integer = 0 To ds2.Tables(0).Rows.Count - 1
host = ds1.Tables(0).Rows(i)("ReaderIP").ToString
Try
'My.Computer.Network.Ping(host)
Dim ping As New System.Net.NetworkInformation.Ping()
Dim pingReply As System.Net.NetworkInformation.PingReply = ping.Send(host) 'ping ipaddress
'test.WriteByDate("e:\temp", "log", "service", "reader" & ds1.Tables(0).Rows(i)("Reader_location").ToString & "disconnected" & e1.Message)
Catch e1 As System.Net.NetworkInformation.PingException 'if not connected try reconnecting
status1 = api.TcpConnectReader(ds1.Tables(0).Rows(i)("ReaderIP").ToString, ds1.Tables(0).Rows(i)("ReaderPort")) 'API call to connect to device
If status1 = 0 Then ' successfully connected
Exit For
Else
test.WriteByDate("e:\temp", "log", "service", "reader" & ds1.Tables(0).Rows(i)("Reader_location").ToString & "disconnected" & e1.Message) 'otherwise write to log
GoTo nxt
End If
End Try
nxt: Next
End Sub
conn.Close()
|
|
|
|
|
Your post isn't readable because it's too wide. Break the code sample lines into multiple lines to reduce the width of the post.
From the limited information I got from your post (what I could read anyway), you used the Timer control in the ToolBox and dropped it on a Form?? This isn't going to work in a service because there is no message pump. In a service, you would normally use the System.Threading.Timer, which makes direct calls back to your code instead of using events.
modified on Wednesday, January 7, 2009 2:20 PM
|
|
|
|
|
Try using the Timer.Elapsed event instead and set the amount of time in the properties for the timer control.
Humble Programmer
|
|
|
|
|
The service I have has a timer (System.Timers.Timer) that works.
Searching for help on this class should point you in the right direction.
Tim
|
|
|
|
|
ok it worked using the system.threading.timer class.Apparently the other two timers dont work in windows service in .net 2.0.read it online.
I want to know more what this timer does.I searched online and what I figured is that it similar to the forms timer except that the timer event runs in a different thread using timercallback delegate.
So is it something like a thread that runs periodically?
|
|
|
|
|
I am writing a plugin for a program where I am creating control forms. Here is a sample of the code for creating the forms...
<br />
_singlePointDialog = New singlePointDialog()<br />
_singlePointDialog.Show(RhUtil.RhinoApp.MainWnd)<br />
_singlePointDialog.Hide()
The reason for this is i want the form open and receiving values while users are interacting with the program but i don't want the form visible until the user asks for it.
Now what i have currently works fine except there is a flicker... obviously from the initial show then the hide.
The program SDK give me access to a IWin32Window (RhUtil.RhinoApp.MainWnd). I tried setting the form.owner value but i don't have a windows.forms.form object to set it to. Ahh!
<br />
_singlePointDialog.Owner = RhUtil.RhinoApp.MainWnd
This does not work! :-P
Is anyone aware of a way to initialize the form without showing it?
|
|
|
|
|
Not sure what you're doing, but can't you just declare your form and then not immediately call the .show or .hide methods? You're variable is already instantiated with the first line.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I think i got caught up on this instead of figuring out when i should have shown the form. opps. I went back and made some changes to where form is opened and closed.
What i am really wondering about is why:
Public Sub Show(Owner as IWin32Window)
and
Public Property Owner() as Windows.Forms.Form
would accept different inputs?
|
|
|
|
|
|_josh_| wrote: _singlePointDialog.Show(RhUtil.RhinoApp.MainWnd)
What did you think was going to happen? You told it to show itself! So, yeah, there's going to be a flicker as the form pops up and then hides.
|
|
|
|
|
Ok, now that i have changed the locations of the _singlePointDialog.Show(RhUtil.RhinoApp.MainWnd) I see why i was doing this originally.
If i change the code so that when a user clicks a button it runs the code:
_singlePointDialog.Show(RhUtil.RhinoApp.MainWnd)
and
_singlePointDialog.Hide()
it shows the form but every call to _singlePointDialog.Show(RhUtil.RhinoApp.MainWnd)recalls Form.Load which resets all values that were previously set in the Form.Load call. That is why i was running:
_singlePointDialog = New singlePointDialog()<br />
_singlePointDialog.Show(RhUtil.RhinoApp.MainWnd)<br />
_singlePointDialog.Hide()<br />
to initialize the Form, and then using:
_singlePointDialog.Visible = True
and
_singlePointDialog.Visible = False
to show and hide the form.
Which brings me back to my original question is there a way to load the form(setting all important values) without visualizing it? This includes settings the form owner to RhUtil.RhinoApp.MainWnd which is an IWin32Window object.
I hope this clarifies my dilemma and someone has a clue how to solve it.
thanks in advance!
|
|
|
|
|
hey josh,
in your first post, you wrote the reason you want to do this, is for the form to receive data but to be hidden to the user until she wants to see it. i wonder what interesting problem you try to solve by this approach.
my suggestion is to collect the data in a collector-class. show the form when it is appropriate to the user and use the data from the collector-class then.
i really can't think of anything you need the form for to collect data. though i suspect you to "collect" keystrokes. are you? in case, there is a better solution to doing this.
regards,
arthur
|
|
|
|
|
Again an issue with the parent form-child form thing.
I have two forms Form1 and Form2.
Form1 is embedded as control in Form2.
Multiple instances of Form1,each with a different name are open in Form2.
I want to close all open instances of Form1 at the same time with the click of a button.
How should i start?
|
|
|
|
|
Loop through the controls of Form2, and check their type. if it is a form, close it. Shouldn't be harder then closing all types of control y within control x.
|
|
|
|
|
|
I have tried to search for an answer on line but maybe my search choices are worded wrong. I have a form that has multiple text boxes. (Just like many forms) I am using a barcode scanner to input data into the textboxes. I put a enter post amble in the scanner to go to the next field, and it works. The form gives the user the ability to lock fields and keep those values in the textboxes for multiple iterations of the form entry. I lock textfields by changing enabled to false.
Issue: When I scan the text box previous to a locked textbox the cursor will not tab over the locked field. I do not want to put a tab in the scanner do to other issues on that page.
I want to know if there is a way to force a tab through code. Example: When the textbox is validated then force tab to tab to next unlocked textbox.
Thank you for any help you offer.
|
|
|
|
|
Check that your locked control has TabStop property set to false. That could be the reason if the focus goes to the locked control.
Also since you now the layout of your form, one way could be that you programmatically use SetFocus method on the control where you want to go.
|
|
|
|
|
I have tried the tabstop idea. It still does not work. I Need to know if there is a way to force a tab in code. If I can I think it will work. I want to try that before I write a bunch of code to change focus.
|
|
|
|
|
You can simulate tab with SendKeys, but I think it would be easier to call for example: Select Method[^].
When you say that it doesn't work, do you mean that the focus goes to the locked control even though it's TabStop is False or does tho focus go somewhere else?
|
|
|
|
|
It sounds like there is no set tab order, that you are figuring out at runtime.
I use this to enable/disable our controls tabstops,
''' <summary>
''' This sets the tab stops to false when in inquire mode and tab stops to true if in update mode.
''' </summary>
''' <param name="c">C is the control from the calling form</param>
''' <param name="bStatus">This sets the control tabstops to True (enabled) false (disabled)</param>
''' <remarks></remarks>
Public Sub sInitializeControls(ByVal c As Control, ByVal bStatus As Boolean)
'This routine needs to be ran after a form is loaded
'When we enable and disable controls the cursor will stop on the controls that have been disabled
'This is a recursive function
'c = Control from Calling form
'
Dim ctrl As Control
For Each ctrl In c.Controls
If String.Compare(ctrl.Name, "btnClose") = 0 Or String.Compare(ctrl.Name, "btnCancel") = 0 Then
'exit
Else
ctrl.TabStop = bStatus
If ctrl.HasChildren Then
sInitializeControls(ctrl, bStatus)
End If
End If
Next
End Sub
You might be able to modify this to your needs.
I would think you could call this to set all tab stops false and then in the validation routine you could set the specific control you are wanting to move to
like so
control.tabstop = true
control.focus() or control.select()I have found the latter of these two to be more reliable
Humble Programmer
|
|
|
|