Page Index Toggle Pages: 1 [2]  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) Help with ThisElement in a Subroutine or Function (Read 5081 times)
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
 
Page Index Toggle Pages: 1 [2] 
Send Topic Send Topic Print Print