Hot Topic (More than 10 Replies) Help with ThisElement in a Subroutine or Function (Read 5074 times)
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Help with ThisElement in a Subroutine or Function
Aug 16th, 2004 at 5:33pm
Print Post Print Post  
I was trying to improve upon my existing code by creating a subroutine to replace code I used in every telephone number element and thought I could make use of the new command ThisElement released in version 1.0.4.

The code below was what I was using to properly format and control the data for a telephone number.
// Formats Telephone Number (not Subroutine)

var vHPhone as String    
var vNewHPhone As String 
var vhphonecount
var vhpnentered

     Vhpnentered = @num(HomePhone)
     // Writeln(Vhpnentered)
     
     vhphonecount = @num(@len(vhpnentered))
     //writeln(vhphonecount)

If vhphonecount = "10"


{
     @color(HomePhone,0,7)
     vHPhone = @Num(HomePhone)
     vNewHPhone = "(" + @Left(vHPhone, 3) + ") " + @Mid(vHPhone, 4, 3) + "-" + @Right(vHPhone, 4)
     HomePhone = vNewHPhone 
}
else
{
     @color(HomePhone,7,1)
     @msgbox("The Telephone Number needs to be Exactly 10 Digits", "The numbers you entered " +
     @num(Homephone),"is : " + Vhphonecount + " Digits Please check Home Telephone and Re-enter")
     
}   

Originally I used this code in on element change on every telephone element by copying and changing the element name.  I have since learned that the better method would be to create a subroutine or a function that will be called from each element.  So I tried creating a subroutine (see below) It does not work.


//  Formats Telephone Number with a Subroutine using ThisElement

Subroutine FormatPhone() // Name of Subroutine

// Declare Variables
var vHPhone as String    
var vNewHPhone As String 
var vhphonecount
var vhpnentered

// set Variables to empty
var vHPhone = “”   
var vNewHPhone = “” 
var vhphonecount = “”
var vhpnentered = “”

// Setting variable Vhpnentered to @num of element called from.

     Vhpnentered = @num(ThisElement)      // Writeln(Vhpnentered)

// Calculating number of digits
     
     vhphonecount = @num(@len(vhpnentered))
     //writeln(vhphonecount)

// how to handle if or if not 10 digits

If vhphonecount = "10"


{
     @color(ThisElement,0,7)
     vHPhone = @Num(ThisElement)
     vNewHPhone = "(" + @Left(vHPhone, 3) + ") " + @Mid(vHPhone, 4, 3) + "-" + @Right(vHPhone, 4)
     ThisElement = vNewHPhone 
}
else
{
     @color(ThisElement,7,1)
     @msgbox("The Telephone Number needs to be Exactly 10 Digits", "The numbers you entered " +
     @num(ThisElement),"is : " + Vhphonecount + " Digits Please check Home Telephone and Re-enter")
      
}   


End Subroutine

I placed this code in Global Code section

And in my telephone elements on element change I put FormatPhone()

I thought that this would call the subroutine named FormatPhone and pass the Element Name it was called from. I seem to be misunderstanding the correct method to create my subroutine

Can someone comfortable with Subroutines and functions please explain were I went wrong. Some of us are slow learners and need a little more help then others. (This shows the importance of the upcoming Sesame conference and Masters Seminar classes in October)

Thanks,

Robert
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #1 - Aug 16th, 2004 at 5:39pm
Print Post Print Post  
Robert,

I see a couple of issues. One is that you are not typing two of your variables. This will cause them to be Ints. However, you treat them as Strings. This can cause strange behavior.

Your description of how your code should be working is correct. In what way is it failing? Does it not run at all? Produce incorrect results?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #2 - Aug 16th, 2004 at 6:26pm
Print Post Print Post  
Quote:
Robert,

I see a couple of issues. One is that you are not typing two of your variables. This will cause them to be Ints. However, you treat them as Strings. This can cause strange behavior.


That is a Rookie Error.  Angry

I have changed these from string to integer and back a dozen times this weekend. Must of left them off by accident. I even removed the section that sets the variables to null. I will correct and see if that solves my problem

Quote:
Robert,

Your description of how your code should be working is correct. In what way is it failing? Does it not run at all? Produce incorrect results?


It runs inconsistently and does not run every time. I figured I was doing something incorrect with ThisElement because my other subroutines seem to work fine. If you do not see anything flagrantly wrong with my process other then my declarations I will correct my errors and contact Tech support if my problem continues.

Thanks for the Quick Response as always You guys and gals are the best. Cheesy

  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #3 - Aug 16th, 2004 at 6:30pm
Print Post Print Post  
ThisElement does exactly what you think it does, and you are doing just what you should be doing by making a subroutine and using it in this way.

Let me know if you need help getting it straightened out.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #4 - Aug 16th, 2004 at 7:16pm
Print Post Print Post  
Just to be official I figured I would point out that while upgrading using ThisElement it was also appropriate to replace the old @color command with the improved and more consistant RGBColor() command and the replacement of  the problematic not to be used Goto with ThrowFocus()

{
     RGBColor(ThisElement,0,0,0,255,255,255)
     vHPhone = @Num(ThisElement)
     vNewHPhone = "(" + @Left(vHPhone, 3) + ") " + @Mid(vHPhone, 4, 3) + "-" + @Right(vHPhone, 4)
     ThisElement = vNewHPhone 
}
else
{
     RGBColor(ThisElement,255,255,255,255,0,0)
     @msgbox("The Telephone Number needs to be Exactly 10 Digits", "The numbers you entered " +
     @num(ThisElement),"is : " + Vhphonecount + " Digits Please check Home Telephone and Re-enter")
       Throwfocus(ThisElement)
      
}   


End Subroutine
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #5 - Aug 16th, 2004 at 7:18pm
Print Post Print Post  
Boy, somebody was paying attention in the SBasic class!  Grin

Gold stars for Robert!!!  Grin Grin Grin
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #6 - Aug 17th, 2004 at 3:21pm
Print Post Print Post  
I figured I was on a subroutine roll so I created a few more to handle some simple tasks like first letter capitalization and things like that.

I then created one that checks the validity of a zip code by counting digits and comparing information contained in your zipcode samples database. All was going well until I tried returning values to other fields based on that lookup.

In this example I had the user enter the zip code and then on element exit I want to do a lookup into the zipcode database and return the city, state, time zone, county and +4 digits if available.

I can do this easily if I place my code in all the elements and specifically name the element I want data returned to

Xlookup("C:\Sesame\Data\Samples\ZipCode.db", homezip, "zip code", "city", Homecity)
      Xlookup("C:\Sesame\Data\Samples\ZipCode.db", homezip, "zip code", "state", Homestate)
      Xlookup("C:\Sesame\Data\Samples\ZipCode.db", homezip, "zip code",  "Full county", HomeCounty)
      Xlookup("C:\Sesame\Data\Samples\ZipCode.db", homezip, "zip code",  "Time Zone", HomeTZ)

But

If I want to do this in a subroutine I can change the first parameter to ThisElement  because that stays constant but I need to specify different elements that receive the data.

Can you point me in the direction of the methods you recommend I employ to do that?

Thanks
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #7 - Aug 17th, 2004 at 3:39pm
Print Post Print Post  
1. I recommend you use @XLookupSourceList instead of the multiple XLookups. It's much faster.  Smiley

2. You can use @ElementName(ThisElement) to get and use the name of ThisElement. That way, you can use an If...Then to behave differently based on which element is current.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #8 - Aug 17th, 2004 at 4:27pm
Print Post Print Post  
I must be missing something  ???   Because if I understand you correctly your saying I should use @ElementName(ThisElement) to identify were the subroutine is being called from and then change the parameters accordingly:

Basically create a subroutine that tests for the element I am working with and set my variables to the ones needed something sort of like this:

Var vfrom as string
Var vcity as string
Var vstate as string
Var vzip as string
Var vcounty as string
Var vtimezone as string

Vfrom = @ElementName(ThisElement)

If Vfrom = Homezip
{
     vstate = Homestate
     vcity = HomeCity
     vzip = HomeZip
     vcounty = HomeCounty
     vtimezone = HomeTz
}
Else If Vfrom = Workzip
{
     vstate = Workstate
     vcity = WorkCity
     vzip = WorkZip
     vcounty = WorkCounty
     vtimezone = WorkTz
}
Else If Vfrom = Shipzip
{
     vstate = Shipstate
     vcity = ShipCity
     vzip = ShipZip
     vcounty = ShipCounty
     vtimezone = ShipTz
}
Else If Vfrom = Otherzip
{
     vstate = Outherstate
     vcity = OutherCity
     vzip = OutherZip
     vcounty = OutherCounty
     vtimezone = OutherTz
}

