grizzmo Posted January 5, 2011 Posted January 5, 2011 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
Kurapica Posted January 5, 2011 Posted January 5, 2011 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
grizzmo Posted January 6, 2011 Author Posted January 6, 2011 (edited) 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, 2011 by grizzmo
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now