Wrox Programmer Forums
|
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2008, 11:03 PM
Registered User
 
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default help me in writing a program

what i wanted to do is to have the user input 10 letter or digit
A B C D E F G H I J

then will generate 50 combination with set of 3 each time

 but also i want to be able to have a button that chooses 10 from the 50 generated

  ABF ABG ABH ABI ABJ OR FGH FGI FGJ OR GHI GHJ

so if you can help me in that i will really appreciate it thx



jolo
 
Old February 26th, 2008, 06:00 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Dude you have an interesting question, heres what i would do!


button_click() 'Your normal button click event
SplitNumbers()
end sub

Private Sub SplitNumbers()
Dim str as String
str = textbox1.text
dim len as Integer
len = str.length
dim splitStr(len) as string
for i as integer = 0 to len -1
splitStr(i) = str.substring((i+1), 1)
next
Generate_Combinations(splitStr)
End Sub

Public Sub Generate_Combinations(ByVal combo() As String)
Dim extraLetters as string
dim len as length
len = combo.length

for i as integer = 0 to len - 1
  combo(i) = combo(i) & RandomLetter() & RandomLetter()
next
End Sub

Public Function RandomLetter() As String
dim randomNumber as integer = cint((rnd() * 90))
for i as integer = 0 to 100000 'make a continuouse loop so we find a _character
if randomNumber < 65 then
return 'code to make ascii number, can't remember what it is, but i will find out, i don't have vb present to look!
else
randomNumber = Cint((rnd() * 90))
end if
next
End Function

Okay, everything below the button click event is properly coded, i hope, i have literally jsut done this out of my head okay. on the form you need a textbox called textbox1 and a button. Assuming you know how to program buttons and their click event then you can do this. The new combinations will be created into the combo() array from there you can manipulate it. have fun with that, write back if you have any queries, obviously i will test the code at about 5.00pm if i can remember!

Good luck.

------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
 
Old February 26th, 2008, 12:17 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

I'm a bit confused about the generating 50 combinatiosn part, here's my depictions of what you said:-
    - 50 Combinations for each letter in the 10 letter input
    - 50 combinations for the whole 10 letter input
Also that creates more questions about the selecting 10 parts of them, again here are the depictions:-
    - 10 from each of the 50 combinations
    - 10 from one of the 50 combinations

Below is my updated code i said i would do, there is a form called Form1 and a textbox call txtInput and a Button called btnCode. This code generates radom extra letters, not numbers so you can tweak what you want.

Code:
Public Class Form1
    Public lbl(9) As Label

    Private Sub btnCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCode.Click
        SplitTextBoxAndGenerate()
    End Sub

    Private Sub SplitTextBoxAndGenerate()
        Dim str As String
        str = txtInput.Text
        Dim len As Integer = str.Length
        Dim splitStr(len - 1) As String
        For i As Integer = 0 To len - 1
            splitStr(i) = str.Substring(i, 1)
            splitStr(i) = splitStr(i) & RandomLetter() & RandomLetter() 'Generate Combinations
            lbl(i).Text = splitStr(i)
        Next
    End Sub

    Public Sub Generate_Combinations(ByVal combo() As String)

    End Sub

    Public Function RandomLetter() As String
        Dim randomNumber As Integer = CInt((rnd() * 90))
        For i As Integer = 0 To 100000 'make a continuouse loop so we find a _character
            If randomNumber > 65 Then
                Return CStr(Strings.Chr(randomNumber)) 'code to make ascii number, can't remember what it is, but i will find out, i don't have vb present to look!
            Else
                randomNumber = CInt((Rnd() * 90))
            End If
        Next
        Return "A"
    End Function

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Create_Control_Array()
    End Sub

    Private Sub Create_Control_Array()
        lbl(0) = Label1
        lbl(1) = Label2
        lbl(2) = Label3
        lbl(3) = Label4
        lbl(4) = Label5
        lbl(5) = Label6
        lbl(6) = Label7
        lbl(7) = Label8
        lbl(8) = Label9
        lbl(9) = Label10
    End Sub
End Class
Enjoy, the best way to learn vb is to get source code like this figure out an aim and achieve it by any means, and you'll just learn so much, also another technique is to create a big project and any controls inside this project that you don't know how to use just create a new project and soley base the project around that control and manipulate it in as many ways possible. This is how i learnt to use vb and honestly in like 6months i've gone from beginner to atleast high intermediate!

Good luck,


------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM
Writing plugins dotnetprogrammer VS.NET 2002/2003 0 December 29th, 2004 06:14 AM
Start a program inside another program Silje Classic ASP Professional 1 November 16th, 2004 02:08 AM
writing a lottery program in C++ captlem66 VB.NET 2002/2003 Basics 2 October 13th, 2004 02:50 AM
Need help in writing a C program using win32 API rameshbabumv C++ Programming 0 March 10th, 2004 05:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.