![]() |
VB.NET: Loops - calculate selected items
Dear Members
I am new to this forum and I am very excited to join you and learn from you and I hope able to share from my knowledge. I have a problem with the following code which I extracted from my program. I have been going well until this section of my program and I hope someone is able to assist me. Basically, this section of my program should calculate selected list items within a loop. I have a feeling I am horribly off track. Could someone please give me an idea where I am going wrong as I am striving to make my programs as efficient as possible. I look forward to your response. Thanking you in anticipation:) :
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click |
Welcome to the forums.
When you say 'horribly off track', are you suggesting that it's producing wrong results? |
Thank you for your prompt reply. When I run my program, this is the error message:
Quote:
Thanks |
first off, which line is it blowing up on? insert a breakpoint on the line before that and see what the values in your variables involved in the crash are.
sounds like you're trying to put something bad into an integer. |
My program starts hanging on this line ...
:
If lstYachtSize.SelectedItem(0) And cboYachtType.SelectedItem(0) ThenThe variables indicate "22" for the yacht size and "C&C" for the yacht type. So, if the user selects a yacht size and type, the calculation for these 2 selections should place the total in a label. Any ideas as to what I am doing wrong? |
This has a chance to be of no use but still, I found the way things are linked in vb using 'and', 'and also' etc sometimes can have issues that are not of much concern, Dont know why but it seems to spit perfectly sensible code back at you. so out of curiosity try this :
:
Do While intIndex < lstYachtSize.Items.CountIt makes for repetitive code but beats drinking coffee and staring at whats already there. |
I would suggest that "C&C" is not a variable that is amenable to calculation of a total. That seems to be what you're suggesting.
|
Loops
Dear Members
I have finally managed to get the code to work. I was very silly as it was not logical to place the code within a loop. The program does not require a repetition of actions nor does it search for items in a list. I therefore did not require the loop as I had already selected the item and then needed to do the calculation. Also, the calculation really has nothing to do with the selection of yacht type. I guess I needed the weekend break to see all this logic. See correct code below: :
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.ClickThanks once again for your patience and all your wonderful input. I hope I am able to assist any other novices like myself in this forum. Best Regards |
| All times are GMT -5. The time now is 12:46 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC