Jump to content



Photo

create if...elseif statement Visual basic

visual basic vb

  • Please log in to reply
58 replies to this topic

#31 OP soccerstar206

soccerstar206

    Neowinian

  • Joined: 19-August 13

Posted 24 August 2013 - 22:53

Thanks for all the help guys! Every one of your helpful comments contributed to me getting an A on the assignment!




#32 adrynalyne

adrynalyne

    Neowinian Senior

  • Joined: 29-November 09

Posted 24 August 2013 - 23:11

Anyone who can not use If statements, case select, or for if loops should not

be in a programming class.

Programming classes are there to teach, are they not? 

 

Although I think if someone has trouble with something this simple, they might want to take up another skill. Like knitting. 



#33 +warwagon

warwagon

    Only you can prevent forest fires.

  • Tech Issues Solved: 2
  • Joined: 30-November 01
  • Location: Iowa

Posted 24 August 2013 - 23:27

Programming classes are there to teach, are they not? 

 

Although I think if someone has trouble with something this simple, they might want to take up another skill. Like knitting. 

 

Yep, I learned LONG ago that programming was not for me.



#34 Joe User

Joe User

    Lazy Joe's

  • Tech Issues Solved: 1
  • Joined: 29-May 07
  • Location: Somewhere in the US
  • OS: Windows 8.1 Update 1
  • Phone: Nexus 5

Posted 24 August 2013 - 23:46

10 price = 7.50
20 if age > 62 then price = 5.50
30 if age < 20 then price = 4.50
40 if age < 12 then price = 3.50
50 if age < 6 then price = 0

 

Wait, was this supposed to be in Commodore 64 BASIC?

 

