Posted January 5, 201114 yr Hope someone can give me a hint, because I have the following code copied from reflector(VB.NET) into vb express edition 2010, but I have a lot of errors, so I started fixing the code, but i ended with an error, which it seems I , not yet, can't resolve myself. Here she comes:Private Function genRandomLetter(ByVal rand As Random) As CharReturn IIf((rand.Next(1, 3) = 1), DirectCast(rand.Next(&H41, 90), Char), DirectCast(rand.Next(&H61, &H7A), Char)))End FunctionAnd here is the error:Error 2 'Integer' values cannot be converted to 'Char'. Use 'Microsoft.VisualBasic.ChrW' to interpret a numeric value as a Unicode character or first convert it to 'String' to produce a digit.This solution offered seems to be impossible, only error after error.So, I tried to declare "Char" as string, as Integer and as Object, but unfortunately, "Char" can't be used.So I used "x" or whatever,instead of "Char" as char/string/integer, no good again.This solution doesn't work for me at all! Here are the Imports I included:Imports System.ReflectionImports System.Reflection.EmitImports System.Windows.FormsImports System.Security.CryptographyImports System.TextImports System.ComponentModelImports System.GlobalizationImports System.ThreadingImports System.WindowsImports Microsoft.VisualBasic.CompilerServicesThat's about it, any tips are welcome.Thnxgrizzmo
January 5, 201114 yr Public Function GenerateRS(ByVal Length As Int32) As String Dim Base As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" Dim Chars() As Char = Base.ToCharArray Dim FinalString As New System.Text.StringBuilder(Length) Dim RN As New Random(Now.Millisecond) For i As Int32 = 1 To Length FinalString.Append(Chars(RN.Next(0, Chars.Length - 1))) Next Return FinalString.ToString End Function
January 6, 201114 yr Author Thanks for the code Kurapica,I made my own solution with someones else help, here she comes:Private Function genRandomLetter(ByVal rand As Random) As Char Return IIf((rand.Next(1, 3) = 1), Convert.ToChar(rand.Next(&H41, 90)), Convert.ToChar(rand.Next(&H61, &H7A))) End FunctionAlso convert Integer to Char, whithout any probs.Have a nice day and thanks for your time. Edited January 6, 201114 yr by grizzmo
Create an account or sign in to comment