15,908,444 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by BHort (Top 31 by date)
BHort
31-Oct-11 11:54am
View
I was thinking something like this might work:
Public Class mystringclass
Private mystring
Public Sub New(curString As String)
mystring = curString
End Sub
Public Function ProcStr() As String
Return somefunkyprocessingon_mystring
End Function
End Class
Public Class MyClass
Private MyStr As mystringclass
Other declarations here as well
Public Sub New(curStr As String, other items)
MyStr = New mystringclass(curStr)
other stuff
End Sub
End Class
I'm fairly new to .Net so would this allow me to have myclass.MyStr.ProcStr?
I know I've left out a lot of the plumbing ... I was trying to focus on just the core components ...
BHort
31-Oct-11 11:45am
View
Ok ... then how can I describe what I want.
I have a class myclass
The class has a string property (one of many properties) mystring
I want to process the string in a standard way but I don't want to give future programmers the impression that the method call is operating on anything other than just that string.
My thinking was that if the method call looked like
myclass.mystring.mymethod
It would be the most obvious that the method was only operating on the string.
I know how to create myclass.mymethod but that doesn't provide the opportunity for self documenting code.
Is there a way to do this or not.
BHort
29-Oct-11 10:04am
View
Ok ... I'm not quite sure how I gave you the impression that I cared if all the standard methods were hidden or not ... I don't care. I just want to be able to have my methods visible ... that's my goal, not hiding a bunch of other stuff.
So if I want myclass.mystring.mymethod to exist and work ... do I need to create a seperate class for mystring or can I create it all within myclass and how would the getter/setter and method be defined?
I tried Public ReadOnly Property MyString() As String but I couldn't figure out how to create the method to work on that rather than being a method for the class as a whole. So this created MyString and it worked but I couldn't figure out the method part of getting this to work as I'm hoping.
BHort
29-Oct-11 8:47am
View
Or explain better.
One of the properties of my class is a string. I want to create a method that works on that string that is called by doing a myclass.mystring.method call rather than simply a myclass.method call.
Does that make it clearer?
So what I was suggesting was that perhaps I needed to create
mystringclass
and within that create mystringclass.method
And then in my outer class I would have myclass.mystringclassobject which would then have a method associated which I could call by doing a myclass.mystringclassobject.method call.
Hopefully this makes some sense ...
BHort
28-Oct-11 14:54pm
View
I tried right after posting my comment. Hence my accepting the solution prior to your response.
BHort
27-Oct-11 18:42pm
View
Can I have multiple Catch ex As statements? The first being this and then the next being the more general one?
BHort
13-Oct-11 11:57am
View
The final piece of the puzzle was two minor adjustments.
First, turn HideSelection to false on the TreeView. Simple but important.
Second, give the TreeView focus.
Doing those two things gives the nice blue background on the selected item just as if the user had clicked on it.
BHort
13-Oct-11 11:03am
View
By the way ... the syntax for VB.Net is virtually identical so your code snippet was helpful.
BHort
13-Oct-11 11:00am
View
Unfortunately the DB structure wont help because the TV changes depending on UI selections which determine which features and elements to display.
That said, the DB structure is roughly as follows. It has 4 different tables. Timers -> Timers/Tag Groups XRef -> Tag Groups -> Tags
Tag Groups can show up under multiple timers, hence the XRef.
BHort
13-Oct-11 10:58am
View
Ok, I'm slowly figuring this out ... I think! ;-)
When I try and do a find, it's only looking in my 5 root nodes, not the sub-nodes. How do I get Find to also look in the sub-nodes?
Right now I'm getting a "Sequence contains no elements" error when I search for a sub-node that I know is there using text that is identical to the displayed text of the sub-node. (Actually it's a sub-sub-node but still)
BHort
5-Oct-11 18:21pm
View
In doing further development I've discovered that the multimedia timer is pretty accurate. It stays within a few microseconds of accurate without needing any help. When it does drift slightly ... if it's going too fast, I quickly stop and start it again ... and that seems to pull it back on track and/or keep it from straying too far. I do this whenever the timer is > 3 microseconds off. If it's going too slowly I haven't found a great solution other than to add in a "fake" extra tick (equal to 1/100th of a second for my application). I only do this when the error is > 8 microseconds because the impact is bigger but the result is that the timer is staying very true over an extended period with these correction measures.
BHort
5-Oct-11 16:37pm
View
It's too complex for our users. We need something *simple* for them to be able to export their data and/or import into another instance on another machine.
BHort
5-Oct-11 16:02pm
View
Could you perhaps provide an example of how I would write the code to create a proceedure "CountRecs" with the code "SELECT count(*) As numrecs FROM mytable" (trivial I know but it's simple enough to show me how it would be written which is what I'm looking for).
BHort
5-Oct-11 16:00pm
View
Understood. The DBA isn't the issue in this case ... it's more, I wouldn't know how to write it to be generated externally and I wouldn't know how to trap any errors that might get generated (although I guess a try except would hopefully be sufficient)
BHort
5-Oct-11 11:48am
View
Totally what I needed. I didn't think it would be but it's exactly the solution. For other peoples benefit, I'm going to post it as a solution ... although you should really get the credit.
BHort
5-Oct-11 10:20am
View
Well, what about using an ODBC connection to the DBF files? Using the Access ODBC driver to connect to the DBF database you should be able to again simply access the DBF file using SQL and ignore the fact that it's a DBF file. It wont be fast because you typically wouldn't have any indexes loaded but it would work.
BHort
3-Oct-11 12:34pm
View
Implemented the change plus added the command to reduce the priority of my DB save routine thread from RealTime to Normal priority (I previously had the entire app at Real Time priority) ... my application is keeping to within 3/1000ths of a second accuracy ... oh am I happy!
Thank you. Things are much more stable now.
BHort
3-Oct-11 12:10pm
View
But wouldn't that create a lot of overhead creating a new connection to the database for each thread?
BHort
21-Sep-11 17:10pm
View
Got it.
The correct If should be:
If allowedChars.IndexOf(e.KeyChar) = -1 And e.KeyChar <> Convert.ToChar(Keys.Back) Then
So the complete solution is to paste:
Dim allowedChars As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
If allowedChars.IndexOf(e.KeyChar) = -1 AND e.KeyChar <> Convert.ToChar(Keys.Back) Then
' Invalid Character
e.Handled = True
End If
Into the KeyPress event of a text box.
Hope this helps someone else. I really like it because it means my input testing is done up front.
BHort
21-Sep-11 17:04pm
View
Just did ... no joy. I thought it was because it would skip the back with the logic you supplied but putting NOT around the 2nd half didn't help ... but I think you might be on the right track ... I'll keep trying ...
BHort
19-Sep-11 10:05am
View
I'm trying to implement a time correction algorithm to ensure my application timer stays closer to the original intended time. Basically to remove or at least adjust for the drift as it happens.
BHort
14-Sep-11 10:58am
View
Is it possible to create (in the designer) an array of radio buttons?
BHort
13-Sep-11 11:21am
View
I stand corrected. I figure I'm surviving ... so I'm not really worried about it but I do appreciate people who are willing to contribute a constructive criticism once in a while. Thanks again.
BHort
13-Sep-11 11:07am
View
Excellent. Thank you for that. I've been programming for 30 years but I'm still fairly new to VB.Net
BHort
12-Sep-11 12:12pm
View
Asked another way ... how can I ensure the outputed number of "1"s and "2"s is what I expect if the problem is in the process scheduler?
BHort
12-Sep-11 12:11pm
View
But I'm not getting the output expected ... so how is my code working fine? I need to know that when I output for Timer 1 ... I'm going to get Timer 1 information. I don't care about the order but I do care about being confident that I'm getting the right timer.
BHort
12-Sep-11 12:03pm
View
Here is the code for my example (with a line commented out towards the bottom so you can easily switch from subroutine to task and back)
<pre>
Imports System.Threading.Tasks
Public Class Form1
Public TickCounts As Integer = 0
Public AllowTimerTics As Boolean = False
Public CurTimers(4) As TimerListDef
Public Class TimerListDef
Public TimerID As Integer
Public TimerInterval As Integer
Public CountDown As Integer
End Class
Delegate Sub myInvokedMethod(ByVal test As String) 'We need a delegate in order to be able to invoke it at runtime with a parameter
Private Sub AddErrItem(ByVal ErrStr As String)
Dim item1 As New ListViewItem
Dim tempStr As String
tempStr = Format(Now, "hh:::mm:::ss:::fff ") + ErrStr
item1 = New ListViewItem(tempStr)
lstErrors.Items.Add(item1)
End Sub
Delegate Sub myInvokedOPCMethod(ByVal test As Integer) 'We need a delegate in order to be able to invoke it at runtime with a parameter
Private Sub ReadOPCData(ByVal CurTimerToRead As Integer)
Dim DispText As String
DispText = "Timer: " & CurTimerToRead.ToString
If Me.InvokeRequired Then
Me.Invoke(System.Delegate.CreateDelegate(GetType(myInvokedMethod), Me, "AddErrItem"), New Object() {DispText})
Else
AddErrItem(DispText)
End If
End Sub
Private Sub TimerTicToc_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerTicToc.Tick
Dim TimerToRead As Integer
TextBox2.Text = TickCounts.ToString
If AllowTimerTics Then 'Should not allow timer tics when the Timers/Tags global variables are being recreated
For Counter = 1 To 3
CurTimers(Counter).CountDown = CurTimers(Counter).CountDown - 1
If CurTimers(Counter).CountDown <= 0 Then
CurTimers(Counter).CountDown = CurTimers(Counter).TimerInterval
TimerToRead = Counter 'We do this because the debugger warned of unexpected results of we passed the counter directly
'Launch a task to do the read to keep the time for this loop short
Task.Factory.StartNew(Sub() ReadOPCData(TimerToRead), TaskCreationOptions.AttachedToParent)
'ReadOPCData(TimerToRead)
End If
Next
TickCounts += 1
If TickCounts > 120 Then
AllowTimerTics = False
TimerTicToc.Stop()
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TickCounts = CInt(TextBox1.Text)
If TimerTicToc.IsRunning Then
MessageBox.Show("Hey, it's running!")
Else
For Counter As Integer = 1 To 3
CurTimers(Counter) = New TimerListDef
CurTimers(Counter).TimerID = Counter
Next
CurTimers(1).TimerInterval = 10
CurTimers(2).TimerInterval = 25
CurTimers(3).TimerInterval = 100
CurTimers(1).CountDown = 10
CurTimers(2).CountDown = 25
CurTimers(3).CountDown = 100
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime
AllowTimerTics = True
Try
TimerTicToc.Start()
Catch ex As Exception
MsgBox("Can't start the timer" & vbCrLf & ex.Message)
End Try
TimerTicToc.Start()
AllowTimerTics = True
End If
End Sub
End Class
</pre>
This particular example requires a ListView box, 2 text boxes and a button. The listview is for output and I've syncronized the timer to Form1 to simplify output ... although I don't intend to in the final version.
BHort
12-Sep-11 11:59am
View
No, the counts aren't different in the total number of counts, just in the values that should be displayed.
I've got a very small project that I've created to demonstrate the problem ... but it requires the multimedia timer DLL that was part of the article here:
The Multimedia Timer for the .NET Framework
BHort
12-Sep-11 10:12am
View
Part of my concern is coming from the fact that I'm using a component that uses a multimedia timer to implement a timer component that can generate "tics" with a frequency lower than every 15 ms. It seems to work great when I use it and call my routine as a subroutine but not when I call it as a task ... and I'm wondering if the transfer of the variable into the task is getting interrupted by another "tic" and hence the variable gets changed mid process.
Is there a way to ensure the launching of the thread is atomic? Another thought I had was to put my values into an ArrayList using a Monitor.Enter/Exit pair and pulling them off again within the task. I might not guarantee that execution 1 gets value 1 (because of the non determinism) but I can ensure that for n values there will be n calls and thus all the values will be processed.
Does that sound like a plausible option? Again, I'm fairly new at VB.Net multithreading so I'm open to being told I'm out to lunch ...
BHort
12-Sep-11 10:04am
View
I understand the non-deterministic nature of threads but the issue that's causing me to question that being the source of the problem is the fact that the total number of "1"s and "2"s aren't correct. If you notice in my "correct" output I have 5 "1"s and 2 "2"s ... the incorrect showing 4 and 3 respectively. The quantity of each output isn't correct ... which is where my feeling like the variable is getting changed is coming from.
BHort
8-Sep-11 10:07am
View
When I run it as a subroutine I get:
Timer: 1
Timer: 1
Timer: 1
Timer: 2
Timer: 1
Timer: 1
Timer: 2
etc.
which is correct. When I run it as a task I get:
Timer: 1
Timer: 1
Timer: 1
Timer: 2
Timer: 2
Timer: 2
Timer: 1
etc.
Or various other similar wrong values for what should be displayed.
Timer 1 is going 100 times per second. Timer 2 is 40 times per second. Timer 3 is every 1/10th of a second (not that I've shown the third timer in my sample)
Show More