PDA

View Full Version : string generator help! change code .vb


marhanen
06-21-2006, 09:42 PM
I found this code on the internet its kind of what i want but i'm not sure how i'm suppose to use it and i wanted it to post the results in a text file

so i guess i'm asking how do i run it and how can i change it so that it will post results in a text document

i'll just post all the files that came with

AssemblyInfo.vb

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("2BDB74C2-527B-41E8-868A-8905921A20DF")>

' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:

<Assembly: AssemblyVersion("1.0.*")>


--------------------------------------------------------------------------

Module1.vb

Module Module1
Sub Main()
Dim KeyGen As RandomKeyGenerator
Dim NumKeys As Integer
Dim i_Keys As Integer
Dim RandomKey As String

''' MODIFY THIS TO GET MORE KEYS - LAITH - 27/07/2005 22:48:30 -
NumKeys = 20

KeyGen = New RandomKeyGenerator
KeyGen.KeyLetters = "abcdefghijklmnopqrstuvwxyz"
KeyGen.KeyNumbers = "0123456789"
KeyGen.KeyChars = 12
For i_Keys = 1 To NumKeys
RandomKey = KeyGen.Generate()
Console.WriteLine(RandomKey)
Next
Console.WriteLine("Press any key to exit...")
Console.Read()
End Sub
End Module


-------------------------------------------------------------------------


RandomKey.sln

Microsoft Visual Studio Solution File, Format Version 8.00
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "RandomKey", "RandomKey.vbproj", "{021339EF-4198-4ED3-8DD3-394227FB9C2C}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{021339EF-4198-4ED3-8DD3-394227FB9C2C}.Debug.ActiveCfg = Debug|.NET
{021339EF-4198-4ED3-8DD3-394227FB9C2C}.Debug.Build.0 = Debug|.NET
{021339EF-4198-4ED3-8DD3-394227FB9C2C}.Release.ActiveCfg = Release|.NET
{021339EF-4198-4ED3-8DD3-394227FB9C2C}.Release.Build.0 = Release|.NET
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal


--------------------------------------------------------------------------

RandomKey.vbproj

<VisualStudioProject>
<VisualBasic
ProjectType = "Local"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{021339EF-4198-4ED3-8DD3-394227FB9C2C}"
>
<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "RandomKey"
AssemblyOriginatorKeyFile = ""
AssemblyOriginatorKeyMode = "None"
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Exe"
OptionCompare = "Binary"
OptionExplicit = "On"
OptionStrict = "On"
RootNamespace = "RandomKey"
StartupObject = "RandomKey.Module1"
>
<Config
Name = "Debug"
BaseAddress = "285212672"
ConfigurationOverrideFile = ""
DefineConstants = ""
DefineDebug = "true"
DefineTrace = "true"
DebugSymbols = "true"
IncrementalBuild = "true"
Optimize = "false"
OutputPath = "bin\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "1"
/>
<Config
Name = "Release"
BaseAddress = "285212672"
ConfigurationOverrideFile = ""
DefineConstants = ""
DefineDebug = "false"
DefineTrace = "true"
DebugSymbols = "false"
IncrementalBuild = "false"
Optimize = "true"
OutputPath = "bin\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "1"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
/>
</References>
<Imports>
<Import Namespace = "Microsoft.VisualBasic" />
<Import Namespace = "System" />
<Import Namespace = "System.Collections" />
<Import Namespace = "System.Data" />
<Import Namespace = "System.Diagnostics" />
</Imports>
</Build>
<Files>
<Include>
<File
RelPath = "AssemblyInfo.vb"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Module1.vb"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "RandomKeyGenerator.vb"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</VisualBasic>
</VisualStudioProject>



--------------------------------------------------------------------------

RandomKey.vbproj.user

<VisualStudioProject>
<VisualBasic LastOpenVersion = "7.10.3077" >
<Build>
<Settings ReferencePath = "" >
<Config
Name = "Debug"
EnableASPDebugging = "false"
EnableASPXDebugging = "false"
EnableUnmanagedDebugging = "false"
EnableSQLServerDebugging = "false"
RemoteDebugEnabled = "false"
RemoteDebugMachine = ""
StartAction = "Project"
StartArguments = ""
StartPage = ""
StartProgram = ""
StartURL = ""
StartWorkingDirectory = ""
StartWithIE = "true"
/>
<Config
Name = "Release"
EnableASPDebugging = "false"
EnableASPXDebugging = "false"
EnableUnmanagedDebugging = "false"
EnableSQLServerDebugging = "false"
RemoteDebugEnabled = "false"
RemoteDebugMachine = ""
StartAction = "Project"
StartArguments = ""
StartPage = ""
StartProgram = ""
StartURL = ""
StartWorkingDirectory = ""
StartWithIE = "true"
/>
</Settings>
</Build>
<OtherProjectSettings
CopyProjectDestinationFolder = ""
CopyProjectUncPath = ""
CopyProjectOption = "0"
ProjectView = "ProjectFiles"
ProjectTrust = "0"
/>
</VisualBasic>
</VisualStudioProject>



--------------------------------------------------------------------------

RandomKey.xml

<?xml version="1.0" ?>
- <doc>
- <assembly>
<name>RandomKey</name>
<version>1.0.2034.40750</version>
<fullname>RandomKey, Version=1.0.2034.40750, Culture=Invariant Language (Invariant Country), PublicKeyToken=null</fullname>
</assembly>
- <members>
- <member name="T:RandomKey.RandomKeyGenerator">
<date>27072005</date>
<time>070339</time>
<type>class</type>
<summary>REQUIRES PROPERTIES: KeyLetters, KeyNumbers, MaxChars</summary>
</member>
- <member name="M:RandomKey.RandomKeyGenerator.Generate">
<date>27072005</date>
<time>072344</time>
<type>function</type>
<summary>GENERATES A RANDOM STRING OF LETTERS AND NUMBERS. LETTERS CAN BE RANDOMLY CAPITAL OR SMALL.</summary>
<returns type="String">RETURNS THE RANDOMLY GENERATED KEY</returns>
</member>
</members>
</doc>

--------------------------------------------------------------------------

RandomKeyGenerator.vb

Option Strict On
Imports System.Text
''' <date>27072005</date><time>070339</time>
''' <type>class</type>
''' <summary>
''' REQUIRES PROPERTIES: KeyLetters, KeyNumbers, MaxChars
''' </summary>
Public Class RandomKeyGenerator
Dim Key_Letters As String
Dim Key_Numbers As String
Dim Key_Chars As Integer
Dim LettersArray As Char()
Dim NumbersArray As Char()

''' <date>27072005</date><time>071924</time>
''' <type>property</type>
''' <summary>
''' WRITE ONLY PROPERTY. HAS TO BE SET BEFORE CALLING GENERATE()
''' </summary>
Protected Friend WriteOnly Property KeyLetters() As String
Set(ByVal Value As String)
Key_Letters = Value
End Set
End Property
''' <date>27072005</date><time>071924</time>
''' <type>property</type>
''' <summary>
''' WRITE ONLY PROPERTY. HAS TO BE SET BEFORE CALLING GENERATE()
''' </summary>
Protected Friend WriteOnly Property KeyNumbers() As String
Set(ByVal Value As String)
Key_Numbers = Value
End Set
End Property
''' <date>27072005</date><time>071924</time>
''' <type>property</type>
''' <summary>
''' WRITE ONLY PROPERTY. HAS TO BE SET BEFORE CALLING GENERATE()
''' </summary>
Protected Friend WriteOnly Property KeyChars() As Integer
Set(ByVal Value As Integer)
Key_Chars = Value
End Set
End Property

''' <date>27072005</date><time>072344</time>
''' <type>function</type>
''' <summary>
''' GENERATES A RANDOM STRING OF LETTERS AND NUMBERS. LETTERS CAN BE RANDOMLY CAPITAL OR SMALL.
''' </summary>
''' <returns type="String">RETURNS THE RANDOMLY GENERATED KEY</returns>
Function Generate() As String
Dim i_key As Integer
Dim Random1 As Single
Dim arrIndex As Int16
Dim sb As New StringBuilder
Dim RandomLetter As String

''' CONVERT LettersArray & NumbersArray TO CHARACTR ARRAYS
LettersArray = Key_Letters.ToCharArray
NumbersArray = Key_Numbers.ToCharArray

For i_key = 1 To Key_Chars
''' START THE CLOCK - LAITH - 27/07/2005 18:01:18 -
Randomize()
Random1 = Rnd()
arrIndex = -1
''' IF THE VALUE IS AN EVEN NUMBER WE GENERATE A LETTER, OTHERWISE WE GENERATE A NUMBER - LAITH - 27/07/2005 18:02:55 -
''' THE NUMBER '111' WAS RANDOMLY CHOSEN. ANY NUMBER WILL DO, WE JUST NEED TO BRING THE VALUE ABOVE '0' - LAITH - 27/07/2005 18:40:48 -
If (CType(Random1 * 111, Integer)) Mod 2 = 0 Then
''' GENERATE A RANDOM LOCATION IN THE LETTERS CHARACTER ARRAY - LAITH - 27/07/2005 18:47:44 -
Do While arrIndex < 0
arrIndex = Convert.ToInt16(LettersArray.GetUpperBound(0) * Random1)
Loop
RandomLetter = LettersArray(arrIndex)
''' CREATE ANOTHER RANDOM NUMBER. IF IT IS ODD, WE CAPITALIZE THE LETTER - LAITH - 27/07/2005 18:55:59 -
If (CType(arrIndex * Random1 * 99, Integer)) Mod 2 <> 0 Then
RandomLetter = LettersArray(arrIndex).ToString
RandomLetter = RandomLetter.ToUpper
End If
sb.Append(RandomLetter)
Else
''' GENERATE A RANDOM LOCATION IN THE NUMBERS CHARACTER ARRAY - LAITH - 27/07/2005 18:47:44 -
Do While arrIndex < 0
arrIndex = Convert.ToInt16(NumbersArray.GetUpperBound(0) * Random1)
Loop
sb.Append(NumbersArray(arrIndex))
End If
Next
Return sb.ToString
End Function
End Class


It also came with a exe file that does that but it happens in a cmd window so i cant copy anything or change the letters and numbers that it randomly chooses from

just so you know i have Visual Basic 6.0 Enterprise Edition

oracleguy
06-21-2006, 11:55 PM
This is a VB7 solution file and project, you aren't going to be able to directly open it up if you just have VB6. The code in module1.vb is vb.net code and can be adapted to VB6 with some work.

marhanen
06-22-2006, 06:35 AM
so i need to get VB7 and vb.net?

Brandoe85
06-22-2006, 06:45 AM
If you want to edit it the easiest would be to get .NET. Although, you can still probably edit it and complie it from the command line...or just copy what you need, whichever:
[http://www.duncanmackenzie.net/samples/commandline/]

You can check out vb express..last I knew it was free:
[http://msdn.microsoft.com/vstudio/express/vb/]

Good luck;