|
|
hello!
i wanna add a context menu as "Close CD Tray" in CD drive's context menu.
but i can't only CD drive's context menu.
my context menu is working on all drives as C:, D:, E: so on.
i wanna show it just only on CD drive's context menu.
could u help me pls?
i'll thz u very much....
|
|
|
|
|
|
You will have to check which drive is selected before you create the context menu.
Then when the user clicks the cd drive you show your menu, otherwise you just show the default one.
My advice is free, and you may get what you paid for.
|
|
|
|
|
If you work with a 32bit Windows take loo at this[^]
On a 64b windows it won't work.
|
|
|
|
|
I am having a major problem with a date. (One of the day, month, year kind!) The problem is conversion from a string to a date.
Either I am in perpetual brain fart mode or something odd is going on.
This is a data line being imported
nc,71401286,0,"Thursday, May 20, 2010 01:00:54 UTC",38.8335,-122.8778,1.0,1.80,12,"Northern California"
This is the code that gets the date part and changes it into "dd/MM/yyyy HH:mm:ss"
astrData = strLine.Split(",")
sbldValues = New StringBuilder(strCMD & astrData(QUAKE_ID) & QUOTE & COMMA)
strPartLine = astrData(QUAKE_ID) & COMMA
'Next is the networkID
sbldValues.Append(QUOTE & astrData(NET_SOURCE) & QUOTE & COMMA)
strPartLine &= astrData(NET_SOURCE) & COMMA
'Next is the version which is also a string
sbldValues.Append(QUOTE & astrData(VERSION_NO) & QUOTE & COMMA)
strPartLine &= astrData(VERSION_NO) & COMMA
strEventDate = CDate(Trim(astrData(DATE_PART_1) _
& astrData(DATE_PART_2).Substring(0, astrData(DATE_PART_2).Length - 4))).ToString("dd/MM/yyyy HH:mm:ss")
sbldValues.Append("CONVERT(datetime,'" & strEventDate & "',103)" & COMMA)
If bFileStartDone = False Then
m_strFileStartDate = strEventDate
m_strFileEndDate = strEventDate
bFileStartDone = True
Else
m_strFileEndDate = strEventDate
End If
strPartLine &= strEventDate & COMMA
(COMMA and QUOTE are just constants as I find these easier to read and debug.)
Later on in the code there is this section:
strDate1 = Format(drowData("Date_Time"), "dd/MM/yyyy HH:mm:ss")
strDate2 = astrValues(EVENT_DATE) 'This is already in the right format
If strDate1 <> strDate2 Then
bDifferences = True
intDateDiff = DateDiff(DateInterval.Minute, drowData("Date_Time"), CDate(strDate2))
If intDateDiff > intTimeVariance Then
The second it hits the CDate(strDate2) I get the exception below
System.InvalidCastException was unhandled
Message="Conversion from string "19/05/2010 02:12:54" to type 'Date' is not valid."
Source="Microsoft.VisualBasic"
StackTrace:
at Microsoft.VisualBasic.CompilerServices.Conversions.ToDate(String Value)
My problem is that this runs in a test bed version, and in a compiled exe as part of a windows forms project, but NOT when it is running in a service.
The code is identical - literally - as the class in which this resides is designed to work with the service or the windows program, thus the code file is just copied between the two.
The service is running under 'local system' and I am suspecting the this may have something to do with it, but what? Why should a date conversion behave differently? Have I missed something somewhere?
Edited for a speeling era
|
|
|
|
|
Hi,
my best guess is this: CDate(strDate2) is attempting to parse the string and turn it into a DateTime; as no format is specified, it relies on the regional setting in effect, which one normally sets through the Regional Settings control panel, although it can be overridden by setting the thread's CultureInfo. I assume you did the former; now running as a service, it is not your regional setting that is in effect, it probably is some system default, which may well be an American-style one.
The clean fix is by not using CDate; I'd use DateTime.TryParse or TryParseExact with an explicit format right there. When not communicating with the user, you should always enforce the format your app wants. That is defensive programming: simple and robust.
FWIW: I find your code rather unreadable. I don't like the identifier names much, and all those constants (without their value) obscure the matter even more. So I can not judge the correctness of what was shown.
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).
|
|
|
|
|
All those Caps are irritating.
And the names rather confusing.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
Please see my response to Luc (eyesight), and they please tell me pray how you name and display constants so as to differentiate then from variables? I am always willing to learn.
A la Microsoft
FILE_NOTIFY_CHANGE_FILE_NAME
FILE_NOTIFY_CHANGE_DIR_NAME
FILE_NOTIFY_CHANGE_ATTRIBUTES
FILE_NOTIFY_CHANGE_SIZE
FILE_NOTIFY_CHANGE_LAST_WRITE
FILE_NOTIFY_CHANGE_SECURITY
If that is old fashioned and not used any longer than please enlighten me as to the modern style.
|
|
|
|
|
No Problem with the constants, and now I have read the other response I see the QUOTE and COMMA reasoning.
Fair Dos, but it does look untidy, but I can appreciate why you choose to do it. Those Old Eyes aren't what they used to be!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
Thanks. No indeed they are not.
|
|
|
|
|
There are larger readability issues; I hope my reply to the OP will hit the nail on the head.
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).
|
|
|
|
|
Hi Luc,
Thanks for the response. I have tried it in American date format and specifying a formatter and none of it seems to work.
Originally as I stated I had the conversions in. I will try the TryParse. You have at least identified for the the fact that it is something to do with the fact that the code is not running as a user, and for that I thank you.
Obviously without the declarations of the constants it is not so readable, but I do it that way to make it more readable. I find that astrData(LATITUDE) is easier to understand when I come back to the code later than astrData(4)
I am curious as to what you don't like about the identifier names? Please enlighten me as I learnt to program over the last 30 years starting in the days of ANSI Basic 1.0 and things have probably changed a bit. My variables always have an identifier for the type, i.e. bGood, strBad, cmdClick etc etc and I was taught that constants should be capitalised and split with and underline to make them readable. It is all named as to it's purpose. i.e QUOTE is a quote ( ' ) and COMMA is a comma ( , ). You might find it a mite curious that I use & QUOTE & COMMA because I have had so many problems debugging this type of thing recently since I find "', very dificult to read in the editor - maybe because I am using Arial font, and the eyesight is not what it used to be, so doing it this way I don't get it wrong. But I am always open to new suggestins to make the code better.
|
|
|
|
|
Coding styles are a very subjective thing. Personally I am with you on this one. I, too learnt to program in ANSI Basic 1.0 and my coding style is exactly like yours, except I don't use constants much.
|
|
|
|
|
Good to know that I am not the only old fart person out there doing it that way! Thanks for telling me that.
|
|
|
|
|
Hi,
your message and code feels very slithery to me; let me explain that. When I try to read and understand a statement such as (I'll pick a simple one here):
strPartLine = astrData(QUAKE_ID) & COMMA
all I am getting from it is: some variable (type unknown, meaning unknown), with a name that suggests it is part of a string (names should describe the essence of the object, not their type), not sure what it will be about (would the app be about earthquakes? hmm, interesting, but I'm not sure here), gets calculated as one element of some array (aha, I've seen that one before, it is the split result), unfortunately I don't know which element gets copied, and some other thing gets appended, its declaration and definition are not available, so I can only hope it is a string (if not VB will execute a sneaky conversion), and here the name suggests it is a comma (however I've learned by experience not to assume anything, especially when the context is an app that doesn't work properly).
And here is an alternative way of writing the same line of code:
Dim quakeNameComma as string = linePart(1) & ","
which reads: a string variable holding the name of the quake is calculated as the second part of the line with a comma appended. Yeah, I can read that in a few milliseoonds and I know for a fact what is going on in that line. Quite a change. Now I don't need to concentrate on the line itself, I can concentrate on getting the overall picture of your code snippet; when I'm three lines down I will still remember what has happened before.
The same goes for your problem description:
This is a data line being imported
nc,71401286,0,"Thursday, May 20, 2010 01:00:54 UTC",38.8335,-122.8778,1.0,1.80,12,"Northern California"
which may, or may not, mean: the initial content of strLine is ...
and then
Message="Conversion from string "19/05/2010 02:12:54" to type 'Date' is not valid."
Are you saying the above input (May 20, 2010 01:00:54) is converted into 19/05/2010 02:12:54 and then it throws? That is a mysterious conversion, I have no clue what functionality you are trying to get; or did you just throw some non-matching examples together to make things more obscure?
So my problem overall was you were not offering much of a grip on the problem. I had to assume too many things at once to come up with a reasonable hypothesis, apart from the impression you had a date problem, probably caused by an implicit format assumption.
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).
|
|
|
|
|
Hi Luc,
I will digest that. In the meantime, as of a minute ago and after making sure everything came out in American date format, the service is running without errors.
It has been a salutory lesson that running under Local System is a different dimension to running as a logged in user.
My most sincere thanks to you Luc as I would not have sussed this one for ages without you pointing me in the right direction. Unfortunately there is no :hail: smiley so I can't use it, but :hail: anyway.
|
|
|
|
|
you're welcome.
Getting it to work properly is part of the goal; making sure it works reliably is a part as well. And IMO striving for excellent readability is a big factor in both.
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).
|
|
|
|
|
Hi Luc,
"your message and code feels very slithery to me;" Eww! I hate snakes.
"I'll pick a simple one here
strPartLine = astrData(QUAKE_ID) & COMMA"
Mm, sorry Luc that one was confusing as it is a testing line.
"would the app be about earthquakes?" Yup - Importing USGS data using a service
"The same goes for your problem description:
This is a data line being imported
nc,71401286,0,"Thursday, May 20, 2010 01:00:54 UTC",38.8335,-122.8778,1.0,1.80,12,"Northern California"
which may, or may not, mean: the initial content of strLine is ..."
I put that in there to show what the date part looked like on the original so you could perhaps make head or tail of my code that was chopping it up and turning it into numbers only. Unfortunately as my DB says, I am not the best at explaining things.
"and then
Message="Conversion from string "19/05/2010 02:12:54" to type 'Date' is not valid."
Are you saying the above input (May 20, 2010 01:00:54) is converted into 19/05/2010 02:12:54 and then it throws? " Yes basically.
"That is a mysterious conversion, I have no clue what functionality you are trying to get; or did you just throw some non-matching examples together to make things more obscure?" ??? Not quite sure what you mean there. Can I just put the text in - May 20, 2010 01:00:54 ??. I think possible when logged in but not when running as a service maybe?
"So my problem overall was you were not offering much of a grip on the problem. I had to assume too many things at once to come up with a reasonable hypothesis, apart from the impression you had a date problem, probably caused by an implicit format assumption."
Nevertheless you did manage to come up with an hypothesis! Again my thanks.
Re your last post:
"Getting it to work properly is part of the goal; making sure it works reliably is a part as well. And IMO striving for excellent readability is a big factor in both." I will try to be clearer in future!!
Over and out
|
|
|
|
|
I know the issue has been resolved; but, I just read the post. Here's another take on a solution. This code uses the Date Wizard class library to come up with the converted date variable. (Click here for the article on the Date Wizard.)
Imports _2gs_datewizard
'** Split source string on spaces (source string is in Textbox1)
Dim ss() As String
ss = TextBox1.Text.Split(" ")
'** Convert the month in ss(1) from a name to a number
Select Case ss(1).Substring(0, 3).ToLower
Case "jan" : ss(1) = "1"
Case "feb" : ss(1) = "2"
Case "mar" : ss(1) = "3"
Case "apr" : ss(1) = "4"
Case "may" : ss(1) = "5"
Case "jun" : ss(1) = "6"
Case "jul" : ss(1) = "7"
Case "aug" : ss(1) = "8"
Case "sep" : ss(1) = "9"
Case "oct" : ss(1) = "10"
Case "nov" : ss(1) = "11"
Case "dec" : ss(1) = "12"
End Select
'** Remove trailing comma from the day in ss(2)
Dim dayString As String = ss(2).ToString
ss(2) = dayString.Substring(0, dayString.Length - 1)
'** Convert to date (ss(3) contains the year)
Dim df As New C_DateFunctions
Dim sourceDate As Date = df.BuildDate(ss(1), ss(2), ss(3))
df = Nothing
'** Test the procedure by displaying the resulting date
MsgBox(sourceDate.ToShortDateString)
The test at the end displays the converted date as 5/20/2010.
|
|
|
|
|
i use mscomm in vb.net.
the problem is i cant detect the comport is open or close by other software,i can do this only if the comport is open by my own vb.net program.
when i use hyper terminal to connect by comport1,i open my vb.net program and check the comport.portopen it always give me false.so when i use the following code:
if comport.portopen=true then
comport.portopen=false
end if
i cant close the port as the vb program not even know it is open by other software.
after that if i continue use port.portopen=true i will give me exception as the port is alredi open.
i had surf through web and found many ppl having this problem also,but nobody provide a good solution.
is there a way to force all the comport of my computer to close on my formload?
|
|
|
|
|
newbievbnet wrote: is there a way to force all the comport of my computer to close on my formload?
I hope there isn't. When an app opens something (a file, a serial port, whatever) and got promised exclusive access, then no other app should have the power to undo that.
A process can ask for (a fraction of) available CPU cycles, memory, access to files, ports, etc, to the extent that those are free. And Windows will provide or not provide as it sees fit, taking into account what has already been set aside for other running processes. No process can demand resources.
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).
|
|
|
|
|
I am sort of new to multithreadings (doing it about 9 months now) and I ran into an unusual error that I can't figure out. First, how the code is set up:
I have my delegate Delegate Sub RecommendReportsDoneDelegate()
Before I start the calling of the new thread:
DetermineRecommendations = New clsReportRecommendations
AddHandler DetermineRecommendations.StatusChange, AddressOf StatusChange
AddHandler DetermineRecommendations.RecommendationsDone, AddressOf RecommendationsDone
DetermineRecommendations.Start(DataFolder)
The "Start" method actually creates the new thread in the DetermineRecommendations class. Finally, the sub that handles the RecommendationsDone event is:
Private Sub RecommendationsDone()
Try
If Me.InvokeRequired Then
Me.Invoke(New RecommendReportsDoneDelegate(AddressOf RecommendationsDone))
Else
Me.Enabled = True
CopyData()
SetUpUnitSheet()
ShowRecommendations()
SetUpSamplingSheet()
DetermineReportType()
Status.Text = "Finished"
End If
Catch ex As Exception
End Try
However, on the Me.Invoke I get the following error:
Index and length must refer to a location within the string. Parameter name: length
The error occurs in mscorlib. Any ideas on why there seems to be some string function occurring with the Me.Invoke ? By the way, the
|
|
|
|
|
Hi,
I don't see anything wrong right away.
However I feel some essential information must be missing here. I would like to know:
- what is "Me" in the code shown, i.e. in which class is all this? and what type does it derive/inherit from?
- is any of the relevant objects created by code running on a secondary thread? are you trying to create a Form, a Control, ... by a timer tick handler, by a BackgroundWorker.DoWork handler, ...?
I also would suggest you put the whole else block (Me.Enabled...Status.Text=...) in one try-catch, where you catch an Exception and show Exception.ToString() in its entirety. I expect an exception will throw, and offer exact class name, method name, line number information (look for the first line number it spits out).
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).
|
|
|
|
|
OK, you can probably tell from my subject that I am a newbie to VB.net. This may be simple, but I haven't seen (or recognized) a method yet. My problem: An existing program needs to pass information to, and get data from another independent executable module (or DLL) whose name must be defined at run-time. I want to be able to vary the "slave" module as well as it's call name without changing the host. Ideas would be very welcome. Thanks.
Troy
|
|
|
|
|