Mini rant on coding. - Chicagoland Sportbikes
Chicagoland Sportbikes
 
Geek Squad to the rescue! fucken computer crashing on you again? another porn site infected your computer? tierd of your wife seeing your anal fisting videos and want to lock her out of the external HD? get the answers you need from our local computer experts.

 
LinkBack Thread Tools Display Modes
post #1 of 9 (permalink) Old 03-30-2007, 04:46 PM Thread Starter
 
Join Date: Apr 2002
Posts: 6,882
           
Mini rant on coding.

Sorry this is one of those times I gotta share and there's gotta be a coder or developer here that's gone through this more than once Now I've written a fair amount of code...SQL, VB, C++ and developed some programs that I'm proud of. Usually this happens without a hitch. But then there are times when you need to create a such a simple little thing that turns into more lines than you expected and a whole helluva lot more thought than ever imagined. The task? Look at a field. If there are any lower case letters in it then consider it a failure...otherwise it passes. Simple I figured...just see if "Ucase(field) = field" and presto in one line...not so fast. The friggen code to do this simple task?

stringvar x;
numbervar i;
stringvar z;
numbervar strLen;
global stringvar UCaseCheck := 'Pass';

strLen := len({Command.Invoice Number});
x := totext({Command.Invoice Number});
z := totext({Command.Invoice Number});
ucase(x);

For i := 1 to strLen Do
(
Local NumberVar charPos := i;
if AscW(x[charPos]) <> AscW(z[charPos]) then UCaseCheck := 'Fail';
);

UCaseCheck;

Last edited by BIGGY; 03-30-2007 at 04:49 PM.
BIGGY is offline  
Sponsored Links
Advertisement
 
post #2 of 9 (permalink) Old 03-30-2007, 05:23 PM
SV650N
 
crashomon's Avatar
 
Join Date: Jul 2005
Location: Over by Toyota Park
Posts: 3,117
Location: Over by Toyota Park
Sportbike: 2005 SV650SN
Years Riding: Since 1980
How you found us: craigslist
           
Time to start using PHP!
crashomon is offline  
post #3 of 9 (permalink) Old 03-30-2007, 05:32 PM
Irony helps us play!
 
Arch's Avatar
 
Join Date: Jan 2006
Location: N'ville
Posts: 29,508
Location: N'ville
Sportbike: 2000 F4
Years Riding: Long enough to know better
How you found us: some hot MILF whispered it in my ear
           
Doesn't your string start at position [0] and not [1] ?

...at least in C it does... in which case 'i' should initialize at 0

What lang is that?

Everyone Exaggerates

We're being taken for a ride... agaaaaaaain.....


Best Auto/Moto Insurance | Motorcycle Protection Today | FREE Trade-In Quote
Arch is offline  
Sponsored Links
Advertisement
 
post #4 of 9 (permalink) Old 03-30-2007, 05:46 PM
[Online]
 
Fracker's Avatar
 
Join Date: Mar 2005
Location: Chicago
Posts: 3,695
Location: Chicago
Sportbike: Multistrada 1100S; CBR600RR
Years Riding: Since 2004
How you found us: CRR
           
It looks like Crystal Reports script. This is a fucking abomination.


+1 on what Arch said - I don't remember how it is in Crystal Reports, but it can be 0-based string.

Wait, why do you even compare them letter by letter? Why doesn't "Ucase(field) = field" work?

- Stas

Thou shalt not disfigure the soul.
Fracker is offline  
post #5 of 9 (permalink) Old 03-30-2007, 10:56 PM Thread Starter
 
Join Date: Apr 2002
Posts: 6,882
           
The language is Crystal syntax of VB6. You can write one of a few languages. If things like DIM is your cup'o'tea then it'll accept it too. i = 1 works for Crystal Reports. Don't ask me why, but yea everywhere else it's been 0. 0 works too though.

As for comparing straight "ucase(field) = field". That does not work because crystal will not tell a difference between caps vs not except in certain instances like 'instr', 'filter', etc... So in crystal syntax...'AAA' = 'aaa' is true including any other combo's 'AaA' = 'aAA...etc.

This meant that I had to convert to ascii and compare the numbers. However AscW only takes the first letter, so in order to check the entire string you gotta do the loop.
BIGGY is offline  
post #6 of 9 (permalink) Old 03-30-2007, 11:50 PM
Irony helps us play!
 
Arch's Avatar
 
Join Date: Jan 2006
Location: N'ville
Posts: 29,508
Location: N'ville
Sportbike: 2000 F4
Years Riding: Long enough to know better
How you found us: some hot MILF whispered it in my ear
           
I assume you tried:

x := UpperCase(totext({Command.Invoice Number}));
y := totext({Command.Invoice Number});

if x<>y then UCaseCheck := 'Fail';

???

Everyone Exaggerates

We're being taken for a ride... agaaaaaaain.....


Best Auto/Moto Insurance | Motorcycle Protection Today | FREE Trade-In Quote
Arch is offline  
post #7 of 9 (permalink) Old 03-31-2007, 12:38 AM Thread Starter
 
Join Date: Apr 2002
Posts: 6,882
           
Yup. Although that would fail based on the first test I did which was:
if 'AAA' = 'aaa' then BAD else GOOD. By the nature of Crystal I guess it never compares case unless you tell it to.

But good that no one just whipped out an answer in 3 seconds of some magical function that I never heard of Makes me feel not as dumb for taking an hour to figure out that the others fail, and then to write these few lines

Last edited by BIGGY; 03-31-2007 at 12:41 AM.
BIGGY is offline  
post #8 of 9 (permalink) Old 03-31-2007, 01:04 AM
Irony helps us play!
 
Arch's Avatar
 
Join Date: Jan 2006
Location: N'ville
Posts: 29,508
Location: N'ville
Sportbike: 2000 F4
Years Riding: Long enough to know better
How you found us: some hot MILF whispered it in my ear
           
Even tried compareStr() ? basically, like strcmp() and it's supposed to be case sensitive.

Everyone Exaggerates

We're being taken for a ride... agaaaaaaain.....


Best Auto/Moto Insurance | Motorcycle Protection Today | FREE Trade-In Quote
Arch is offline  
post #9 of 9 (permalink) Old 04-01-2007, 01:15 PM
 
Join Date: Apr 2003
Posts: 1,038
           
Evertime I see code I can't help but think about maintaining code. If you haven't read this book already, I highly recommend it as one of the best resources available on writing quality, efficient and maintainable code.

Code Complete - Steve McConnell

P.S. - I don't write or even look at code very often anymore. I became a project manager partly because my code was usually ugly and a PITA to maintain by anyone other than me. But I am always on my Tech Leads to include more than functional checks in their code reviews.
flinchy is offline  
Reply

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the Chicagoland Sportbikes forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may 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 On
Trackbacks are On
Pingbacks are On
Refbacks are On

 
For the best viewing experience please update your browser to Google Chrome