Normal Topic Simplifying Programming Code (Read 403 times)
Louis Galvao
Full Member
***
Offline


"Sufferin' Succatash"

Posts: 265
Location: Canada
Joined: Feb 14th, 2005
Simplifying Programming Code
Oct 21st, 2005 at 8:56pm
Print Post Print Post  
Given that I attended the programming course way back at the end of June, I should know this by now, but functions, sub-routines and loops throw me for a loop !

I have the following code which is simple, works fine but is repetitive in nature adding to the lines of code.

In affect, it calls on a global value and provides a specific pop up menu to choose from.

The code on element entry goes like this:

var VChoice as string

//popup is placed directly over Description field

PopupSelectPosition(4, @XPos(DESCRIPTION), @YPos(DESCRIPTION))

If Category = "Client Relations" Then
{
     VChoice = @GlobalValue("Client Relations")
     Description = @PopupMenu(VChoice, "Select an Item")
}
else
If Category = "Computer Maintenance"
{
     VChoice = @GlobalValue("Computer Maintenance")
     Description = @PopupMenu(VChoice, "Select an Item")
}
else
If Category = "Corporate Promotions"
{
     VChoice = @GlobalValue("Corporate Promotions")
     Description = @PopupMenu(VChoice, "Select an Item")
}
else
If Category = "Media Advertising" Then
{
     VChoice = @GlobalValue("Media Advertising")
     Description = @PopupMenu(VChoice, "Select an Item")
}
else
If Category = "Market Brochures"
{
     VChoice = @GlobalValue("Market Brochures")
     Description = @PopupMenu(VChoice, "Select an Item")
}
else
If Category = "Newsletters" Then
{
     VChoice = @GlobalValue("Newsletters")
     Description = @PopupMenu(VChoice, "Select an Item")
}
else
If Category = "Stationery" Then
{
     VChoice = @GlobalValue("Stationery")
     Description = @PopupMenu(VChoice, "Select an Item")
}


I need a hint as to how to simplify this code above so I can apply it to other applications.

Thanks,

Louis
  

Louis Galvao
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Simplifying Programming Code
Reply #1 - Oct 21st, 2005 at 9:20pm
Print Post Print Post  
Hello Louis,

From what you have posted I see no reason to have a big If statement, when the GlobalValue that you are referring to has the same name as the value in Category. Something like the following should do the trick for you.

Code
Select All
Var VChoice as String

//popup is placed directly over Description field

PopupSelectPosition(4, @XPos(DESCRIPTION), @YPos(DESCRIPTION))

VChoice = @GlobalValue(Category)
Description = @PopupMenu(VChoice, "Select an Item") 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Louis Galvao
Full Member
***
Offline


"Sufferin' Succatash"

Posts: 265
Location: Canada
Joined: Feb 14th, 2005
Re: Simplifying Programming Code
Reply #2 - Oct 21st, 2005 at 9:37pm
Print Post Print Post  
Ray:

That is unbelievable !

It works the exact same way, but you have taken 37  lines of code and shrunk them down to 4 !

I have to get more familiar with these global values to better utilize them in other applications.  I am tired of taking the long way home.

Thanks and have a great weekend.

Louis
  

Louis Galvao
Back to top
 
IP Logged