6 Replies - 7064 Views - Last Post: 10 November 2007 - 04:06 PM Rate Topic: -----

#1 liquid198  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 22-October 07

Nested Selct case Help

Post icon  Posted 22 October 2007 - 07:07 PM

Dim Units As String
		Dim Totaldue As Integer

	  If  Select Case Units
			Case 1 To 3
				Totaldue = "15"
			Case 4 To 8
				Totaldue = "14"
			Case Is > 8
				Totaldue = "12"
			Case Else
				MessageBox.Show(Message,Marine Packing" 
				MessageBoxButtons.OK, MessageBoxIcon.Information

	  Else

if Select Case  Units

Case 1 to 4
   Total due="10"
Case >4
   Total due ="9"
end select




*I know this is wrong.. what im trying to do is the order clerks will enter a name, number of units ordered, and whether the customer is a retailer or wholesaler. It shoud calculate the amount due.Use a messagebox.show method to display a message when the user enters a 0 or a negative number as the number of units. also use the messagebox.show to display a message when the user enters a letter other than W or R. im a total beginner.. struggling

*Always use code tags for your code, like this :code:

This post has been edited by PsychoCoder: 22 October 2007 - 07:39 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Nested Selct case Help

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Nested Selct case Help

Posted 22 October 2007 - 07:51 PM

Well for starters you cant use If Select Case..., the compiler wont like that and will scream at you. It also looks as if you're using 2 select cases, is this for 2 separate products?I think the easiest way to accomplish this would be something like

Dim Units As String
Dim Totaldue As Integer
'Check to make sure they entered a retail or wholesale customer
If Not CustomerType = "W" And Not CustomerType = "R" Then
		MessageBox.Show("Customer type must be W or R","Marine Packing" MessageBoxButtons.OK, MessageBoxIcon.Information)
'Make sure they entered a value greater then 0 (*zero)
ElseIf Not Units > 0 Then
		MessageBox.Show("Amount ordered must be greater than 0","Marine Packing" MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
	  'Our select case for the product type
	  Select Case Product
		   'Product type 1
		   Case Product1
				  'Now determine the amount owed
				  'based on the number of uints
				  Select Case Units
						Case 1 To 3
							 Totaldue = "15"
						Case 4 To 8
							 Totaldue = "14"
						Case Is > 8
							 Totaldue = "12"
				   End Select
			'Product type 2
			Case Product2
					'Now determine the amoutn due based
					 'on the number of units sold
					Select Case Units
						  Case 1 to 4
								Total due="10"
						  Case >4
								Total due ="9"
				   End Select
		End Select
End If



If this is close to what you're looking for great, if not let me know exactly what you're looking for ok.
Was This Post Helpful? 0
  • +
  • -

#3 liquid198  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 22-October 07

Re: Nested Selct case Help

Posted 22 October 2007 - 08:04 PM

yes that what im looking for.. as i told you im a total beginner.. and struggling.. but have a strong "Very" strong desire to learn.. I do have a question as to another way it can be done.. this is just for my head only.. My teacher has not showed us.. to do ...



Select Case Product
'Product type 1
Case Product1


Then go down and enter a Case product 2...


i was very intrigued when I saw it this way.. I am constantly searching other ways of learning so it "fits right in my head" So thanks on that and for the fast reply.. Also.. If you had a problem like this .. would u do it select case? or Nested if,then,else? the entire sentence structure. Which one do u think would be easiest ?
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Nested Selct case Help

Posted 22 October 2007 - 08:08 PM

I would do it the way I showed you if I was solving this problem. Generally when I give someone code examples its an example of how I would do it myself.

As for the select case statements. What you have is a select case inside a select case. The first select case is for your products

Select Case Products
	 Case Product1
		 'Do your stuff her
	 Case Product2
		 'Do your stuff here
End Select



The 2nd Select Case is being used for the number of units purchased, and theres a select case inside each products case.

In my opinion nested select case statements are easier to read and maintain than multiple nested if..elseif..else statements.
Was This Post Helpful? 0
  • +
  • -

#5 liquid198  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 22-October 07

Re: Nested Selct case Help

Posted 22 October 2007 - 08:29 PM

View PostPsychoCoder, on 22 Oct, 2007 - 08:08 PM, said:

I would do it the way I showed you if I was solving this problem. Generally when I give someone code examples its an example of how I would do it myself.

As for the select case statements. What you have is a select case inside a select case. The first select case is for your products

Select Case Products
	 Case Product1
		 'Do your stuff her
	 Case Product2
		 'Do your stuff here
End Select





The 2nd Select Case is being used for the number of units purchased, and theres a select case inside each products case.

In my opinion nested select case statements are easier to read and maintain than multiple nested if..elseif..else statements.


* Was there supposed to be a statement in here somewhere?

This post has been edited by PsychoCoder: 22 October 2007 - 08:33 PM

Was This Post Helpful? 0
  • +
  • -

#6 liquid198  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 22-October 07

Re: Nested Selct case Help

Posted 22 October 2007 - 08:42 PM

i have gotten all the down and corrected my errors and added the appropaite code..
i also have to determine whether the value entered in the number of units control contains data and if that value can be converted into a number or not..


can u send me in the right direction to learn how to do this.. the only examples i have seen is like this


Dim isoldok as boolean
dim israteok as boolean

If is oldok andalso israteok then
Newpay=oldpay+newpay *raiserate


I am studying this and im not sure how it relates to the above select case you were helping me with.. also.. im not even sure.. why a programmer would need this..
Was This Post Helpful? 0
  • +
  • -

#7 ferrari12508  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3
  • View blog
  • Posts: 1,115
  • Joined: 02-November 07

Re: Nested Selct case Help

Posted 10 November 2007 - 04:06 PM

im not understanding why you used if select case, just use select case
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1