@XlookupSourceList(“C:\Sesame\Data\Samples\ZipCode.db",ThisElement,”
zipcode”,”state;city;zip;county;timezone”)

and then return the values to vstate, vcity, vzip, vcounty.vtimezone.

If  I am understanding this correctly would it not be simpler and easier to put separate code in each element or is there an advantage I am missing or am I totally going down the wrong path?

Sorry if I am being dense I am just trying to get a good grasp on the concepts not just the way to accomplish the task.

Thanks
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #9 - Aug 17th, 2004 at 4:39pm
Print Post Print Post  
Using a subroutine is fine for this, but your pseudocode isn't going to work as is, for several reasons, most of which have to do with the difference between a string (element name) and an element reference. I know you like to figure things out, and I don't want to spoil your fun. Do you want me to show you a working example of how to do this, or do you want to figure it out for yourself?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #10 - Aug 17th, 2004 at 4:47pm
Print Post Print Post  
When you say the:

(difference between a string (element name) and an element reference.)

Are you reffering to element name verses field it is bound to or ?   ???

Thanks
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #11 - Aug 17th, 2004 at 4:59pm
Print Post Print Post  
Quote:
When you say the:

(difference between a string (element name) and an element reference.)

Are you reffering to element name verses field it is bound to or ?   ???

Thanks


"HomePhone" is a string. HomePhone (no quotes) is an element reference. If you use an element reference, you either get the value in the element or the element itself, depending on context. Therefore, for example,

If Vfrom = Homezip
compares the value in vFrom to the value in Homezip.

If Vfrom = "Homezip"
compares the value in vFrom to the string "Homezip".

And so on...
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #12 - Aug 17th, 2004 at 5:08pm
Print Post Print Post  
Sure,  I got that. The one in the quote is the literal the other is what is contained in the element.

Ok show me how I should be doing this subroutine. Sesame version 99999999.0.5 might be released by the time I get this on my own.

Thanks for the help.
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #13 - Aug 17th, 2004 at 5:38pm
Print Post Print Post  
Here's how I'd do it. I'd actually make three procedures.
1. A generic function that can lookup a bunch of address info based on a zip code.
2. An assignment subroutine that sorts out where the values go.
3. A subroutine to put them together to minimize the repeated code.

By separating them, I end up with a nice generic function that is usable on other Forms.

NOTE: I don't have your Form, so I'm just typing off the top of my head. There may be compile errors.  Also, the routines could probabaly use some error handling. :)
[code]
GLOBAL CODE::GLOBAL CODE

FUNCTION GetLocationInfo(vZip as String) As String
var vRet as String

    vRet = ""
    vRet = @XlookupSourceList("C:\Sesame\Data\Samples\ZipCode.db", vZip, "zipcode", "state;city;zip;county;timezone")
    Return(vRet)

END FUNCTION

SUBROUTINE AssignLocationInfo(vName as String, vVals as String)
Var vstate as string 
Var vcity as string
Var vzip as string
Var vcounty as string
Var vtimezone as string

  vstate = @AccessStringArray(vVals, 1)
  vcity = @AccessStringArray(vVals, 2)
  vzip = @AccessStringArray(vVals, 3)
  vcounty = @AccessStringArray(vVals, 4)
  vtimezone = @AccessStringArray(vVals, 5)

If vName = "Homezip"
{
Homestate = vstate
HomeCity = vcity
HomeZip = vzip
HomeCounty = vcounty
HomeTz = vtimezone
}
Else If vName = "Workzip"
{
Workstate = vstate
WorkCity = vcity
WorkZip = vzip
WorkCounty = vcounty
WorkTz = vtimezone
}
Else If vName = "Shipzip"
{
Shipstate = vstate
ShipCity = vcity
ShipZip = vzip
ShipCounty = vcounty
ShipTz = vtimezone
}
Else If vName = "Otherzip"
{
Otherstate = vstate
OtherCity = vcity
OtherZip = vzip
OtherCounty = vcounty
OtherTz = vtimezone
}

END SUBROUTINE

SUBROUTINE DoAssignLocationInfo()
var vName as String
var vZip as String
var vLVals as String

    vName = @ElementName(ThisElement)
    vZip = ThisElement
    vLVals = GetLocationInfo(vZip)
    If @Len(vLVals) > 0
    {
       AssignLocationInfo(vName, vLVals)
    }
   
