CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2001
    Posts
    28

    need these two functions (in text box)

    i need two functions:

    1. function that will put # line to # variable
    for example the text is:

    hello
    my nick is ma622

    so i want it:
    function(2,nick)-----it will put "my nick is ma622" to the variable "ma622"
    2. function that will count how much lines in the text box

    10X


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: need these two functions (in text box)

    You can't create variables at run time. Your best bet is to use Collections making "ma622" as the key to an element and the "my nick is ma622" as the text. You can then retrieve the information using the key value. Here is a real simple sample of adding data to a collection and retrieving it. This sample, uses hard coded data. You can of course use variables to input the data.
    Add two command buttons to a form and paste this code into the general declaration section of the form. Run it. Click command1 which creates a collection element. Click command2. It will display what was just created.

    option Explicit
    Dim MyCol as Collection
    Dim Zipcode as Integer
    private Sub Command1_Click()
    ' Add a Zipcode to the collection
    MyCol.Add "City,State", CStr(Zipcode)

    End Sub

    private Sub Command2_Click()
    ' Retrieve a zipcodes city and state
    MsgBox MyCol.Item(CStr(Zipcode))

    End Sub

    private Sub Form_Load()
    ' Establish new colection
    set MyCol = new Collection
    Zipcode = 29483
    End Sub




    John G

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: need these two functions (in text box)

    'THis function will return quantity of the lines in the textbox

    Private Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long

    Const EM_GETLINECOUNT = &HBA



    'Call API to determine how many lines of text are in text box
    LinesOfText = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: need these two functions (in text box)

    'another way to calculat elines in a textbox
    lineCount = Len(Text1.Text) - Len(Replace(Text1.Text, vbCrLf, vbCr))

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: need these two functions (in text box)

    In order to put a certain line from the text box to the variable, try to read text from the textbox between vbCrLf and when you find the desired text assign it to a variable

    I hope that what you want

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  6. #6
    Join Date
    Jun 2000
    Location
    Jhb, Gauteng RSA
    Posts
    21

    Re: need these two functions (in text box)


    'Here is something I ran across.
    'I did not write it.
    'Start a new Project, Add a Module. Add a ComboBox, A command Button, two labels and a textBox
    'using the default names to the form.



    'http://www.vb-helper.com/HowTo/execline.zip
    'PurposeExecute a line of code stored in a string
    'MethodUse the EbExecuteLine API function.
    'Thanks to Sergio Perciballi ([email protected]).
    'DisclaimerThis example program is provided "as is" with no warranty of any kind. '
    'It isintended for demonstration purposes only. In particular, it does no errorhandling.
    'You can use the example in any form, but please mention
    ' www.vb-helper.com.

    ' Copy the following to a form



    '------------------------------------------
    ' (c) 1999 Trigeminal Software, Inc. All Rights Reserved
    '------------------------------------------
    'Thanks to ----------michka - Michael Kaplan
    'Rest of code by Sergio Perciballi -oigres P (Aug-6-2000)
    'Email: [email protected]
    'Uses the function used by the immediate window
    'to execute a line of code.
    option Compare Text
    option Explicit
    private Declare Function EbExecuteLine Lib "vba6.dll" _
    (byval pStringToExec as Long, byval Foo1 as Long, _
    byval Foo2 as Long, byval fCheckOnly as Long) as Long
    ' for VB5 IDE
    'Declare Function EbExecuteLine Lib "vba5.dll" _
    (byval pStringToExec as Long, byval Foo1 as Long, _
    byval Foo2 as Long, byval fCheckOnly as Long) as Long
    ' for Access 97/VBE.dll clients like Word 97 and Excel 97
    'Declare Function EbExecuteLine Lib "vba332.dll" _
    (byval pStringToExec as Long, byval Foo1 as Long, _
    byval Foo2 as Long, byval fCheckOnly as Long) as Long
    Function FExecuteCode(stCode as string, optional fCheckOnly as Boolean) as Boolean

    FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
    End Function
    private Sub Combo1_Click()

    Text1.Text = Combo1.List(Combo1.ListIndex)
    End Sub
    private Sub Command1_Click()

    Dim res as Boolean
    res = FExecuteCode(Text1.Text)
    Label1.Caption = "Status = " & res
    End Sub

    private Sub Form_Click()
    Form2.Show
    End Sub

    private Sub Form_Load()
    Combo1.AddItem "?secret"
    Combo1.AddItem "msgbox secret"
    Combo1.AddItem "secret2"
    Combo1.AddItem "for x=0 to 5:?" & Chr$(34) & "hello " & Chr$(34) & "&x:next:beep"
    Combo1.AddItem "sendkeys " & Chr$(34) & "{TAB}" & Chr$(34) & ":sendkeys " & Chr$(34) & "{up}" & Chr$(34)
    Combo1.AddItem "shell " & Chr$(34) & "calc.exe" & Chr$(34) & ",vbNormalFocus"
    Combo1.AddItem "shell " & Chr$(34) & "c:\windows\explorer.exe ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" & Chr$(34) & ",vbNormalFocus"
    Combo1.AddItem "form1.text1.visible=false"
    Combo1.AddItem "form1.text1.visible=true"
    Combo1.AddItem "form1.combo1.listindex=1"
    Combo1.AddItem "msgbox app.Title"
    Combo1.AddItem "form1.combo1.listindex=1:form1.command1.value=true"
    Combo1.ListIndex = 0
    Show
    End Sub




    hope this helps
    RobZ



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured