|
I have rewritten your code to use a recursive Sub rather than a Function. The main problem with your examle is that you were not inspecting all possible combinations of the input string (i.e. only one iteration of the For...Next loop was ever executed). It can be refined further but this will do for a brief explanation.
This example also uses a Scripting.Dictionary object rather than an array because it simplifies the detection of duplicate strings (I assumed that duplicates were not permitted). Look this up in the VB help files for more information.
Option Explicit
Private Sub GenerateStrings()
Dim wd As Scripting.Dictionary
Set wd = New Scripting.Dictionary
Call test2("some", wd)
'Command1.Caption = wd.Count
End Sub
Sub test2(str As String, ByRef wd As Scripting.Dictionary)
Dim ch As String
Dim ch1 As String
Dim ch2 As String
Dim wlen As Integer
Dim i As Integer
wlen = Len(str)
For i = 1 To wlen
ch1 = Left(str, i - 1)
ch = Mid(str, i, 1)
ch2 = Mid(str, i + 1, wlen)
Select Case ch
Case "s"
Call test2(ch1 & "a" & ch2, wd)
Call test2(ch1 & "c" & ch2, wd)
Case "m"
Call test2(ch1 & "k" & ch2, wd)
Call test2(ch1 & "l" & ch2, wd)
Call test2(ch1 & "u" & ch2, wd)
Case "e"
Call test2(ch1 & "b" & ch2, wd)
Call test2(ch1 & "h" & ch2, wd)
Case Else
End Select
Next
If Not wd.exists(str) Then
Debug.Print str
wd.Add str, str
End If
End Sub
'Function test1(str As String) As String()
' Dim wd() As String, ch As String, ch1 As String, ch2 As String
' Dim wlen As Integer, i As Integer, j As Integer
' j = 0
' wlen = Len(str)
' For i = 1 To wlen
' ch1 = Left(str, i - 1)
' ch = Mid(str, i, 1)
' ch2 = Mid(str, i + 1, wlen)
'
' If ch = "s" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "a" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "c" & ch2
' j = j + 1
' End If
' If ch = "a" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "s" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "c" & ch2
' j = j + 1
' End If
' If ch = "c" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "s" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "a" & ch2
' j = j + 1
' End If
'
' If ch = "m" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "k" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "l" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "u" & ch2
' j = j + 1
' End If
' If ch = "k" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "m" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "l" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "u" & ch2
' j = j + 1
' End If
' If ch = "l" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "k" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "m" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "u" & ch2
' j = j + 1
' End If
' If ch = "u" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "k" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "l" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "m" & ch2
' j = j + 1
' End If
' If ch = "e" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "b" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "h" & ch2
' j = j + 1
' End If
' If ch = "b" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "e" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "h" & ch2
' j = j + 1
' End If
' If ch = "h" Then
' ReDim Preserve wd(j)
' wd(j) = ch1 & "e" & ch2
' j = j + 1
' ReDim Preserve wd(j)
' wd(j) = ch1 & "b" & ch2
' j = j + 1
' End If
'
' Next
' test1 = wd
'End Function
'
...Steve
|
|
|
|
|
LyBun wrote:
Dear steve
First I thank you to give the solution .but we still got some problem with the solution . It is when we create other one like "sole" , "coub" or "bkoa" it can't give the correct answer .It is maybe I tell the condition not clear . so I say again
1 the charater "s" can become to charater "a" and "c" but the "a" can also become to "s" and "c" . the "c" can also become to "s" and "a"
2 the charater "m" become to charater "k" ,"l" and "u" ."k" also can become to "m" ,"u" and "l" . "l" also can become to "m" , "u" and "k" . "u" can also become to "m" , "k" and "l" .
3 the charater "e" can become to charater "b" and "h" the same with the 3 one .
when I change your code it run out of stack space . How to correct the code to avoid the error
The code change is :
Sub test2(str As String, ByRef wd As Scripting.Dictionary)
Dim ch As String
Dim ch1 As String
Dim ch2 As String
Dim wlen As Integer
Dim i As Integer
wlen = Len(str)
For i = 1 To wlen
ch1 = Left(str, i - 1)
ch = Mid(str, i, 1)
ch2 = Mid(str, i + 1, wlen)
Select Case ch
Case "s"
Call test2(ch1 & "a" & ch2, wd)
Call test2(ch1 & "c" & ch2, wd)
Case "a"
Call test2(ch1 & "s" & ch2, wd)
Call test2(ch1 & "c" & ch2, wd)
Case "c"
Call test2(ch1 & "s" & ch2, wd)
Call test2(ch1 & "a" & ch2, wd)
Case "m"
Call test2(ch1 & "k" & ch2, wd)
Call test2(ch1 & "l" & ch2, wd)
Call test2(ch1 & "u" & ch2, wd)
Case "k"
Call test2(ch1 & "m" & ch2, wd)
Call test2(ch1 & "l" & ch2, wd)
Call test2(ch1 & "u" & ch2, wd)
Case "l"
Call test2(ch1 & "k" & ch2, wd)
Call test2(ch1 & "m" & ch2, wd)
Call test2(ch1 & "u" & ch2, wd)
Case "u"
Call test2(ch1 & "k" & ch2, wd)
Call test2(ch1 & "l" & ch2, wd)
Call test2(ch1 & "m" & ch2, wd)
Case "e"
Call test2(ch1 & "b" & ch2, wd)
Call test2(ch1 & "h" & ch2, wd)
Case "b"
Call test2(ch1 & "e" & ch2, wd)
Call test2(ch1 & "h" & ch2, wd)
Case "h"
Call test2(ch1 & "b" & ch2, wd)
Call test2(ch1 & "e" & ch2, wd)
Case Else
End Select
Next
If Not wd.Exists(str) Then
Debug.Print str
wd.Add str, str
End If
End Sub
Hope see your answer soon .
Thanks!!!!!
Regards,
bun
Bun,
The problem with what you are trying to do is that you'll cause an infinite recursion loop in test2() since "a" can replace "s" and "s" can replace "a" etc..., and hence that is why you get the stack overflow error.
I should have asked this question in the first place, but what are you actually trying to achieve? Is this some real world application or just a programming exercise? Is it a condition of the algorithm that multiple substitutions are permitted or is only one pass over the initial input string to be performed?
...Steve
|
|
|
|
|
Hello,
I am designing an accounts webform( Crikey! ) in which I have two fields 'rate' in textbox1 and 'points' in textbox2 which are of type decimal in the first half of the webform. The user enters the values in these text boxes from the webform and on hitting a button 'calculate & display' following things should happen:
1. In textbox3 - result (type decimal) it should display the result (rate)-(points) which I have achieved
2. the user then enters the rest of the form and hits 'save form'. which means i have two buttons on the form,'calculate&display' and 'save'
3. On hitting save, it should save all the values on the webform into my (SQL server) database --- this is not working, it saves all of the other fields except these 3 text box values i.e. 'rate', 'points' and 'result', all that the database is saving each time is '0.00000' and '1.00000'
can someone please help me with this ... cansome give me a quickie tour of how to calculate values on webform , display the result and save the rsult in database because i need to do a lot of this in the rest of the form. I have 6 more fields which I need to compare, calculate,display and save in database !!!
I use Vb.net code but C# is welcome too.
Thanks a Zillion in advance...it is going to be big help!!!
Aartee.
...HE is watching Us All!
|
|
|
|
|
have you tried changing the type of ur results?
Aim small, miss small...
|
|
|
|
|
Hi tatchung,
I don't quite understand what exactly you mean by changing the type of results but everything is in decimal...even if i try it in type Int or varchar etc... it still does not work, it is calculating and displaying the correct subtracted values but only on the webform, not saving it in the database.
Aartee.
...HE is watching Us All!
-- modified at 22:26 Sunday 18th September, 2005
|
|
|
|
|
Good day sir,
I mean have you tried checking the value u are returning in ur insert command? is it of type decimal? i've had a similar problem with a short once and all i did was declared the value in my insert command. might work on ur problem but then again i could be wrong...im still a beginer u know
Aim small, miss small...
|
|
|
|
|
all that the database is saving each time is '0.00000' and '1.00000'
You might have referenced the wrong control, or you are losing the control handle on postback of the page.
If you can give a small sample code containing your Textboxes and Database update we might be able to help you more on this.
Ed
-- modified at 3:03 Monday 19th September, 2005
[Edit]Also, posting in ASP.Net forum might be better.[/Edit]
|
|
|
|
|
Can anyone help with this one
Have a form with a listbox and 5 textboxes, by clicking the different customer id's in the listbox this then displays the relevant info in the textboxes which is first name, last name, city, state and zip code from the Customers Table, this works fine but I'm trying to display at the same time the orders placed for each selected customerid only in a datagrid from the Orders Table but can't get it to work
The orders placed details to be displayed in the datagrid from the database are OrderID, OrderPrice and CustomerID, have tried to include a data relation but being new to programming not sure if it's right, or which is the correct datasource to use for the datagrid
I also need to show when the form initially loads the info for the first CustomerID by default
Any advice/coding which could help me would be much appreciated, my coding is below
Many thanks
Imports System.Data.OleDb
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Dim ds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Declares and instantiates command object
Dim SqlCustomers As String = "SELECT * FROM customers"
'Sets the connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\The Doughnut Shop.mdb"
'Declares and instantiates a new OleDbconnection object
Dim myconnection As OleDbConnection = New OleDbConnection(connString)
' Sets the connection string property
myconnection.ConnectionString = connString
'Declares and instantiates a data adapter
Dim dacustomers As OleDbDataAdapter = New OleDbDataAdapter(SqlCustomers, myconnection)
ds = New DataSet
dacustomers.Fill(ds, "customers")
Dim sqlorders As String = "Select OrderID, OrderPrice, CustomerID from Orders"
' Declares and instantiates the datadapter
Dim daorders As OleDbDataAdapter = New OleDbDataAdapter(sqlorders, myconnection)
daorders.Fill(ds, "orders")
Dim relation As DataRelation = New DataRelation("CustomersOrders", ds.Tables("Customers").Columns("CustomerID"), ds.Tables("Orders").Columns("CustomerID"))
ds.Relations.Add(relation)
ListBox1.DisplayMember = "CustomerID"
ListBox1.DataSource = New DataView(ds.Tables("customers"))
TextBox1.Text = ds.Tables("customers").Rows(0).Item("FirstName")
TextBox2.Text = ds.Tables("customers").Rows(0).Item("LastName")
TextBox3.Text = ds.Tables("customers").Rows(0).Item("City")
TextBox4.Text = ds.Tables("customers").Rows(0).Item("State")
TextBox5.Text = ds.Tables("customers").Rows(0).Item("ZipCode")
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim drv As DataRowView = CType(ListBox1.SelectedItem, DataRowView)
Dim childRows() As DataRow = drv.Row.GetChildRows("CustomersOrders")
TextBox1.Text = drv("FirstName")
TextBox2.Text = drv("LastName")
TextBox3.Text = drv("City")
TextBox4.Text = drv("State")
TextBox5.Text = drv("ZipCode")
DataGrid1.DataSource = childRows
DataGrid1.Refresh()
End Sub
End Class
|
|
|
|
|
SLG7 wrote:
at the same time the orders placed for each selected customerid only in a datagrid from the Orders Table but can't get it to work
Is it displaying all of the customers or nothing at all?
|
|
|
|
|
There's nothing showing in the datagrid for the Orders Table
Been racking my brains over this one any help/coding would be great
Thanks
|
|
|
|
|
Hi there!
I'm trying to control a program with a gamepad.
Does anybody know how to initialize a joystick or gamepad using DirectInput and make the joystick inputs usable?
Thanks
|
|
|
|
|
The samples that come with DirectX show you how.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I can only find C++, is there any VB.Net code as well?
|
|
|
|
|
Did you install managed C++ ? It doesn't install automatically, it needs a command line switch. Then you should have C#/VB.NET samples.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have C++ and Managed in the DirectX SDK folder. In managed I only find C# samples and no VB.NET.
|
|
|
|
|
There are no VB.NET samples in the DirectX SDK anymore. For some reason they have dropped support for VB.NET. This is now way means that you can't use VB.NET with DirectX, there just no documentation support for it. Use the C# examples and translate the code. Much of C#'s syntax maps almost directly to VB.NET statements.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well that aswers my question why I could't find anything on the internet, not happy with it though!
You don't have any code on this by any chance? I'm unfamiliar with C#. Will try it anyway.
Thanks for your help.
|
|
|
|
|
Jerry___ wrote:
not happy with it though!
Neither are the people on the DirectX team at Microsoft.
Jerry___ wrote:
You don't have any code on this by any chance?
Nope.
Jerry___ wrote:
I'm unfamiliar with C#. Will try it anyway.
If you know VB.NET, you know more about C# than you think. If you look at the MSDN documentation, there are thousands of code samples for everything in the .NET Framework, written in both VB.NET and C#. There's your Rosetta Stone. You don't need examples written speciffically in VB.NET to learn about the .NET Framework and DirectX. The managed objects are the same between them because they're using the exact same objects. There isn't a VB.NET version and a C# version. All you have to do is compare any VB.NET samples to the C# samples (MSDN example code supplies both for neearly every in the docs) and take note of what each line does and compare it to the other languages equivilent. It's pretty easy.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 11:16 Monday 19th September, 2005
|
|
|
|
|
Hello again,
I'm allmost done. the program works just like the C# one.
Still one problem, need to translate this to VB.Net:
byte[] buttons = state.GetButtons();<br />
<br />
int button = 0;<br />
foreach (byte b in buttons)<br />
{<br />
if (0!= (b & 0x80))<br />
strText += button.ToString("00 ");<br />
button++;<br />
}<br />
labelButtons.Text = strText;<br />
}
Cant figure out the 0x80 part, and cant find it anywhere either, not even in the help section.
I suppose ("00 ") is a format.
The rest works just fine; you were absolutely right about knowing more about C# than you think!
|
|
|
|
|
All problems solved!
App up and running, fully functional, exactly the same as in the C# example. Very pleased.
If anybody needs it, let me know.
Thanks again.
|
|
|
|
|
I have a mother form and two child forms. How can I properly code VB.NET to show (make it appear) the second form still recognized as "child" form of the mother though what I've clicked is the active child form's button? For instance, I have one active child and I click its button and another child form appears. How can I "tell" this second form that it is a child not of the one who called it but of the mother form? Thanks...
|
|
|
|
|
Creation of child forms should really be left up to the parent form. But,
Dim newChild As New myForm2()
newChild.MdiParent = Me.MdiParent
newChild.Show()
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I need to establish a connection between one PC and a PocketPC.
Someone can guide me about how can I start?
Thanks
|
|
|
|
|
|
Thanks a lot!
Very useful links!!
|
|
|
|
|