|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Does anybody know how to translate this C# code to VB6?and other tricky code to VB6. If anybody could help me it would really make my day. I cannot do it yet. Ulf private class StringReplacementPermuter { private char[] equiChar; private string inputString; private int[] indexIntoString; private int[] indexIntoChar; public StringReplacementPermuter(string inputString, char e, char a) { equiChar = new char[] { e, a }; this.inputString = inputString; } public IEnumerable<string> Permute() { Prepare(); return GetReplacementStrings(0); } private void Prepare() { List<int> occurenceList = new List<int>(); int occurrenceAt = -1; while ((occurrenceAt = inputString.IndexOfAny(equiChar, occurrenceAt + 1)) != -1) { occurenceList.Add(occurrenceAt); } indexIntoString = occurenceList.ToArray(); indexIntoChar = new int[indexIntoString.Length]; } private IEnumerable<string> GetReplacementStrings(int loop) { if (loop == indexIntoString.Length) { yield return ReplaceByMap(); } else { for (int i = 0; i < equiChar.Length; i++) { indexIntoChar[loop] = i; foreach (string os in GetReplacementStrings(loop + 1)) { yield return os; } } indexIntoChar[loop] = 0; } } private string ReplaceByMap() { StringBuilder s = new StringBuilder(inputString); for (int j = 0; j < indexIntoChar.Length; j++) { s[indexIntoString[j]] = equiChar[indexIntoChar[j]]; } return s.ToString(); } } static void Main(string[] args) { foreach (string s in new StringReplacementPermuter("abef", 'a', 'e').Permute()) { Console.WriteLine(s); } Console.Read(); } } First convert it to VB.net, then simplify it and then convert it to VB6.
that would be much easier. "Abhishek" <u***@server.com> wrote in message Here is one C# to VB.Net translator like Abhishek suggested.news:%23FUy2PBoJHA.4872@TK2MSFTNGP04.phx.gbl... > First convert it to VB.net, then simplify it and then convert it to VB6. > that would be much easier. http://authors.aspalliance.com/aldotnet/examples/translate.aspx On 2009-03-09, Nobody <nob***@nobody.com> wrote:
> "Abhishek" <u***@server.com> wrote in message I just tried it, just to see what it would do. This code, is going to be> news:%23FUy2PBoJHA.4872@TK2MSFTNGP04.phx.gbl... >> First convert it to VB.net, then simplify it and then convert it to VB6. >> that would be much easier. > > Here is one C# to VB.Net translator like Abhishek suggested. > > http://authors.aspalliance.com/aldotnet/examples/translate.aspx > > difficult even to translate to VB.NET because it uses a feature of C# (yield return) that is not supported by the VB.NET language. It's not impossible, but would require more work... -- Tom Shelton "Tom Shelton" <tom_shel***@comcastXXXXXXX.net> wrote in message Yeh there's no simple translation into VB6. You could try making enumerable news:%23gex2bOoJHA.1168@TK2MSFTNGP05.phx.gbl... > > I just tried it, just to see what it would do. This code, is going to be > difficult even to translate to VB.NET because it uses a feature of C# > (yield > return) that is not supported by the VB.NET language. It's not > impossible, > but would require more work... > classes, creating a new one for each of the iterations so as to store the state, but it's going to be messy. I think I'd approach this using nested For Each loops. With strings that shouldn't make a difference.
Show quote
Hide quote
"Ulf Christenson" <u.christen***@googlemail.com> wrote in message I've used a C to VB converter with pretty good results.news:ujFlR2AoJHA.996@TK2MSFTNGP03.phx.gbl... >I have this code, but I don't know how to translate these IEnumerable and other tricky >code to VB6. > If anybody could help me it would really make my day. I cannot do it yet. > Ulf > > private class StringReplacementPermuter > { > private char[] equiChar; > private string inputString; > private int[] indexIntoString; > private int[] indexIntoChar; > public StringReplacementPermuter(string inputString, char e, char a) > { > equiChar = new char[] { e, a }; > this.inputString = inputString; > } > > public IEnumerable<string> Permute() > { > Prepare(); > > return GetReplacementStrings(0); > } > > private void Prepare() > { > List<int> occurenceList = new List<int>(); > int occurrenceAt = -1; > while ((occurrenceAt = inputString.IndexOfAny(equiChar, occurrenceAt + > 1)) != -1) > { > occurenceList.Add(occurrenceAt); > } > > indexIntoString = occurenceList.ToArray(); > indexIntoChar = new int[indexIntoString.Length]; > } > > private IEnumerable<string> GetReplacementStrings(int loop) > { > if (loop == indexIntoString.Length) > { > yield return ReplaceByMap(); > } > else > { > for (int i = 0; i < equiChar.Length; i++) > { > indexIntoChar[loop] = i; > > foreach (string os in GetReplacementStrings(loop + 1)) > { > yield return os; > } > } > > indexIntoChar[loop] = 0; > } > } > > > private string ReplaceByMap() > { > StringBuilder s = new StringBuilder(inputString); > > for (int j = 0; j < indexIntoChar.Length; j++) > { > s[indexIntoString[j]] = equiChar[indexIntoChar[j]]; > } > > return s.ToString(); > } > > } > > static void Main(string[] args) > { > foreach (string s in new StringReplacementPermuter("abef", 'a', > 'e').Permute()) > { > Console.WriteLine(s); > } > > Console.Read(); > } > } If you want to try it http://home.surewest.net/galen/download/CtoVB.zip Galen The code I posted is C#, but the C to VB6 converter is amazing anyway!!
But it only accepts header files. Is there a version out there that converts .c files to VB6 as well? The only converters I found were C to VB.NET, but not to VB6. Thanks a lot! Ulf
Wrap a Long String
Determining Available Paper Sizes on Printer Subclassing a la Caton Number Puzzle vb6 closes with erro after I installed msdn oct 2001 Error #429 and compactdatabase in VB6 ListBox bug? Using VBPRNDLG.DLLl Instead of Print Common Dialog Boxes VSM Wants Your Feedback Control Container Property - Why Use It? |
|||||||||||||||||||||||