|
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
|
|
|
|
|
are you talking about two EXE files, hence interprocess communication?
or different parts of a single process, maybe an application with plug-ins?
and the existing program is a .NET one, you have the code, and will be able and allowed to modify it once?
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).
|
|
|
|
|
Luc,
I'm open to whatever would work, two .EXE's or whatever. A friend suggested using DLL's for the "slave" routines, but I don't know if there is a method for run-time setting the call name of a DLL at run time in the supervisory program that once established, I don't want to change.
Yes, the existing program is .NET and I would modify it to call sending/receiving arrays of data in a standardized format.
Thanks,
|
|
|
|
|
OK,
I find having only one EXE simpler, so I would suggest a plog-in scheme. This is how it could be made to work:
- you take the existing code, add some, and create the EXE; that is one project.
- you define an Interface, which basically is a contract describing the methods and parameters all the plug-ins must offer.
- for one or more plug-ins, you create a DLL project, implementing the required functionality.
- in the main program, you add detect logic, select logic, and call logic.
The detect logic could be: all DLL files in a particular subfolder, say "plugins".
The select logic is up to you, it could be a Menu, a ComboBox, or whatever, populated with the names of the DLL files (assuming those are relevant); a more complex scheme would require you load those "assemblies", execute some code to get the types they implement, and call some method/property on them to get a display name, with which you populate the GUI.
The call logic would require some "reflection" code, look at Activator.CreateInstance()
I did not immediately find a relevant article that is based on VB.NET; however there are several with C#, here[^] is one (haven't read it though); the principles should be exactly the same, basically the only difference is syntactic.
I hope this gets you started.
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, Luc, thanks a lot. This is pretty much what I was looking for. I'll work on getting a test case going.
|
|
|
|
|
Hi,
I need to limit the user to only entering integers (positive and negative) into a textbox.
Now I know the trick with the KeyPress event and e.KeyChar , to limit the user to entering only numbers into a textbox, and with CChar("-") I can check for the minus sign.
The problem is, how do I make sure that when entered, the minus sign is always in first place?
Is it possible to check for the index position of the caret ?
Or am I going about this in an overly complicated fashion ?
My advice is free, and you may get what you paid for.
|
|
|
|
|
You can check the position of a specific character in the text box by calling indexOf on the control. Then check it is only at position 1. You will also want to check that it doesn't already have one by calling contains .
You will also need to do the same thing for a decimal point. (if it is the first character entered, then good practice is to prefix the textbox with a 0, so the dp is more visible.
And as you say you already know about the the keypress and keychar, I tend to use the keydown event, but it upto you how you want to do things.
|
|
|
|
|
I had thought of this solution as well, but I had a silent hope that maybe I could do the checking In Flagrante Delicto so to speak, instead of after the minus sign has been entered already.
I mean, during the KeyPress (or indeed KeyDown) event the key has not actually been entered yet, so I can't check for its index yet (right?).
My advice is free, and you may get what you paid for.
|
|
|
|
|