Programming in .Net

Status
Not open for further replies.

JustinW

Super Moderator
Staff member
#41
You're telling me. Now my question class is ten properties less and my module that holds the common code has lost nearly a 150 lines of stuff basically doing the same thing but under different conditions. My programming class as you can imagine was the real easy stuff. Now I'm messing with the advanced stuff not even having taken a more advanced class for it.


Addendum:


Everyones suggestions so far have proven to be very helpful in getting this done. I wrote some more code since than to actually read the array for the current question and display the question contents itself on the testing form:



As you can see the random thing is pulling valid answers like I want, but I'm going to still need to play around with the random stuff because It is displaying multiples of the same response and sometimes it doesn't even display the correct answer as a response.

Thanks everyone for the feedback so far. You know this thread doesn't just haft to be about me. Anyone out there with a question about .net programming feel free to post :smile:
 
Last edited:

mqudsi

Mostly Harmless
Staff member
#42
Just push each response that has been displayed into a stack, and when you come to display a new response check if it's already there or not.
 

JustinW

Super Moderator
Staff member
#43
Sorry, don't know what you mean by stack unless you're referring to an array. In that case, I'm already doing validation in the routine that initializes it and finally found a method where it wouldn't hang by checking the element before it on each go around verus giving it a six condition if statement everytime and having it loop until met.

Actually after some more debugging, this procedure appears to be working properly. I'm now turning my attention to another sub-procedure, which is responsible for actually putting a question and its answers onto the form. I'm going to reverse the instructions in the procedure as sometimes this works when problems arise and see what happens.

EDIT:

It is the random procedure... double-checked the other and its perfectly fine short of an extra line I didn't need but that wouldn't have affected it anyway. And than I found out that when a question has only 2 questions it keeps pulling the same number, so I put in code to check for 2 answered questions and assign the opposite answer. That works great, but since it keeps pulling the same number the output is always the same (2nd answer A, 1st answer B).

I've tried everything using a Randomize() statement and than no Randomize() at all. The results are always the same, even if I put it at the end of the loop...
 
Last edited:

JustinW

Super Moderator
Staff member
#44
Ok so I've pretty much decided to discontinue development until I can figure out the solution here. So what I've done is create a new project for testing, with nothing more than a button on a form that creates an array of 10 elements and goes through a loop like I have been doing to assign random ranges to each between 1 and 10 and check so they should all be unique. Upon getting the messagebox displayed there are almost always duplicates despite the fact I think I'm doing this right. Here's the code:

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Array to be used

Dim randomnumbers(9) As Integer

'String that well contain the values to display in the messagebox

Dim messagestring As String = ""

'Cycles through each element in the array

For I As Integer = 0 To randomnumbers.Count - 1
'Assigns the current I element a random number between the range of 1 and 10
randomnumbers(I) = CInt(Int((10 * Rnd()) + 1))
'Only happens on the 2nd or any other go-around since there well never be a first answer that is the same when the others have not be given values.
If I > 0 Then

'Compares the current element to the last one. If equal, decrease I so the same element is used in the next go around.
If randomnumbers(I) = randomnumbers((I - 1)) Then

I -= 1
Else

'Appends the current element to the string to be displayed at the end when it is unique from previous elements
messagestring &= randomnumbers(I) & " "

End If

Else
'Assigns the first element to the string to be displayed at the end of the procedure.
messagestring &= randomnumbers(I) & " "

End If

Next
MessageBox.Show(messagestring)
End Sub

End Class
If you spot anything (no matter how big or small) thats wrong with it let me know...
 

Attachments

Last edited:

JustinW

Super Moderator
Staff member
#45
Just to confirm here another user suggested using the random class with the .next method. It ended up producing the same results...

Addendum:

Hmm. Interesting what a search on "random array vb" can find. Just found an article that may help me. You think this would work?
 
Last edited:

JustinW

Super Moderator
Staff member
#46
Well the article didn't help because I didn't try it... had two much stuff in there for such a little task.

Anyway, I'm pleased to say I figured out the problem :smile:

The Solution: Use two one-demensional arrays of the same size. One of them will contain the random numbers while the other contains the information your application needs to work with. After you've assigned in your values for both arrays, you can use Array.Sort, specifying the array containing the random numbers as the first "key" array than specifying the other array you want sorted secondary to however the first one comes out. Example:


Public
Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = ""'String of numbers in thier random order to show
Dim RandomNumbers(0) As Decimal'Array of random numbers used to sort the real numbers randomally so they are unique
Dim Numbers(9) As Integer'Array of actual numbers the application will use
Numbers(0) = 1
Numbers(1) = 2
Numbers(2) = 3
Numbers(3) = 4
Numbers(4) = 5
Numbers(5) = 6
Numbers(6) = 7
Numbers(7) = 8
Numbers(8) = 9
Numbers(9) = 10
For I As Integer = 0 To Numbers.Count - 1
ReDim Preserve RandomNumbers(I)
RandomNumbers(I) = Rnd()
Next
Array.Sort(RandomNumbers, Numbers)
For I As Integer = 0 To Numbers.Count - 1
str &= Numbers(I) & " "
Next
MessageBox.Show(str)
End Sub
End Class
So a few steps away from completing this thing :smile:
 

mqudsi