END SUBROUTINE
[/code]

Then, in each element event where needed:
[code]DoAssignLocationInfo()[/code]
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #14 - Aug 17th, 2004 at 8:01pm
Print Post Print Post  
Erika,

Thanks these examples are really helpful.  Smiley

This is good learning material for reverse engineering how things are done. It seems I need to confront Arrays head on. I have not really confronted them in detail yet.

Is Arrays still a topic being covered in the classes in October?

I also need to get a better understanding of  function versus subroutine. I am re-reading that section once again. Eventually it will sink in.

Finally is the reason you would make this a routine instead of a quick cut, paste and edit for each element you  would call this from mainly for better speed or is it just good programming practices to routine and function as much as possible.

Thanks again
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #15 - Aug 17th, 2004 at 8:13pm
Print Post Print Post  
Quote:
Erika,

Thanks these examples are really helpful.  Smiley

This is good learning material for reverse engineering how things are done. It seems I need to confront Arrays head on. I have not really confronted them in detail yet.

Keep in mind that I have not used actual Arrays here. I'm using a StringArray, which is nothing more than a semicolon-separated list of values, just like you'd see in a Keyword field. Much easier to work with than true arrays.

Quote:
Is Arrays still a topic being covered in the classes in October?

I believe Tom plans to cover arrays at one of the Masters Seminars. Of course, Arrays will still be covered in the full-length SBasic classes that I'll start giving after the Conference.

Quote:
I also need to get a better understanding of  function versus subroutine. I am re-reading that section once again. Eventually it will sink in.


There is only one difference: a function returns a value; a subroutine does not return a value.

Quote:
Finally is the reason you would make this a routine instead of a quick cut, paste and edit for each element you  would call this from mainly for better speed or is it just good programming practices to routine and function as much as possible.


All of the above.
1. As a procedure, you can change it in one place, and all your zip code fields will fall into line automatically.
2. Less code, less compile time.
3. Self-documenting
4. Etc...

There are so many good reasons to use procedures. Many of them will become clear simply through using them. I'm very glad to see you taking this direction with your code.   Grin
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #16 - Aug 18th, 2004 at 7:26pm
Print Post Print Post  
Why does this show no errors when I test with the goto but errors with Throwfocus? Does it have something to do with the fact that goto ends the program and ThrowFocus allows the programming to finish?

What do I have wrong?

SUBROUTINE DoAssignLocationInfo()
var vName as String
var vZip as String
var vLVals as String

// checks for 5 digits in zip code

If @len(@num(ThisElement)) <>5 then

{
@Msgbox("The ZipCode Must be" , "at least five digits." , "Please correct the entry.")

     // RGBColor(ThisElement,",",",255,0,0)
      Throwfocus ThisElement
}
else

{

    vName = @ElementName(ThisElement)
    vZip = ThisElement
    vLVals = GetLocationInfo(vZip)


    If @Len(vLVals) > 0
    {
   AssignLocationInfo(vName, vLVals)
    }
}   
END SUBROUTINE

I also tried this and 2000 other possibilities


SUBROUTINE DoAssignLocationInfo()
var vName as String
var vZip as String
var vLVals as String


    vName = @ElementName(ThisElement)
    vZip = ThisElement
    vLVals = GetLocationInfo(vZip)

// checks for at least 5 digits in zip code

If @len(@num(vzip)) <> 5 then

{
     @Msgbox("The ZipCode Must be" , "at least five digits." , "Please correct the entry.")

     // RGBColor(ThisElement,255,255,255,255,0,0)
      ThrowFocus vzip
}
else

{


    If @Len(vLVals) > 0
    {
   AssignLocationInfo(vName, vLVals)
    }
}   
END SUBROUTINE
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #17 - Aug 18th, 2004 at 7:36pm
Print Post Print Post  
ThrowFocus needs paretheses.
ThrowFocus(myzip)

GoTo is a legacy command from Q&A and does not have parentheses. ThrowFocus() is an SBasic procedure and wants the parentheses.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #18 - Aug 18th, 2004 at 7:48pm
Print Post Print Post  
Quote:
ThrowFocus() is an SBasic procedure and wants the parentheses.



Dang it,  Embarrassed I have read page 12 of the 1.0.4 supplement at least 200 times since yesterday, No Kidding.  I have tried everything with the code possible and a simple basic thing like that messes me up. (Shame on me) I was so busy looking for something wrong with the logic I missed the simplest thing. Embarrassed Embarrassed

