By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,080 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,080 IT Pros & Developers. It's quick & easy.

Problems with enumeration and do/loop, while/ endwhile, for/next

P: 3
Hello everyone,

I'm brand new to this forum and have not yet trolled through all the posts so bear with me please.

I am a beginner at VB.Net programming (using VB express 2008) and (of course) am having some trouble with a particular assignment for my programming class.

I am trying to enumerate an array as simply as possible but I lack some experience. I am not allowed to use anything predefined to create this list. but here goes.

This is the code I have so far:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
  2.         Dim rows As Integer
  3.         Dim Sum As Integer
  4.         Dim Spacing As Integer
  5.         Dim Pins As Integer
  6.         Dim Cost As Integer
  7.         Dim Revenue As Integer
  8.         Dim Profit As Integer
  9.         Dim Average As Integer
  10.         Dim counter As Integer
  11.         Pins = 'Here's where the breakdown occurs...How do I make the program (while enumerating columns) prompt me for Pins values?
  12.         counter = 0
  13.         Sum = 0
  14.         rows = numIterations.Value And rows <> 0
  15.         If rows >= 1 Then
  16.             Spacing = Int(1000 / rows)
  17.         End If
  18.         Do Until (Int(rows) >= rows)
  19.             counter = counter + 1
  20.             While (counter <= rows)
  22.                 For Spacing = 1 To 1000 Step 2
  23.                 Next
  24.                 Cost = 100000 + 12 * Pins
  25.                 Revenue = Pins * (1000 - Pins)
  26.                 Profit = Revenue - Cost
  27.                 Sum = Sum + Profit
  30.             End While
  31.         Loop
  32.         txtTable.AppendText("Number                         " & "Cost                         " & "Revenue                         " & "Profit                         ")
  33.         txtTable.AppendText(ControlChars.CrLf)
  34.         If rows >= 1 Then
  35.             Average = Sum / rows
  36.         End If
  37.         txtTable.AppendText(ControlChars.CrLf)
  38.         txtTable.AppendText(ControlChars.CrLf)
  39.         txtTable.AppendText("Average Profit: " & FormatCurrency(Average).ToString())
  41.     End Sub
It's supposed to look like 4 columns with the info for each row lined up under its corresponding column. The form setup is a label that describes what belongs in the numupdownbox with a button next to it to activate this section of code above. I am almost sure that I have something out of order but I don't know what. In essence however, the problem I have is this: how does telling the code above how many rows there are (by way of numIterations.Value) equate to a prompt for the value "pins"? There are no syntax errors or exception errors that VB studio can find - it does exactly what I tell it to do during debugging (I'm just not telling it what want correctly, apparently).
I realize this topic is probably beaten to death but at this point anything I can get by way of advice or a nod in the right direction is for the grade on this assignment...I don't even care about it - I just want to know so I can get it right.

Thanks in advance
Oct 12 '08 #1
Share this Question
Share on Google+
2 Replies

P: 3
please disregard, I posted in the wrong area
Oct 12 '08 #2

Expert Mod 15k+
P: 31,709
Any interested parties can find the repost here (Loop and enumeration problems).
Oct 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.