Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Incrementing The AlphaNumeric

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,39041
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Incrementing The AlphaNumeric
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Incrementing The AlphaNumeric - 10/23/2006 9:38:06 PM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Greetings,

I'm trying to figure out a creative way to increment a 4 digit alphanumeric

It can only b 4 digits ranging from 0000 --> ZZZZ

Anyone have an idea how this could be accomplished? Do I have to treat this as a Base 36 number to get the job done or is there a different method?

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch
 
 
Post #: 1
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 12:18:59 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
strTest = "1234"
WScript.Echo Right("0000" & CInt(strTest) + 1, 4)
strTest = "0001"
WScript.Echo Right("0000" & CInt(strTest) + 1, 4)

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TNO)
 
 
Post #: 2
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 12:28:46 AM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Umm, not quite. Its alphanumeric not just Numeric

What if it was numbers like the following?

1234
612A
99Z4
D001
etc...

And any other random combination of 0-9 & A-Z, I'd like to be able to increment these numbers regardless of wether its Alpha or Numeric
so:

1234 + 1 --> 1235
612A + 1 --> 612B
99Z4 + 1 --> 99Z5
D001 + 1 --> D002
And so on. I'm pretty certain that if the "number" was treated as a Base 36 number it would be possbile but I'm not sure what the vbscript equivalent of parseInt(numString, [radix]) is.

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 12:35:26 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Sorry...didn't see that alphas were possible. I have a question. what would "123Z" become?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TNO)
 
 
Post #: 4
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 1:00:49 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Nevermind. I'm not really awake yet. I actually read your post and realize that if it were base 36 then 123Z would become 1240. Then I assume that ZZZZ would become 0000. I'll ponder it. I'm sure it can be done it's just a matter of the best way.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 1:11:37 AM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
it would become 124A

the base consists of 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 1:12:41 AM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
I looked at this post and went "Oooh challenging!" and then went "Oooh...err..wait a minute that'll make my head hurt".

Then I thought about it some more and have now wasted an hour trying out various methods.

You bastard 

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 1:18:32 AM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
What I'm thinking of is to convert base 36-->base 10, add 1, then convert back to base 36 for the result. Too bad the only functions available in vbscript are Hex and Oct

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ginolard)
 
 
Post #: 8
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 1:21:38 AM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
quote:

it would become 124A


err...1240, I'm confusing myself with base 36 thinking

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to TNO)
 
 
Post #: 9
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 1:26:41 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Here is a first pass at a solution. See if you can poke some holes in it:


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TNO)
 
 
Post #: 10
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 2:32:22 AM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Looks like that will do it. You've just about inspired me to recreate a generic parseInt function for vbscript 

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 2:35:40 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Good luck. I don't think I would want to.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TNO)
 
 
Post #: 12
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 3:03:48 AM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Well, I think I'm retarded for not treating this problem like I do for base 2....taking out the remainders.
when you divide a base 10 number by its radix and keep the remainder, then when you convert the remainder the result will be what you want but written backwards.

I got a JavaScript equivalent for the parseInt method but I'm a bit rusty still and need some help in translating it over to vbscript:


      

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 13
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 4:23:01 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Oooh...I like using the string for the values. Not so hip with treating it as a global rather than putting it in a function. Am I reading it wrong or will it only work for a 4 character string?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TNO)
 
 
Post #: 14
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 4:42:20 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Ok, so if I understand correctly, you should be able to hand a ParseInt function a string and a Radix. The function will treat the string as a base-Radix number and return the base-10 equivalent. Do I have that right? If so, I think this will do it:


      


No error checking though. It should probably make sure that the string is at least a valid base-radix number at the least.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 15
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 5:12:15 AM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
The code I posted was a bit erroneous in its conversion (I originally intended it for Hex)

The basic concept of making a generic base conversion function is this:

As with all bases there is a simple algorithm for converting a representation of a number to a base by doing integer division and remainder operations in the source base

So basically it works like this

Let d be the number to represent in hexadecimal, and the series hihi-1...h2h1 be the hexadecimal digits representing the number.
  1. i := 1
  2. hi := d mod 16
  3. d := (d-hi) / 16
  4. If d = 0 (return series hi) else increment i and go to step 2
"16" may be replaced with any other base that may be desired.



So I think a better function than my original would be the following:




      



It would be optimal to use some BitWise operators but I haven't used them often enough in the past couple years to be proficient with them

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 16
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 5:47:26 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Did you try my function? I don't think yours does the same thing as mine. Maybe I misunderstand, but ParseInt() in java simply converts any base number to base 10. is that not the goal here as well? I get a stack error with your code.:

      

(7, 14) Microsoft JScript runtime error: Out of stack space


Looks like an infinite loop problem.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TNO)
 
 
Post #: 17
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 5:57:42 AM   
  mcds99


Posts: 433
Score: 4
Joined: 2/28/2006
Status: offline
This is not an answer to your question but a comment/question.

Not fully understanding the math in this, it is amazing that I even understand some of it.

Math not being my strongest suit in college, I made it through calculus and trigonometry, barley.

I find it so much fun to at least try to figure out the how and why of the code.

What is this used for?

The reason I ask is when IPv6 lands this sort of scripting will be invaluable for DNS and DHCP administration.

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to TNO)
 
 
Post #: 18
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 6:01:15 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
I read this:

quote:

Math not being my strongest suit in college, I made it through calculus and trigonometry, barley.


And thought you only got through math by using lots of barley (mixed with hops of course).

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mcds99)
 
 
Post #: 19
 
 RE: Incrementing The AlphaNumeric - 10/24/2006 5:54:54 PM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Ok, I'm pretty sure I got it now. (amazing what sleep can do)


      

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Incrementing The AlphaNumeric Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts