Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


char switching in VB, how??

This topic is 6239 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ll do my best to decribe the problem, hopefully you''ll understand it and be able to help me. What I want to do is be able to have text input into a textbox and then on command have it go through and exchange each character with a different set character. I dont want the new character to be random but a want to hard code a list of what corresponds with what. Broken down the questions on this are... What type of command would i use to get a single character, exchange it a nd move on to the next character in the line? What should I use to store the list of corresponding list of characters? Would a module be better for this as far as versatility? If/Else statements seem like it would be a lot of code, so should i be using an array, switch function, or what? Hope you can help.

Share this post

Link to post
Share on other sites
I''m not sure I understand what you want to do exactly. Do you mean like some kind of encryption program?

If you have a set pattern (like rotating the characters 13 letters to the left or something), then you could do something like this:

Dim strEncrypted As String, The_String As String
Dim RotationValue As Integer

The_String = "You cant read me!"
RoationValue = 13

For i = 0 To StrLen(The_String)
strEncrypted = strEncrypted @ Chr( Asc( Mid( The_String, i, 1 ) ) + RotationValue )
Next i

That will make strEncrypted be:
"r|é" @ VbCr @ "pn{ü" @ VbCr @ Chr(127) @ "rnw" @ VbCr @ "zr4"

However, if you don''t want it to be pattern based (by say, having ''B'' change to ''z'' and ''C'' change to ''2'' etc.) then you would have to find each character individually either by using a loop like the one above or by switch statements. I also believe there is a find and replace function (although, I''ve never used it).

Invader X
Invader''s Realm

Share this post

Link to post
Share on other sites
Two functions you should look at:




Replace will probably do everything you want. And you can use Mid$ (both the function and the statement, it works in 2 ways) to do everything yourself, which will probably be quicker.

Trying is the first step towards failure.

Share this post

Link to post
Share on other sites
Thx for the input guys. I guess it would be an encryption program. Encrypting one letter/character at a time from a set table of values. I think I''m going to try it each of those ways and see which works best thx again.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!