»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 03-09-2004, 07:36 AM   #1 (permalink)
Registered User
 
Join Date: Mar 2004
Location: Scotland
Posts: 17
norty is on a distinguished road
Visual Basics

Hello

Im working with visual basic for my college assessment. It is a prototype of an ATM (bank machine).

Ive came across a problem, can anyone help me?

Ive got to put in 5 passwords with different balances, the code i have put in is

Quote:
Private Sub Form_Load()
If realpincode(1) = "0000" Then balance = 100
Else
If realpincode(2) = "1234" Then balance = 300
Else
If realpincode(3) = "3020" Then balance = 1000
Else
If realpincode(4) = "0007" Then balance = 250
Else
If realpincode(5) = "5678" Then balance = 600
Else
If realpincode(6) = "9009" Then balance = 700
End If
End If
End If
End If
End If
End If
but an error is comig up saying that 'Else without If', where the first else is.

Any ideas??

Thanx in advance

Norty xxx

norty is offline   Reply With Quote
Old 03-09-2004, 07:40 AM   #2 (permalink)
Registered User
 
novadragoon's Avatar
 
Join Date: Jan 2003
Posts: 84
novadragoon is on a distinguished road
Send a message via AIM to novadragoon
try adding and deleting one end if, in Vis C that sometimes helps
__________________

Group: Members
Posts: 262
Contributions: 8
Member No.: 439
Joined: 17-August 01



just as the title says

http://ccb056.zapto.org/cupholder.htm

--------------------
'You must've torn out the "Q" section in my dictionary, because I don't know the meaning of the word "quit"! '
-Mr. Furious, Mystery Men
novadragoon is offline   Reply With Quote
Old 03-09-2004, 07:43 AM   #3 (permalink)
Guest
Guest
 
Posts: n/a
Correctly, you should use If (statement) then Esle If (statement) until the last one and then just use Else. You only need on End If like novadragoon says.

BTW, cool avatar, nova.

Code:
Private Sub Form_Load()
   If realpincode(1) = "0000" Then balance = 100
   
   Else If realpincode(2) = "1234" Then balance = 300

   Else If realpincode(3) = "3020" Then balance = 1000

   Else If realpincode(4) = "0007" Then balance = 250

   Else If realpincode(5) = "5678" Then balance = 600

   Else If realpincode(6) = "9009" Then balance = 700

   End If
Honestly, I would write like:
Code:
Private Sub Form_Load()
   If realpincode(1) = "0000" Then
      balance = 100
   Else If realpindcode(2) = "1234" Then
      balance = 300
   End If
You do realize that you're incrimenting through your array while you're checking the variable though, right? I mean, chances are, by the way you have it set up, that (1) will always be "0000" and (2) will always be "1234" and so on. Wouldn't you want to check a single input against the array to determine which of the pin numbers has been input instead, and then set the balance according to which of the array was input?
  Reply With Quote
Old 03-09-2004, 07:44 AM   #4 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
Step 1: Use the [ code ] tag for code, so you don't lose your indents

Step 2: What in the world are you trying to do here?!

Are you trying to do

If <condition> Then
Do something
ElseIf <condition> Then
Do something
ElseIf <condition> Then
Do Something
End If

???
IF thats the case then you only need ONE end if and its spelled 'ElseIf' as one word.

NOW if you're trying to do a
If <condition> Then dosomething
If <condition Then DoSOmething...

Thats not a good coding practice.

Also your use of an array here is quite confusing
To me I would think you'd only have ONE PIN... not an array of PIN's but please explain what you're trying to do
Can you give some pseudocode of what you're trying to do?

The only way I could interpret your code is that you're trying to do
If realpincode(1) = "0000" Then balance = 100
ElseIf realpincode(2) = "1234" Then balance = 300
ElseIf realpincode(3) = "3020" Then balance = 1000
ElseIf realpincode(4) = "0007" Then balance = 250
ElseIf realpincode(5) = "5678" Then balance = 600
ElseIf realpincode(6) = "9009" Then balance = 700
End If


Welcome to TechIMO
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 03-09-2004, 07:45 AM   #5 (permalink)
Registered User
 
Join Date: Mar 2004
Location: Scotland
Posts: 17
norty is on a distinguished road
Thanx, ill try that!

Norty xxx
norty is offline   Reply With Quote
Old 03-09-2004, 07:48 AM   #6 (permalink)
Guest
Guest
 
Posts: n/a
Oooh, it is one word. Wow am I out of practice.
  Reply With Quote
Old 03-09-2004, 07:52 AM   #7 (permalink)
Registered User
 
Join Date: Mar 2004
Location: Scotland
Posts: 17
norty is on a distinguished road
Thanx Vass0922

Sorry bad description, what im trying to do is...

Make a prototype of a bank machine, but in the requirements to pass it for my assessment i have got to have 5 passwords to work , each with a different balance.

Does that make any more sense?

It is an array im trying to do.

yes what you wrote( below), reading it thats what im trying to do

If realpincode(1) = "0000" Then balance = 100
ElseIf realpincode(2) = "1234" Then balance = 300
ElseIf realpincode(3) = "3020" Then balance = 1000
ElseIf realpincode(4) = "0007" Then balance = 250
ElseIf realpincode(5) = "5678" Then balance = 600
ElseIf realpincode(6) = "9009" Then balance = 700
End If


thanx, ill try writing that code in, as you have written it!

Norty xxx
norty is offline   Reply With Quote
Old 03-09-2004, 08:00 AM   #8 (permalink)
Registered User
 
Join Date: Mar 2004
Location: Scotland
Posts: 17
norty is on a distinguished road
Quote:
Originally posted by Whir

You do realize that you're incrimenting through your array while you're checking the variable though, right? I mean, chances are, by the way you have it set up, that (1) will always be "0000" and (2) will always be "1234" and so on. Wouldn't you want to check a single input against the array to determine which of the pin numbers has been input instead, and then set the balance according to which of the array was input? [/B]
Im fairly new to visual basic, what youve said seems way better than what ive tried to do.

Unfortunately ive no idea how i would begin to do what you have written!

Norty xxx
norty is offline   Reply With Quote
Old 03-09-2004, 08:06 AM   #9 (permalink)
Guest
Guest
 
Posts: n/a
Well, it would require a loop, but there would only need to be one If statement in that case. You could either use a While or a For statement. I like For statements, but they're not as versatile as While.

This will take a while to explain and I'm on my way out the door, but if vass checks back, he should understand what I'm getting at.

Hmm, on second approach, it looks as though you'd need a multilayer array. Or something like that. My head hurts. I'll check back when I get home. Good luck.
  Reply With Quote
Old 03-09-2004, 08:08 AM   #10 (permalink)
Registered User
 
Join Date: Mar 2004
Location: Scotland
Posts: 17
norty is on a distinguished road
Thanx Whir

Norty xxx
norty is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 03:23 PM.