Author Topic: Concatation Of Variable Number of Parameters in a Sub  (Read 1562 times)

0 Members and 1 Guest are viewing this topic.

Offline PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Concatation Of Variable Number of Parameters in a Sub
« on: April 13, 2011, 10:59:55 AM »
0
I was looking at building a sub that accepts a variable data set and wondering what the most efficient way to reassign the parameters might be.

Specifically, I wanted to run through the parameters in an ascending loop assigning the parameters to a series of variables using concatation.

The result should be that it will assign parameter values to your variable X in ascending order as %X1, %X2, etc, until it has given each parameter a variable assignment.

This is the structure of what I came up with:

Code: [Select]
Gosub Parameter_Parser 1 12 123 1234 12345 123456
Halt

Sub Parameter_Parser
Set %TotalParameters %0
Set %ParameterCount 0
Repeat
      {
      Set %ParameterCount %ParameterCount + 1
      Set %CurrentParameter % . %ParameterCount
      Set %X . %ParameterCount %CurrentParameter
      Display Parameter %ParameterCount of %TotalParameters total is %X . %ParameterCount
      }
Until %ParameterCount = %TotalParameters
return
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Concatation Of Variable Number of Parameters in a Sub
« Reply #1 on: April 13, 2011, 01:32:53 PM »
0
same thing condensed

Code: [Select]
Gosub Parameter_Parser 1 12 123 1234 12345 123456
Halt

Sub Parameter_Parser
  Set %TotalParameters %0
  for %ParameterCount 1 %TotalParameters
      Set %X . %ParameterCount % . %ParameterCount
return

I use simular code for a sub to make one sentance with space

Code: [Select]
gosub makeline  this is a test. this is only a test.
display ok #result
halt

sub makeline
  if %0 > 0
    {
    set #result
    for %x 1 %0
       set #result #result , #spc , % . %x
    }
return #result
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Tags: