| | |
Timing problem? Variable does not always update
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 27
Reputation:
Solved Threads: 2
All my (programming) life I’ve been plagued by timing problems! I assumed (haha) that when I changed from a pervasively multitasking OS to Vista I would escape the problem but it seems like I must be missing something.
My problem lies in WhichChar. Note the line:
'MsgBox(vbNullString)
If I leave it commented out, the StringBuilder retVal is only occasionally updated, about half the time. If I uncomment the MsgBox line, retVal is always correctly updated.
I did see that the Controls are not guaranteed to be thread-safe, that may be the problem I am running into. I have two more problems with ComboBoxes in general, but I will keep digging to see if I can resolve them myself.
This is a project with multiple purposes. The actual job of the program is to rename songs. I am using iTunes to put my CD collection on my computer. Most of the CDs are identified automatically, others I can ID with a few of the free online DB services. A handful I can find the track list online but not in a database. In these cases the file name and song title look like “01 Track 01”, “Track 1” or “01 Track”.
Entering all this info manually would take less time than writing the code! So, I last worked in Basic in the late ‘70s, got into C then C++ as soon as alpha wear was available. I recently switched to Windows and thought I would play with a bit of programming. This is my first attempt (after “Hello, world!”) and I am finding the going a bit slow.
Thanks in advance for the help I get!
-Ed
My problem lies in WhichChar. Note the line:
'MsgBox(vbNullString)
If I leave it commented out, the StringBuilder retVal is only occasionally updated, about half the time. If I uncomment the MsgBox line, retVal is always correctly updated.
I did see that the Controls are not guaranteed to be thread-safe, that may be the problem I am running into. I have two more problems with ComboBoxes in general, but I will keep digging to see if I can resolve them myself.
VB.NET Syntax (Toggle Plain Text)
Private Sub asteriskComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles asteriskComboBox.SelectedIndexChanged WhichChar(asteriskComboBox, asteriskReplacement, asteriskComboIndex) End Sub Public Sub WhichChar(ByVal CBox As ComboBox, ByRef retVal As StringBuilder, ByRef indexToChange As Integer) If Not isInstantiating Then indexToChange = CBox.SelectedIndex Dim selectedIndex As Integer selectedIndex = CBox.SelectedIndex Dim selectedItem As New Object selectedItem = CBox.SelectedItem retVal.Length = 0 'MsgBox(vbNullString) Select Case indexToChange Case 0 'single space retVal.Append(" ") Case 1 'hyphen retVal.Append("-") Case 2 'single space>hyphen<single space> retVal.Append(" - ") Case 3 'open single quote retVal.Append("`") Case 4 '' close single quote retVal.Append("'") Case 5 'underscore retVal.Append("_") Case Else 'everything else retVal.Append(CBox.SelectedText) End Select End If End Sub
This is a project with multiple purposes. The actual job of the program is to rename songs. I am using iTunes to put my CD collection on my computer. Most of the CDs are identified automatically, others I can ID with a few of the free online DB services. A handful I can find the track list online but not in a database. In these cases the file name and song title look like “01 Track 01”, “Track 1” or “01 Track”.
Entering all this info manually would take less time than writing the code! So, I last worked in Basic in the late ‘70s, got into C then C++ as soon as alpha wear was available. I recently switched to Windows and thought I would play with a bit of programming. This is my first attempt (after “Hello, world!”) and I am finding the going a bit slow.
Thanks in advance for the help I get!
-Ed
Last edited by edgar5; Jan 2nd, 2009 at 3:41 am.
•
•
Join Date: Dec 2008
Posts: 27
Reputation:
Solved Threads: 2
I have (I think) determined the problem. My terminology is very rusty, but I think the word is “scope” (might now be a Namespace thing).
Here is what is going on…
The Form and the ComboBox were created in the VB visual editor. As I expected this to be a simple project (HaHa) I decided to put all the code within the
This mean that when I call
I need to learn how to create classes which inherit from others (I do that in C++--maybe I should simply try Visual C++) That way I might be able to get the data out of the ComboBox any time I needed it. Have to play around with it some.
Here is what is going on…
The Form and the ComboBox were created in the VB visual editor. As I expected this to be a simple project (HaHa) I decided to put all the code within the
Public Class form1…End Class code section (as the beginner examples like “Hello, world!” seem to do. VB declares all the gadgets and underlying support code ( main() etc.) in some hidden file—I found it once but seem to have lost it! The ComboBox is declared as somewhat global, but it’s member Subs are somehow private (is my guess).This mean that when I call
Private Sub ComboBox_SelectedIndexChanged() and within that function examine the contents of ComboBox.SelectedText the value returned is accurate, but when I pass (ByRef or ByVal) ComboBox to Public Sub WhichChar() the values returned by ComboBox.SelectedText are in fact wild pointers and only accidently point to anything reasonable occasionally.I need to learn how to create classes which inherit from others (I do that in C++--maybe I should simply try Visual C++) That way I might be able to get the data out of the ComboBox any time I needed it. Have to play around with it some.
-Ed
MS Vista Ultimate 64-bit; Visual Studio 2008 & 2010 beta; Visual Basic; Visual C++
Asus P5E3 Deluxe w/ Intel E6850, 8 GB OCZ DDR3 PC3-12800, SAPPHIRE HD3870 GPU
MS Vista Ultimate 64-bit; Visual Studio 2008 & 2010 beta; Visual Basic; Visual C++
Asus P5E3 Deluxe w/ Intel E6850, 8 GB OCZ DDR3 PC3-12800, SAPPHIRE HD3870 GPU
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: how to change file name?
- Next Thread: Problem in Removing Node from XML using Vb.net
| Thread Tools | Search this Thread |
.net .net2008 2008 access account add advanced application array basic beginner browser button buttons click code combo cpu cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic employees excel exists fade filter forms generatetags html images input intel internet listview mobile module monitor mysql net number objects open panel pdf picturebox picturebox2 port position print printing printpreview problem regex reuse right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver storedprocedure survey temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet vista visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year