(Yes, this is a horrible example of coding, it's deliberate)



#35 Top Qat

Top Qat

    Neowinian

  • Tech Issues Solved: 6
  • Joined: 09-July 04
  • Location: London, UK
  • OS: Windows 8.1u1 and Server 2012 R2u1
  • Phone: Samsung Galaxy S 3

Posted 25 August 2013 - 00:42

Some more examples for your education:

 

REXX

/* REXX */
arg intAge .

select
when intAge <   6 then decTicketPrice = 0
when intAge <= 12 then decTicketPrice = 3.5
when intAge <= 19 then decTicketPrice = 4.5
when intAge >  62 then decTicketPrice = 5.5
otherwise              decTicketPrice = 7.5
end

return decTicketPrice

Cobol

01 DECTICKETPRICE			PIC S9(5)V99 COMP-3.
01 INTAGE				PIC 9(3) COMP-3.

EVALUATE TRUE
WHEN INTAGE <  6
	MOVE ZERO TO DECTICKETPRICE
WHEN INTAGE <= 12
	MOVE 3.5  TO DECTICKETPRICE
WHEN INTAGE <= 19
	MOVE 4.5 TO DECTICKETPRICE	
WHEN INTAGE >  62 
	MOVE 5.5 TO DECTICKETPRICE
WHEN OTHER
	MOVE 7.5 TO DECTICKETPRICE
END-EVALUATE.

Easytrieve Plus (v6.4 up)

DECTICKETPRICE				W	4 P 2
INTAGE					W	2 P

IF      INTAGE LT  6
	DECTICKETPRICE = 0
ELSE-IF INTAGE LE 12
	DECTICKETPRICE = 3.5
ELSE-IF INTAGE LE 19
	DECTICKETPRICE = 4.5
ELSE-IF INTAGE GT 62
	DECTICKETPRICE = 5.5
ELSE
	DECTICKETPRICE = 7.5
END-IF


#36 Joe User

Joe User

    Lazy Joe's

  • Tech Issues Solved: 1
  • Joined: 29-May 07
  • Location: Somewhere in the US
  • OS: Windows 8.1 Update 1
  • Phone: Nexus 5

Posted 25 August 2013 - 00:48

 

Some more examples for your education:

 

REXX

 

Needs more GOTO's.



#37 FloatingFatMan

FloatingFatMan

    Resident Fat Dude

  • Tech Issues Solved: 1
  • Joined: 23-August 04
  • Location: UK

Posted 25 August 2013 - 06:52

Thanks for all the help guys! Every one of your helpful comments contributed to me getting an A on the assignment!

 

Now there's a misrepresented grade if ever I saw one.



#38 CGW-88

CGW-88

    ||Modified||

  • Joined: 16-July 12
  • OS: Windows 8.1
  • Phone: Lumia 625

Posted 28 August 2013 - 14:45

Tbh it seems the OP didn't even try to do this.

if you pseudocode what is required for this you have pretty much written the code....especially considering its to be written in vb.

if x = x then
y = y
else
if x = z then
y = y1
else
'etcetceyc

if you are doing a programming course OP and your posting like this.......you wont get far im sorry.

#39 Top Qat

Top Qat

    Neowinian

  • Tech Issues Solved: 6
  • Joined: 09-July 04
  • Location: London, UK
  • OS: Windows 8.1u1 and Server 2012 R2u1
  • Phone: Samsung Galaxy S 3

Posted 29 August 2013 - 12:17

Needs more GOTO's.

 

Challenge accepted!

 

REXX

/* REXX */
arg intAge .

/* There is no 'GOTO' in REXX. The statement to use is 'SIGNAL'					 */
/* This is the unconditional form of 'SIGNAL ON' that is used to catch exceptions	*/

if intage < 6 then do
		decticketprice = 0
		signal my_ass
	end
  
if intage <= 12 then do
		decticketprice = 3.5
		signal my_ass
	end
	
if intage <= 19 then do
		decticketprice = 4.5
		signal my_ass
	end
	
if intage > 62 then do
		decticketprice = 5.5
		signal my_ass
	end
	
decticketprice = 7.5

my_ass.

return decticketprice

Cobol

01 DECTICKETPRICE			PIC S9(5)V99 COMP-3.
01 INTAGE					PIC 9(3) COMP-3.

SOME-BOLLOCKS-CODE SECTION.

	IF INTAGE < 6
		MOVE ZERO TO DECTICKETPRICE
		GO TO MY-ASS
	END-IF.
	
	IF INTAGE <= 12
		MOVE 3.5  TO DECTICKETPRICE
		GO TO MY-ASS
	END-IF.
	
	IF INTAGE <= 19
		MOVE 4.5 TO DECTICKETPRICE	
		GO TO MY-ASS
	END-IF.
	
	
	IF INTAGE > 62 
		MOVE 5.5 TO DECTICKETPRICE
		GO TO MY-ASS
	END-IF.

	MOVE 7.5 TO DECTICKETPRICE.

MY-ASS.
	EXIT.

Easytrieve Plus

DECTICKETPRICE				W	4 P 2
INTAGE						W	2 P

SOME-BOLLOCKS-CODE. PROC

	IF INTAGE LT 6
		DECTICKETPRICE = 0
		GO TO MY-ASS
	END-IF

	IF INTAGE LE 12
		DECTICKETPRICE = 3.5
		GO TO MY-ASS
	END-IF
	
	IF INTAGE LE 19
		DECTICKETPRICE = 4.5
		GO TO MY-ASS
	END-IF
	
	IF INTAGE GT 62
		DECTICKETPRICE = 5.5
		GO TO MY-ASS
	END-IF

	DECTICKETPRICE = 7.5

MY-ASS.

END-PROC


#40 Joe User

Joe User

    Lazy Joe's

  • Tech Issues Solved: 1
  • Joined: 29-May 07
  • Location: Somewhere in the US
  • OS: Windows 8.1 Update 1
  • Phone: Nexus 5

Posted 29 August 2013 - 19:54

 

Challenge accepted!

 

Very good try, but I expected this done DOS batch language.



#41 Top Qat

Top Qat

    Neowinian

  • Tech Issues Solved: 6
  • Joined: 09-July 04
  • Location: London, UK
  • OS: Windows 8.1u1 and Server 2012 R2u1
  • Phone: Samsung Galaxy S 3

Posted 29 August 2013 - 21:20

Challenge accepted (again)!

Echo off
set intAge=%1%
if %intAge% LSS  6 (
	SET decTicketPrice=0
	goto done
)
if %intAge% LEQ 12 (
	SET decTicketPrice=3.5
	goto done
)
if %intAge% LEQ 19 (
	SET decTicketPrice=4.5
	goto done
)
if %intAge% GTR 62 (
	SET decTicketPrice=5.5
	goto done
)
set decTicketPrice=7.5

:done
Echo Ticket price is %decTicketPrice%



#42 PUC_Snakeman

PUC_Snakeman

    Neowinian

  • Tech Issues Solved: 1
  • Joined: 24-July 01

Posted 29 August 2013 - 21:27

Alright, but now I want a for-loop to add to the TicketPrice in 0.5 increments. The for-loop must be called from all places that populate the final value.

Do it!



#43 abecedarian paradoxious

abecedarian paradoxious

    cell tech

  • Tech Issues Solved: 1
  • Joined: 04-November 07

Posted 29 August 2013 - 21:56

Write an If..ElseIf  statement (or Select Case if you prefer) given the following:

 

decTicketPrice                    ‘ticket price

intAge                                  ‘age of customer   

 

If customer's age is less than 6, ticket price is Free

 

If customer's age is 6 to 12, ticket price is $3.50

 

If customer's age is 13 to 19, ticket price is $4.50

 

If customer's age is over 62, ticket price is $5.50

 

Otherwise, ticket price is $7.50

All values of age were covered in the criteria; so no need for any 'else' statements.

 

But if you insist:

 

float decTicketPrice = 7.50;   // default ticket price

if (intAge < 6) decTicketPrice = 0.00 // under 6 are free

     else decTicketPrice = 3.50; // 6 and over base price is 3.50

 

/* The above statement just screwed up the teacher's requirement */

/* of an 'otherwise' ticket price since the customer is either under 6 */

/* or 6 or above. Dumb teacher giving dumb assignment fails.         */

 

if (intAge > 12) decTicketPrice += 1.00; // over 12 adds a dollar

if (intAge > 62) decTicketPrice += 1.00; // over 62 adds another dollar



#44 adrynalyne

adrynalyne

    Neowinian Senior

  • Joined: 29-November 09

Posted 29 August 2013 - 21:58

All values of age are covered; no need for any 'else' statements.

 

float decTicketPrice = 0.00;

if (intAge >= 6) decTicketPrice += 3.50;

if (intAge >= 12) decTicketPrice += 1.00;

if (intAge >= 62) decTicketPrice += 1.00;

VB doesn't use semicolons to end a line ;)



#45 Lord Method Man

Lord Method Man

    Neowinian Senior

  • Tech Issues Solved: 1
  • Joined: 18-September 12
  • OS: Windows 8.1 Pro
  • Phone: Nokia Lumia 1520

Posted 29 August 2013 - 21:59

All values of age are covered; no need for any 'else' statements.

 

float decTicketPrice = 0.00;

if (intAge >= 6) decTicketPrice += 3.50;

if (intAge >= 12) decTicketPrice += 1.00;

if (intAge >= 62) decTicketPrice += 1.00;

 

Doesn't cover the $7.50 cost if they are between 19 and 62.





Click here to login or here to register to remove this ad, it's free!