Thanks for the help, Sorry it was for something so stupid. Undecided
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #19 - Aug 18th, 2004 at 8:45pm
Print Post Print Post  
Does the way commands and subroutines get nested affect the @Msgbox?
With my code below I need to press ok 3 times before the box disappears.
Am I missing something simple again?


SUBROUTINE DoAssignLocationInfo()
var vName as String
var vZip as String
var vLVals as String

// checks for at least 5 digits in zip code

If @len(@num(ThisElement)) <> 5 then

{
     @Msgbox("The ZipCode Must be" , " five digits." , "Please correct the entry.")

     // RGBColor(ThisElement,255,255,255,255,0,0)
      ThrowFocus (ThisElement)
}

else
{
    vName = @ElementName(ThisElement)
    vZip = ThisElement
    vLVals = GetLocationInfo(vZip)



    If @Len(vLVals) > 0
    {
   AssignLocationInfo(vName, vLVals)
    }
}   
END SUBROUTINE
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #20 - Aug 18th, 2004 at 8:54pm
Print Post Print Post  
The combination of the @MsgBox and the ThrowFocus may be creating an event loop, depending on where things are being called. I can't tell without seeing the rest of your code.

Regardless, you may want to consider using the alternate method of data validation that I showed you in the SBasic class, rather than creating a "trap".   Wink
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #21 - Aug 18th, 2004 at 9:41pm
Print Post Print Post  
Quote:
you may want to consider using the alternate method of data validation


Oh  (light bulb just went on)

Yes the failure flag and notify stuff. So many tools, so much teaching so little memory.

Time to re-read that section.  I have lots of traps to replace.

Thanks for the reminder.

  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #22 - Aug 19th, 2004 at 1:51pm
Print Post Print Post  
The phrase that comes to my mind is: "Control the data, not the user".

As an ancilliary: "It is better to accept a mistake than enforce one".

As an example, take phone numbers: From my phone in a office building, any of the following are legal phone numbers:

*8
3-81
011-49-222-444-111
1-800-555-1200 @ 444
1-800-555-1200 ext 4444
751-1212
(321) 123-1234
(321) 123-4444-8-1234
(321) 123-4444 or (321) 123-9999 if after noon, but before 6:00
+49-222-444-111

The variety is pretty much endless. The situation is similiar with postal codes, first and last names, currency, any unit of measurement, etc...

The irony of this seemingly untenable situation is that the humans using the computer deal with it fine, it really only becomes a problem when the programmer/designer attempts to enforce an overly narrow set of conditions on the users. In other words, the programmer tries to make the user create uniformity in data, where uniformity is actually incorrect.

If, you enforce that a phone number must be (xxx) xxx-xxxx, you will begin to see addtions, notes, and alterations appearing in less frequently used fields nearby. That reduces the value of the phone number field (which is usually only used by humans that can and do understand that "Ext" and "@" both mean "extension") and the nearby field, that starts to become nonsensical.

Very often the best thing a programmer can do to prevent typos while still allowing for the correct non-conformity of data, is to be adaptive. Check the data against a set of known good formats, if it matches none of them, ask the user if they are sure. If they are, add that "new" format to the list of known good formats.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #23 - Aug 19th, 2004 at 2:33pm
Print Post Print Post  
Quote:
The phrase that comes to my mind is: "Control the data, not the user".

As an ancilliary: "It is better to accept a mistake than enforce one".


Not only do you guys and gals offer training in the technical side of coding you offer us philosophical wisdom as well


When learning something like Sbasic I spend lots of time on the technical aspects of the task I want to have accomplished. I need to remember I also need to put time into the philosophical side to coding. As corny as it sounds I almost need to add a mission statement to my code that tests / validates  my approach to what I am trying to accomplish to make sure it is of real value.

It is ironic I need to build a validation routine for me as much as I believed I needed them for others.

Thanks for the insight.

  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Help with ThisElement in a Subroutine or Funct
Reply #24 - Aug 19th, 2004 at 3:51pm
Print Post Print Post  
Quote:
Very often the best thing a programmer can do to prevent typos while still allowing for the correct non-conformity of data, is to be adaptive. Check the data against a set of known good formats, if it matches none of them, ask the user if they are sure. If they are, add that "new" format to the list of known good formats.

Excellent suggestion Mark!  Grin
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged