P.manidas 39 Posting Whiz in Training

Dear Abiba,

The thread had been marked as SOLVED on 21st March 2011 by me as i had got the answer. So, there is not need to reply on this thread.

Probably, you have posted without observing that. Anyway, welcome to Daniweb and waiting for more reply from your side on unsolved thread.

Thanks

codeorder commented: :) +12
P.manidas 39 Posting Whiz in Training

6

jingda commented: For being a great partner +0
P.manidas 39 Posting Whiz in Training

The above puzzle is very tough to solved. But any way, The solution is ..

Here,
1 -> 11 (One 1)
11 -> 21 (two 1)
21 -> 1211 (one 2 and one 1)
1211 ->111221 (one 1, one 2 and two 1)
111221 ->312211 (three 1, two 2 and one 1)

Suppose there there is a no. 5861155
for fist digit (5) that is ONE 5 =15
for second digit (8) that is ONE 8=18
for third digit (6) that is ONE 6=16
for forth and fifth digit (11 (though both the digit is same)) those are TWO 1=21
for sixth and seventh digit (55 (though both the digit is same)) those are TWO 5=25

So, the number is 1518162125

Arbus commented: Right answer! +0
P.manidas 39 Posting Whiz in Training

The number is 2519

Arbus commented: Perfect! +0
P.manidas 39 Posting Whiz in Training

“We are what our thoughts have made us; so take care about what you think. Words are secondary. Thoughts live; they travel far.”

- Swami Vivekananda -

P.manidas 39 Posting Whiz in Training

Try this one

Dim Complete As Boolean = False
Dim Com As Boolean= False
Dim PlaceNum As String
Dim i As Integer
Dim j As Integer

Dim Num1 As Integer=1
Dim Num2 As Integer=1


Do While Complete = False
If listbox1.Items.Count > 1 Then
For j = 0 To listbox1.Items.Count - 2 Step 1
    PlaceNum = listbox1.Items(j)
    For i = j + 1 To listbox1.Items.Count - 1 Step 1
        If PlaceNum = listbox1.Items (i) Then
            Num1 = Num1 * Val(listbox1.Items (i))
            listbox1.items.RemoveAt (i)
            listbox1.items.RemoveAt (j)
            Complete = False
            Com = True
            Exit For
        Else
            Com = False
        End If
     Next i
     
     If listbox1.Items.Count = 1 Then
     Complete = True
     Exit For
     End If
     
     If Com = True Then
        Exit For
     End If
     
     If j = listbox1.Items.Count - 2 Then
        Complete = True
     End If
Next j
Else
Complete = True
End If
Loop

For i = 0 To listbox1.Items.Count - 1 Step 1
Num2 = Num2 * listbox1.Items (i)
Next i

Textbox1.Text = Num1
Textbox2.Text = Num2
tstory28 commented: The code was right on the nose. He figured out exactly what I needed. +1
P.manidas 39 Posting Whiz in Training

By this below codes you can check how many words are there on single line or multi line text box even if user enter space in between and before or after words.

Private Sub Command1_Click()
Dim Counts As Integer
Dim dupText As String

dupText = Replace(Trim(Text1.Text), vbNewLine, " ")

If dupText = "" Then
    Counts = 0
Else
    Counts = 1
    For i = 1 To Len(dupText)
        If Mid(dupText, i, 1) = " " Then ' use Mid to search space
            If Mid(dupText, i - 1, 1) <> " " Then
                Counts = Counts + 1
            End If
        End If
    Next
End If
MsgBox Counts
End Sub
debasisdas commented: agree +12
dnk commented: Thanks for duplicate checking :) +2
WaltP commented: and thanks for doing his homework for him. Now he doesn't have to think. -3
P.manidas 39 Posting Whiz in Training

Adding 7 nos. textbox's text into a listbox

lstAlbums.Items.Add(Form1.textbox1.text.ToString)
lstAlbums.Items.Add(Form1.textbox2.text.ToString)
lstAlbums.Items.Add(Form1.textbox3.text.ToString)
lstAlbums.Items.Add(Form1.textbox4.text.ToString)
lstAlbums.Items.Add(Form1.textbox5.text.ToString)
lstAlbums.Items.Add(Form1.textbox6.text.ToString)
lstAlbums.Items.Add(Form1.textbox7.text.ToString)

