Qbasicnews.com

Full Version: Need serious help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I need help, Our teacher told us to try this program but I have no idea hot it goes. My friend helped me in this but it shows three outputs :oops: can anyone debug this program?

Program is about to input the e-mail address and check whether it is valid or not.

CLS
INPUT "Enter email address"; a$
a$ = UCASE$(a$)
l = LEN(a$)
FOR i = 1 TO l
b$ = MID$(a$, i, 1)
SELECT CASE b$
CASE "@"
e = e + 1
CASE " "
e = e + 1
END SELECT
NEXT i
IF e > 1 THEN PRINT "invalid" ELSE PRINT "valid"
FOR j = 1 TO l
b$ = MID$(a$, j, 1)
SELECT CASE b$
CASE "@"
at = j + 1
CASE "."
at = j - 1
td = j + 1
END SELECT
NEXT j
IF at <> 0 THEN
FOR k = at TO dt
s$ = MID$(a$, k, 1)
s = ASC(s$)
SELECT CASE s
CASE IS <= 64
e1 = e1 + 1
CASE IS >= 91
e1 = e + 1
END SELECT
PRINT e, at, dt, s, e1
NEXT k
END IF
IF td <> 0 THEN
FOR p = td TO l
m$ = MID$(a$, p, 1)
l$ = l$ + m$
NEXT p
END IF
PRINT l$
IF l$ <> "com" THEN c5 = 1
IF e <> 1 OR e1 > 0 OR l = 0 THEN PRINT "invalid" ELSE PRINT "valid"
END
What the hell is that? Is that even code?

Real code: (I left out ".com" validation since there is more than just ".com".)

Code:
DECLARE FUNCTION is.email.address% (text$)
DIM SHARED illegal.charset$
illegal.charset$ = ":;<=>?^]['/" + CHR$(92)

CLS
PRINT is.email.address%("a4@r.5.5.5")

FUNCTION is.email.address% (text$)

len.text% = LEN(text$)
FOR i% = 1 TO len.text%
temp$ = MID$(text$, i%, 1)
SELECT CASE ASC(temp$)
CASE 32: EXIT FUNCTION         'space
CASE 64: IF i% = 1 THEN EXIT FOR
at.exists% = -1: n% = i%       '@
CASE IS > 122: PRINT "N": EXIT FUNCTION
CASE IS < 46: PRINT "N": EXIT FUNCTION
CASE 46: IF at.exists% THEN IF i% - 2 >= n% GOTO dot.remix
EXIT FUNCTION
END SELECT
IF INSTR(illegal.charset$, temp$) <> 0 THEN EXIT FUNCTION
NEXT i%

IF at.exists% THEN is.email.address% = -1
EXIT FUNCTION

dot.remix:
n% = i%
IF i% = len.text% THEN EXIT FUNCTION
DO: i% = i% + 1
temp$ = MID$(text$, i%, 1)
SELECT CASE ASC(temp$)
CASE 32: EXIT FUNCTION
CASE 64: EXIT FUNCTION
CASE IS > 122: EXIT FUNCTION
CASE 46
IF n% >= i% - 1 THEN EXIT FUNCTION
n% = i%
CASE IS < 46: EXIT FUNCTION
END SELECT
IF INSTR(illegal.charset$, temp$) <> 0 THEN EXIT FUNCTION
IF i% = len.text% THEN EXIT DO
LOOP
IF n% = len.text% THEN EXIT FUNCTION
IF at.exists% THEN is.email.address% = -1
END FUNCTION
Quote:What the hell is that? Is that even code?

lol
What is it exsposed to do? (sp?)
see if it could be an email address:

At the very least, it must be:

A@B.C
Well, not really. It could be:

a@b.c
xyz <a@b.c>
"xyz" <a@b.c>
a@b.c (xyz)
a .(xyz)b@c.d
"X.400 Dude" <IMCEAX400-c=au+3Ba=access400+3Ba=access400+3Bp=intenet+3Bdda+3ARFC-822=bhyland+28a+29mailhost+2Eplugged+2Enet+2Eau+3B@dedt.qld.gov.au>

with xyz being descriptive text.

Also, you could have a@b.c.d.e.f.g etc.

But man, that code at the beginning looked like an entry to an obfuscated code contest. Smile
Oh, I didn't realize that..
Hey comp. dudes, i don't know much about programming, as I said, my friend made this program, and OMG,
Can u just write the program in a simple language,,,my teacher will never that a 14 year old kid would do.
It's simpler than yours, batman! How can you say that! I am right now revising it a little...

EDIT: You're needlessly adding and your vars don't say anything about what they do..
Wink lol
Pages: 1 2