Mostly Harmless
Staff member
#47
Glad you got it working :smile:

Sorry I didn't have the time to go through your code :frowning:
 

JustinW

Super Moderator
Staff member
#48
Thats alright. Thanks for your help.

Do you happen to know of any properties involving radio buttons where no matter if you change thier text property any default value sticks? I got really far into the project on modifications tonight and now the radio buttons are acting up.

If not I have another copy of the project so I haven't lost everything, but its gonna be hard trying to retrace the changes I've made tonight. Helps to keep a log... shame on me for not doing that :frowning:
 

mqudsi

Mostly Harmless
Staff member
#49
Not sure I understand your question. What do you mean, default value sticks?
 

JustinW

Super Moderator
Staff member
#50
Yep, the default text property was sticking on the radio buttons though I had changed it (or at least I thought it was that at the time), but thats been fixed somewhat. Don't know whats up but the project appears to have some corruption issues going on. At first I discovered it had added new radio buttons that covered the orginals with the default text the originals had on the test form, so I deleted those and the others could be selected with the properties window but were not visible though thier visible property is set to true.

Today, I got it where everything is working except for the first radio button (answer A). Everytime I load it up it doesn't show the text nor the selection circle, though I had it set to true on visible (the default). I suspect the value has been changed like the mysterious adding of the extra controls, well have to investigate this. But if not, I don't know what else to do. I've deleted the control, added a new one by the same name, and even added a new one under a different name and modify all refereences in code to reflect it. Mysteriously it works fine after I've moved on to the next question in the sample file, or go back to 1 from question 2 and than the answer is shown.

I don't want to haft to start this over nor use my backup (its about 10 days old with many changes). The rest of the program is working correctly except for this one crazy radio button...

My plan if all fails on me here is to take the rest of the program except for the test form and import it into a new project. Now what would I need to do that? Just the designer and code files for each form? I would want to copy these files to the new project folder and than import them so they are in the new projects directory.


Addendum:


Alright to update...

Created a new project and imported everything except for the testing form (Basically went back and re-designed it from the ground up)

The earlier described problems have gone away. I have code I put in for the navigation buttons to jump between questions where if the user selected an answer previously for a question on return visit, the answer would be selected (radio button would be checked). Now that's not working...

I seem to be swapping one problem for another. I'll make sure to cover all the bases next time when I'm doing a VS project. You just never know when its gonna decide to choke on you.


Addendum:


Well I don't know what I did but I fixed it by moving the code around and doing some slight modifications (though I didnt see any errors to start with) :smile:

Time to make a copy before my next problem lol


Addendum:


OK. I want to make a search textbox I got execute a button's click event if the user hits the enter key while it has focus. Here's what I tried:

Private Sub txtSearch_Enter(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtSearch.Enter
btnSearch.PerformClick()
End Sub
Would this be correct? Ran it and it didn't do anything when I pressed enter.
 
Last edited:

mqudsi

Mostly Harmless
Staff member
#51
No.
You'd need to handle the KeyPress event, and check if the key that was pressed is an Enter.

.Enter is for when the mouse moves over the button.
 

JustinW

Super Moderator
Staff member
#52
What the FQN of the property I need to use to check for enter? KeyEventArgs?

Addendum:

Ok, I tried:

If e.KeyChar = "&Enter" Then

But that didn't work. Its the either the property or the &Enter part...
 
Last edited:

JustinW

Super Moderator
Staff member
#54
I'm getting this error with it:



Tried converting as well as ""s. That takes away the errors but doesn't work.


Addendum:


Ok, heres the correct way to do it:

Private Sub txtSearch_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSearch.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then

btnSearch.PerformClick()
End If

End Sub

Addendum:

300,000 miliseconds would be the correct interval for a 5 minute timer right? This is the last thing to do :smile: Annoying though if it is correct. Can't seem to figure out what the problem is here...
 
Last edited:

JustinW

Super Moderator
Staff member
#56
That's what I thought, but apparently not. Set it to 600000 for the interval. Works like a charm :heh

Re-calculated all the other avialable time slots according to it.

At this point i'm just trying to comment/clean-up the code. Its pretty much done. Good cause I wanted it done by the end of the weekend so I could start using it :smile:

When I get totally done with this, should I just copy the compiled file from the debug directory to a common apps folder or is it best that I actually build it?
 
Last edited:

mqudsi

Mostly Harmless
Staff member
#57
Build what exactly?
 

JustinW

Super Moderator
Staff member
#58
The solution using the build wizard...

Don't suppose I need to anyway. Don't need an installer for it or anything. Runs just fine on its own.
 

mqudsi

Mostly Harmless
Staff member
#59
Oh... No, I would recommend doing it manually by copying the EXEs and stuff.
 

JustinW

Super Moderator
Staff member
#60
Man it feels good to get something like this done :smile:

All semester we were just doing calculations and displaying stuff on forms. I wanted to take what I've learned over the last few months and build something I could actually use. More importantly, what others may want to use. To put toegether an actual application that is useful on my own pretty much with the help provided here is still amazing to me... On to C# and better programs :smile:

I can only imagine how good it feels to put together the finishing touches on an application like EasyBCD that helps thousands every day. So thanks again for everything....
 
Status
Not open for further replies.