For saving a listbox item into a text file

'for saveing listitem into text file
Dim Objfile As New System.IO.StreamWriter("C:\TestText.txt")
Dim intCounter As Long 
For intCounter = 0 To lstAlbums.Items.Count - 1
    objFile.WriteLine(lstAlbums.Items(intCounter).ToString)
Next intCounter

Objfile.Close()
Objfile.Dispose()

Retrieving textfile(i.e list items saved in the text file) into listbox on form load event

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Reading and adding into a listbox
Try
   Dim objFile As New System.IO.StreamReader("c:\TestText.txt")
   Dim strAlbumName As String
   strAlbumName = objFile.ReadLine()
   Do Until strAlbumName Is Nothing
        LstAlbums.Items.Add(strAlbumName)
        strAlbumName = objFile.ReadLine()
   Loop
   objFile.Close()
   objFile.Dispose()
   Catch ex As Exception
      MsgBox("The file could not be found.")
   End Try
End Sub

in my codes Listbox name is lstAlbums

P.manidas 39 Posting Whiz in Training

If you want to add list item of listbox1 of from1 to listbox1 of Form2

write the below codes in form2_load event....

Dim a As Integer
ListBox1.Items.Clear()
For a = 0 To Form1.ListBox1.Items.Count - 1 Step 1
    ListBox1.Items.Add(Form1.ListBox1.Items.Item(a).ToString)
Next

If you want to add textbox's text of from1 to listbox1 of Form2

write the below codes in form2_load event....

ListBox1.Items.Clear()
ListBox1.Items.Add(Form1.textbox1.text.ToString)
ListBox1.Items.Add(Form1.textbox2.text.ToString)
ListBox1.Items.Add(Form1.textbox3.text.ToString)
ListBox1.Items.Add(Form1.textbox4.text.ToString)
ListBox1.Items.Add(Form1.textbox5.text.ToString)
P.manidas 39 Posting Whiz in Training

I have got the result/solution from Microsoft Visual Basic Developer Center. The answer has given by respected sir "Calle Mellergardh". And the codes are ...

Private Sub AddFromCreatedTextBox_Click()
'what will be the codes here
Dim ctl As Control
    Dim num As Integer
    Dim total As Integer
   
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox And InStr(ctl.Name, "TxtBox") <> 0 Then
            num = Val(Trim(ctl.Text))
            total = total + num
        End If
    Next
    MsgBox total
End Sub
debasisdas commented: thank you for shairing. +9
P.manidas 39 Posting Whiz in Training

This is an example with listbox for getting your solution. Hope, it will solve your problem.

Dim A As Integer = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        A = A + 1
        If Trim(TextBox1.Text) = Trim(Now) Then
            ListBox1.Items.Add(Now & " " & A)
        Else
            A = 1
            ListBox1.Items.Add(Now & " " & A)
        End If
        TextBox1.Text = Now
    End Sub
swathys commented: thank you +0
P.manidas 39 Posting Whiz in Training

Try this one....

Creating a button

Private Sub Form_Load()
Dim Com As CommandButton
Set Com = Me.Controls.Add("vb.commandbutton", "BtnName")

    With Com
        .Left = 1000
        .Top = 3000
        .Width = 5000
        .Height = 1000
        .Visible = True
        .Caption = "My Button"
    End With
End Sub

Moving a button.....

Dim CmdX As Long
Dim CmdY As Long
Dim MoveBtn As Boolean


Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
CmdX = X
CmdY = Y
MoveBtn = True
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MoveBtn Then
    Command1.Top = Command1.Top - (CmdY - Y)
    Command1.Left = Command1.Left - (CmdX - X)
End If
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveBtn = False
End Sub
P.manidas 39 Posting Whiz in Training

Dear AndreRet,

Sir, i have got another solution for checking execution time of a procedure. This time i have got the solution in fraction without using timer.

Private Sub Command1_Click() 'without timer its successfull
Dim ST As Double
Dim FT As Double
ST = Timer
For a = 1 To 1000000 Step 1
    Label1.Caption = Val(Label1.Caption) + 1
Next
FT = Timer
Text1.Text = "Total time required by this procedure is " + Str(FT - ST) + " Seconds"
End Sub
AndreRet commented: Nice! +6